def test_serialize_detail_response(self): detail_response = DetailResponse(self.request) detail_response.resource = SimpleResource(self.data) serialized_data = self.serializer.serialize_response(detail_response) data = json.loads(serialized_data) expected_data = { "type": "detail", "error": None, "error_code": None, "errors": None, "status": 200, "meta": { 'pagination': None, }, "data": self.data } self.assertEqual(data, expected_data)
class TestDetailResponse(TestCase): def setUp(self): self.request_mock = mock.MagicMock() self.response = DetailResponse(request=self.request_mock) def test_attributes(self): self.assertEqual(self.response.status_code, 200) self.assertEqual(self.response.error, None) self.assertEqual(self.response.meta, {'pagination': None}) self.assertEqual(self.response.response_type, 'detail') self.assertEqual(self.response.resource, None) def test_get_response_data_empty(self): data = self.response.get_response_data() self.assertEqual(data, None) def test_get_response_data(self): self.response.resource = SimpleResource(id=1, name='a') data = self.response.get_response_data() self.assertEqual(data, {'id': 1, 'name': 'a'})
def setUp(self): self.request_mock = mock.MagicMock() self.response = DetailResponse(request=self.request_mock)