def test_iterator_when_not_forbidden_format(self): """Ensure other formats than self.formats return iterators/generators, not lists.""" format_ = 'json' self.assertNotIn(format_, self.formats) rvs = ReportsViewSet() mock_request = MagicMock() mock_request.query_params = QueryDict() result = rvs.listify(self.iterable, mock_request, format=format_) self.assertNotEqual(type(result), type(list()))
def test_listify_format_as_param(self): """Regression test: make sure it's possible to iterate through results serialized with CSV or YAML serializer. This test uses 'format' function parameter.""" rvs = ReportsViewSet() for format_ in self.formats: with self.subTest(format=format_): mock_request = MagicMock() mock_request.query_params = QueryDict() result = rvs.listify(self.iterable, mock_request, format=format_) self.assertEqual(type(result), type(list()))
def test_listify_query_param(self): """Regression test: make sure it's possible to iterate through results serialized with CSV or YAML serializer. This test uses `?format' query param.""" rvs = ReportsViewSet() for format_ in self.formats: with self.subTest(format=format_): mock_request = MagicMock() mock_request.query_params = QueryDict( 'format={}'.format(format_)) result = rvs.listify(self.iterable, mock_request) self.assertEqual(type(result), type(list()))