|
8 | 8 | from rest_framework_json_api.schemas.openapi import AutoSchema, SchemaGenerator |
9 | 9 |
|
10 | 10 | from example import views |
11 | | -from example.tests import TestBase |
12 | 11 |
|
13 | 12 |
|
14 | 13 | def create_request(path): |
@@ -126,34 +125,33 @@ def test_schema_construction(): |
126 | 125 | assert 'components' in schema |
127 | 126 |
|
128 | 127 |
|
129 | | -class TestSchemaRelatedField(TestBase): |
130 | | - def test_schema_related_serializers(self): |
131 | | - """ |
132 | | - Confirm that paths are generated for related fields. For example: |
133 | | - url path '/authors/{pk}/{related_field>}/' generates: |
134 | | - /authors/{id}/relationships/comments/ |
135 | | - /authors/{id}/relationships/entries/ |
136 | | - /authors/{id}/relationships/first_entry/ -- Maybe? |
137 | | - /authors/{id}/comments/ |
138 | | - /authors/{id}/entries/ |
139 | | - /authors/{id}/first_entry/ |
140 | | - and confirm that the schema for the related field is properly rendered |
141 | | - """ |
142 | | - generator = SchemaGenerator() |
143 | | - request = create_request('/') |
144 | | - schema = generator.get_schema(request=request) |
145 | | - # make sure the path's relationship and related {related_field}'s got expanded |
146 | | - assert '/authors/{id}/relationships/entries' in schema['paths'] |
147 | | - assert '/authors/{id}/relationships/comments' in schema['paths'] |
148 | | - # first_entry is a special case (SerializerMethodRelatedField) |
149 | | - # TODO: '/authors/{id}/relationships/first_entry' supposed to be there? |
150 | | - # It fails when doing the actual GET, so this schema excluding it is OK. |
151 | | - # assert '/authors/{id}/relationships/first_entry/' in schema['paths'] |
152 | | - assert '/authors/{id}/comments/' in schema['paths'] |
153 | | - assert '/authors/{id}/entries/' in schema['paths'] |
154 | | - assert '/authors/{id}/first_entry/' in schema['paths'] |
155 | | - first_get = schema['paths']['/authors/{id}/first_entry/']['get']['responses']['200'] |
156 | | - first_schema = first_get['content']['application/vnd.api+json']['schema'] |
157 | | - first_props = first_schema['properties']['data'] |
158 | | - assert '$ref' in first_props |
159 | | - assert first_props['$ref'] == '#/components/schemas/Entry' |
| 128 | +def test_schema_related_serializers(): |
| 129 | + """ |
| 130 | + Confirm that paths are generated for related fields. For example: |
| 131 | + url path '/authors/{pk}/{related_field>}/' generates: |
| 132 | + /authors/{id}/relationships/comments/ |
| 133 | + /authors/{id}/relationships/entries/ |
| 134 | + /authors/{id}/relationships/first_entry/ -- Maybe? |
| 135 | + /authors/{id}/comments/ |
| 136 | + /authors/{id}/entries/ |
| 137 | + /authors/{id}/first_entry/ |
| 138 | + and confirm that the schema for the related field is properly rendered |
| 139 | + """ |
| 140 | + generator = SchemaGenerator() |
| 141 | + request = create_request('/') |
| 142 | + schema = generator.get_schema(request=request) |
| 143 | + # make sure the path's relationship and related {related_field}'s got expanded |
| 144 | + assert '/authors/{id}/relationships/entries' in schema['paths'] |
| 145 | + assert '/authors/{id}/relationships/comments' in schema['paths'] |
| 146 | + # first_entry is a special case (SerializerMethodRelatedField) |
| 147 | + # TODO: '/authors/{id}/relationships/first_entry' supposed to be there? |
| 148 | + # It fails when doing the actual GET, so this schema excluding it is OK. |
| 149 | + # assert '/authors/{id}/relationships/first_entry/' in schema['paths'] |
| 150 | + assert '/authors/{id}/comments/' in schema['paths'] |
| 151 | + assert '/authors/{id}/entries/' in schema['paths'] |
| 152 | + assert '/authors/{id}/first_entry/' in schema['paths'] |
| 153 | + first_get = schema['paths']['/authors/{id}/first_entry/']['get']['responses']['200'] |
| 154 | + first_schema = first_get['content']['application/vnd.api+json']['schema'] |
| 155 | + first_props = first_schema['properties']['data'] |
| 156 | + assert '$ref' in first_props |
| 157 | + assert first_props['$ref'] == '#/components/schemas/Entry' |
0 commit comments