Esempio n. 1
0
 def test_serializer_include_returns_nothing_except_field_name(self):
     request = self.get_request("test/?include_fields=field_two")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertNotIn("field_one", data.keys())
     self.assertIn("field_two", data.keys())
     self.assertNotIn("field_three", data.keys())
     self.assertNotIn("field_four", data.keys())
Esempio n. 2
0
 def test_serializer_field_sets_returns_only_fields_in_list(self):
     request = self.get_request("test/?field_set=one_and_three")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertIn("field_one", data.keys())
     self.assertNotIn("field_two", data.keys())
     self.assertIn("field_three", data.keys())
     self.assertNotIn("field_four", data.keys())
Esempio n. 3
0
 def test_serializer_exclude_returns_everything_in_default_except_excluded_object(self):
     request = self.get_request("test/?exclude_fields=field_one")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertNotIn("field_one", data.keys())
     self.assertIn("field_two", data.keys())
     self.assertIn("field_three", data.keys())
     # Four not in the default set
     self.assertNotIn("field_four", data.keys())
Esempio n. 4
0
 def test_no_lingering_effects_integration(self):
     request = self.get_request("test/?field_set=one_and_three")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertIn("field_one", data.keys())
     self.assertNotIn("field_two", data.keys())
     self.assertIn("field_three", data.keys())
     self.assertNotIn("field_four", data.keys())
     request = self.get_request("test/?field_set=all")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertIn("field_one", data.keys())
     self.assertIn("field_two", data.keys())
     self.assertIn("field_three", data.keys())
     self.assertIn("field_four", data.keys())
     request = self.get_request("test/?include_fields=field_one")
     data = TestObjectSerializer(self.test_object, context={"request": request}).data
     self.assertIn("field_one", data.keys())
     self.assertNotIn("field_two", data.keys())
     self.assertNotIn("field_three", data.keys())
     self.assertNotIn("field_four", data.keys())