Exemple #1
0
    def test_paginated_result_response_with_serialize_kwargs(
            self, pagination_links):
        with self.app.test_request_context("/"):
            result, results_query, pagination = self._get_paginated_result_mocks(
            )
            pagination_links.return_value = {"paginated": "links"}

            response = paginated_result_response("name", results_query, 3, 2,
                                                 '.endpoint', {"arg": "value"},
                                                 {"do": "this"})

            assert json.loads(response.get_data(as_text=True)) == {
                "name": [{
                    "serialized1": "content1"
                }, {
                    "serialized2": "content2"
                }],
                "meta": {
                    "total": 10
                },
                "links": {
                    "paginated": "links"
                }
            }
            results_query.paginate.assert_called_once_with(page=3, per_page=2)
            pagination_links.assert_called_once_with(pagination, '.endpoint',
                                                     {"arg": "value"})
            calls = [mock.call(do="this"), mock.call(do="this")]
            result.serialize.assert_has_calls(calls)
    def test_paginated_result_response(self, pagination_links):
        with self.app.test_request_context("/"):
            result, results_query, pagination = self._get_paginated_result_mocks()
            pagination_links.return_value = {"paginated": "links"}

            response = paginated_result_response("name", results_query, 3, 2, '.endpoint', {"arg": "value"})

            assert json.loads(response.get_data(as_text=True)) == {
                "name": [{"serialized1": "content1"}, {"serialized2": "content2"}],
                "meta": {"total": 10},
                "links": {"paginated": "links"}
            }
            results_query.paginate.assert_called_once_with(page=3, per_page=2)
            pagination_links.assert_called_once_with(pagination, '.endpoint', {"arg": "value"})
            assert result.serialize.call_count == 2