The call device.get_ips()
returns a QuerySet
whereas [ip1, ip2, ip3]
is a list. Hence they're currently not equal.
Given that you don't want to test things that may not matter (order in which rows are returned in .filter()
from the database), I suggest testing as follows:
results = device.get_ips()
result_ips = [ip.ip for ip in results]
self.assertEqual(len(results), 3)
self.assertTrue(ip1.ip in result_ips)
self.assertTrue(ip2.ip in result_ips)
self.assertTrue(ip3.ip in result_ips)
This tests: three results and IPs are the same. This should give reasonable confidence that you're getting the same objects (although you can add more assertions as desired).