@@ -604,6 +604,34 @@ def test_instance_from_detail_lookup(self):
604604 self .assertEqual (result .name , "venusaur" )
605605 self .assertEqual (result .id , 3 )
606606
607+ @responses .activate
608+ def test_equality (self ):
609+ responses .add (
610+ responses .GET , "http://example.com/api/countries/" ,
611+ match = [matchers .query_param_matcher ({"id" : 4 })],
612+ body = """
613+ [
614+ {
615+ "id": 4,
616+ "name": "Japan",
617+ "continent": "asia"
618+ }
619+ ]
620+ """
621+ )
622+
623+ country = Country .objects .get (id = 4 )
624+ # match by ID and type
625+ self .assertEqual (country , Country (id = 4 , name = "Japan" , continent = "asia" ))
626+ self .assertEqual (country , Country (id = 4 , name = "Nihon" , continent = "asia" ))
627+ self .assertNotEqual (country , Country (id = 5 , name = "China" , continent = "asia" ))
628+ self .assertNotEqual (country , Pokemon (id = 4 , name = "Charmander" ))
629+
630+ def test_equality_on_unsaved_objects (self ):
631+ obj1 = Country (name = "New Country" , continent = "oceania" )
632+ obj2 = Country (name = "New Country" , continent = "oceania" )
633+ self .assertEqual (obj1 , obj1 )
634+ self .assertNotEqual (obj1 , obj2 )
607635
608636 @responses .activate
609637 def test_in_bulk (self ):
0 commit comments