|
1 | 1 | import pytest
|
| 2 | +from django.conf.urls import re_path |
| 3 | +from rest_framework.routers import SimpleRouter |
2 | 4 |
|
3 | 5 | from rest_framework_json_api.relations import HyperlinkedRelatedField
|
| 6 | +from rest_framework_json_api.views import ModelViewSet, RelationshipView |
4 | 7 |
|
5 | 8 | from .models import BasicModel
|
6 | 9 |
|
7 | 10 |
|
8 |
| -@pytest.mark.urls("tests.urls") |
| 11 | +@pytest.mark.urls(__name__) |
9 | 12 | @pytest.mark.parametrize(
|
10 | 13 | "format_links,expected_url_segment",
|
11 | 14 | [
|
@@ -38,3 +41,34 @@ def test_relationship_urls_respect_format_links(
|
38 | 41 | actual = field.get_links(model)
|
39 | 42 |
|
40 | 43 | assert expected == actual
|
| 44 | + |
| 45 | + |
| 46 | +# Routing setup |
| 47 | + |
| 48 | + |
| 49 | +class BasicModelViewSet(ModelViewSet): |
| 50 | + class Meta: |
| 51 | + model = BasicModel |
| 52 | + |
| 53 | + |
| 54 | +class BasicModelRelationshipView(RelationshipView): |
| 55 | + queryset = BasicModel.objects |
| 56 | + |
| 57 | + |
| 58 | +router = SimpleRouter() |
| 59 | +router.register(r"basic_models", BasicModelViewSet, basename="basic-model") |
| 60 | + |
| 61 | +urlpatterns = [ |
| 62 | + re_path( |
| 63 | + r"^basic_models/(?P<pk>[^/.]+)/(?P<related_field>[^/.]+)/$", |
| 64 | + BasicModelViewSet.as_view({"get": "retrieve_related"}), |
| 65 | + name="basic-model-related", |
| 66 | + ), |
| 67 | + re_path( |
| 68 | + r"^basic_models/(?P<pk>[^/.]+)/relationships/(?P<related_field>[^/.]+)/$", |
| 69 | + BasicModelRelationshipView.as_view(), |
| 70 | + name="basic-model-relationships", |
| 71 | + ), |
| 72 | +] |
| 73 | + |
| 74 | +urlpatterns += router.urls |
0 commit comments