Skip to content

Commit f52953d

Browse files
committed
Support basic re_path
1 parent 23a8b57 commit f52953d

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

openapi_core/contrib/django/requests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def create(cls, request):
3636
else:
3737
route = cls.path_regex.sub(
3838
r'{\1}', request.resolver_match.route)
39+
# Delete start marker and expression marker to allow concatenation.
40+
if route[:1] == "^":
41+
route = route[1:]
42+
if route[-1:] == "$":
43+
route = route[:-1]
3944
path_pattern = '/' + route
4045

4146
path = request.resolver_match and request.resolver_match.kwargs or {}

tests/integration/contrib/django/data/djangoproject/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'django.middleware.clickjacking.XFrameOptionsMiddleware',
5151
]
5252

53-
ROOT_URLCONF = 'djangotest.urls'
53+
ROOT_URLCONF = 'djangoproject.urls'
5454

5555
TEMPLATES = [
5656
{

tests/integration/contrib/django/data/djangoproject/testapp/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
class TestView(APIView):
1616

17-
def get(self, request, pk):
17+
def get(self, request, pk=None):
1818
with open(settings.OPENAPI_SPEC_PATH) as file:
1919
spec_yaml = file.read()
20-
spec_dict = yaml.load(spec_yaml)
20+
spec_dict = yaml.safe_load(spec_yaml)
2121
spec = create_spec(spec_dict)
2222

2323
openapi_request = DjangoOpenAPIRequest(request)

tests/integration/contrib/django/data/djangoproject/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import include, path
18-
from djangotest.testapp import views
17+
from django.urls import include, path, re_path
18+
from djangoproject.testapp import views
1919

2020
urlpatterns = [
2121
path('admin/', admin.site.urls),
@@ -28,4 +28,5 @@
2828
views.TestView.as_view(),
2929
name='test',
3030
),
31+
re_path(r"^api/test-regexp/$", views.TestView.as_view()),
3132
]

tests/integration/contrib/django/data/openapi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ paths:
3030
schema:
3131
type: integer
3232
minimum: 1
33+
34+
/api/test-simple/:
35+
get:
36+
responses:
37+
'200':
38+
description: Success.
39+
content:
40+
application/json:
41+
schema:
42+
type: object
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from six import b
4+
5+
6+
class TestDjangoRESTFrameworkAPIView(object):
7+
8+
@pytest.fixture
9+
def http_client(self):
10+
from django.test import Client
11+
return Client()
12+
13+
def test_get(self, http_client):
14+
response = http_client.get('/api/test-simple/')
15+
16+
assert response.content == b('{"test": "test_val"}')

0 commit comments

Comments
 (0)