This repository has been archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of failing test on related_field
- Loading branch information
Darragh Duffy
committed
Nov 23, 2022
1 parent
1929ad3
commit 0fc4214
Showing
6 changed files
with
86 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework_json_api.views import RelationshipView | ||
from rest_framework.views import Response | ||
|
||
class TeamMembersRelationshipView(RelationshipView): | ||
def post(self, request, *args, **kwargs): | ||
return Response({}, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from openapi_tester import SchemaTester | ||
from django.urls import reverse | ||
from rest_framework.test import APITestCase | ||
from rest_framework.response import Response | ||
from tests.utils import TEST_ROOT | ||
|
||
schema_tester = SchemaTester(schema_file_path=str(TEST_ROOT) + "/schemas/manual_reference_schema.yaml") | ||
|
||
class BaseAPITestCase(APITestCase): | ||
"""Base test class for api views including schema validation""" | ||
|
||
@staticmethod | ||
def assertResponse(response: Response, **kwargs) -> None: | ||
"""helper to run validate_response and pass kwargs to it""" | ||
schema_tester.validate_response(response=response, **kwargs) | ||
|
||
# @override_settings(USE_X_FORWARDED_HOST=True) | ||
class TeamsAPITests(BaseAPITestCase): | ||
def test_schema_using_assert_response(self): | ||
response = self.client.post( | ||
reverse( | ||
"team-members-relation", | ||
kwargs={ | ||
"version": "v1", | ||
"pk": 1, | ||
"related_field": "members", | ||
}, | ||
), | ||
content_type="application/vnd.api+json", | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertResponse(response) |