|
| 1 | +from django.core.urlresolvers import reverse |
| 2 | + |
| 3 | +import pytest |
| 4 | +from example.tests.utils import dump_json, redump_json |
| 5 | + |
| 6 | +pytestmark = pytest.mark.django_db |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def single_entry(author_factory, entry_factory): |
| 11 | + |
| 12 | + author = author_factory(name="Joel Spolsky") |
| 13 | + entry = entry_factory( |
| 14 | + headline=("The Absolute Minimum Every Software Developer" |
| 15 | + "Absolutely, Positively Must Know About Unicode " |
| 16 | + "and Character Sets (No Excuses!)"), |
| 17 | + blog__name='Joel on Software', |
| 18 | + authors=(author, ) |
| 19 | + ) |
| 20 | + |
| 21 | + |
| 22 | +def test_pagination_with_single_entry(single_entry, client): |
| 23 | + |
| 24 | + expected = { |
| 25 | + "data": [ |
| 26 | + { |
| 27 | + "type": "posts", |
| 28 | + "id": "1", |
| 29 | + "attributes": |
| 30 | + { |
| 31 | + "headline": "The Absolute Minimum Every Software DeveloperAbsolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)", |
| 32 | + "bodyText": "Here goes the body text", |
| 33 | + "pubDate": None, |
| 34 | + "modDate": None |
| 35 | + }, |
| 36 | + "relationships": |
| 37 | + { |
| 38 | + "blog": { |
| 39 | + "data": {"type": "blogs", "id": "1"} |
| 40 | + }, |
| 41 | + "authors": { |
| 42 | + "meta": {"count": 1}, |
| 43 | + "data": [{"type": "authors", "id": "1"}] |
| 44 | + } |
| 45 | + } |
| 46 | + }], |
| 47 | + "links": { |
| 48 | + "first": "http://testserver/entries?page=1", |
| 49 | + "last": "http://testserver/entries?page=1", |
| 50 | + "next": None, |
| 51 | + "prev": None, |
| 52 | + }, |
| 53 | + "meta": |
| 54 | + { |
| 55 | + "pagination": |
| 56 | + { |
| 57 | + "page": 1, |
| 58 | + "pages": 1, |
| 59 | + "count": 1 |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + response = client.get(reverse("entry-list")) |
| 65 | + content_dump = redump_json(response.content) |
| 66 | + expected_dump = dump_json(expected) |
| 67 | + |
| 68 | + assert content_dump == expected_dump |
0 commit comments