|
1 | 1 | import json |
2 | 2 | from datetime import datetime |
3 | 3 |
|
4 | | -from django.test import RequestFactory |
| 4 | +from django.test import RequestFactory, override_settings |
5 | 5 | from django.utils import timezone |
6 | 6 | from rest_framework import status |
7 | 7 | from rest_framework.decorators import action |
@@ -92,6 +92,18 @@ def test_get_blog_relationship_entry_set(self): |
92 | 92 |
|
93 | 93 | assert response.data == expected_data |
94 | 94 |
|
| 95 | + @override_settings(JSON_API_FORMAT_RELATED_LINKS="dasherize") |
| 96 | + def test_get_blog_relationship_entry_set_with_formatted_link(self): |
| 97 | + response = self.client.get( |
| 98 | + "/blogs/{}/relationships/entry-set".format(self.blog.id) |
| 99 | + ) |
| 100 | + expected_data = [ |
| 101 | + {"type": format_resource_type("Entry"), "id": str(self.first_entry.id)}, |
| 102 | + {"type": format_resource_type("Entry"), "id": str(self.second_entry.id)}, |
| 103 | + ] |
| 104 | + |
| 105 | + assert response.data == expected_data |
| 106 | + |
95 | 107 | def test_put_entry_relationship_blog_returns_405(self): |
96 | 108 | url = "/entries/{}/relationships/blog".format(self.first_entry.id) |
97 | 109 | response = self.client.put(url, data={}) |
@@ -507,6 +519,17 @@ def test_retrieve_related_None(self): |
507 | 519 | self.assertEqual(resp.status_code, 200) |
508 | 520 | self.assertEqual(resp.json(), {"data": None}) |
509 | 521 |
|
| 522 | + @override_settings(JSON_API_FORMAT_RELATED_LINKS="dasherize") |
| 523 | + def test_retrieve_related_with_formatted_link(self): |
| 524 | + first_entry = EntryFactory(authors=(self.author,)) |
| 525 | + |
| 526 | + kwargs = {"pk": self.author.pk, "related_field": "first-entry"} |
| 527 | + url = reverse("author-related", kwargs=kwargs) |
| 528 | + resp = self.client.get(url) |
| 529 | + |
| 530 | + self.assertEqual(resp.status_code, 200) |
| 531 | + self.assertEqual(resp.json()["data"]["id"], str(first_entry.id)) |
| 532 | + |
510 | 533 |
|
511 | 534 | class TestValidationErrorResponses(TestBase): |
512 | 535 | def test_if_returns_error_on_empty_post(self): |
|
0 commit comments