-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lookup_value_regex handling of non string types
- Loading branch information
Showing
4 changed files
with
237 additions
and
5 deletions.
There are no files selected for viewing
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,38 @@ | ||
import pytest | ||
from django.db import models | ||
from django.urls import include, re_path | ||
from rest_framework import serializers, viewsets | ||
from rest_framework.routers import SimpleRouter | ||
|
||
from tests import assert_schema, generate_schema | ||
|
||
|
||
class Book(models.Model): | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=255) | ||
|
||
class BookSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = Book | ||
fields = ('name',) | ||
|
||
def _generate_simple_router_schema(viewset): | ||
router = SimpleRouter() | ||
router.register('books', viewset, basename='books') | ||
urlpatterns = [ | ||
re_path('', include(router.urls)), | ||
] | ||
return generate_schema(None, patterns=urlpatterns) | ||
|
||
@pytest.mark.contrib('rest_framework_lookup_value') | ||
def test_drf_lookup_value_regex_integer(no_warnings): | ||
class BookViewSet(viewsets.ModelViewSet): | ||
queryset = Book.objects.all() | ||
serializer_class = BookSerializer | ||
lookup_field = 'id' | ||
lookup_value_regex = r'\d+' | ||
|
||
assert_schema( | ||
_generate_simple_router_schema(BookViewSet), | ||
'tests/contrib/test_drf_lookup_value.yml', | ||
) |
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,194 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: '' | ||
version: 0.0.0 | ||
paths: | ||
/books/: | ||
get: | ||
operationId: books_list | ||
tags: | ||
- books | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Book' | ||
description: '' | ||
post: | ||
operationId: books_create | ||
tags: | ||
- books | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
application/x-www-form-urlencoded: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
multipart/form-data: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
required: true | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'201': | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
description: '' | ||
/books/{id}/: | ||
get: | ||
operationId: books_retrieve | ||
parameters: | ||
- in: path | ||
name: id | ||
schema: | ||
type: integer | ||
maximum: 9223372036854775807 | ||
minimum: -9223372036854775808 | ||
format: int64 | ||
description: A unique value identifying this book. | ||
required: true | ||
tags: | ||
- books | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
description: '' | ||
put: | ||
operationId: books_update | ||
parameters: | ||
- in: path | ||
name: id | ||
schema: | ||
type: integer | ||
maximum: 9223372036854775807 | ||
minimum: -9223372036854775808 | ||
format: int64 | ||
description: A unique value identifying this book. | ||
required: true | ||
tags: | ||
- books | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
application/x-www-form-urlencoded: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
multipart/form-data: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
required: true | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
description: '' | ||
patch: | ||
operationId: books_partial_update | ||
parameters: | ||
- in: path | ||
name: id | ||
schema: | ||
type: integer | ||
maximum: 9223372036854775807 | ||
minimum: -9223372036854775808 | ||
format: int64 | ||
description: A unique value identifying this book. | ||
required: true | ||
tags: | ||
- books | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PatchedBook' | ||
application/x-www-form-urlencoded: | ||
schema: | ||
$ref: '#/components/schemas/PatchedBook' | ||
multipart/form-data: | ||
schema: | ||
$ref: '#/components/schemas/PatchedBook' | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Book' | ||
description: '' | ||
delete: | ||
operationId: books_destroy | ||
parameters: | ||
- in: path | ||
name: id | ||
schema: | ||
type: integer | ||
maximum: 9223372036854775807 | ||
minimum: -9223372036854775808 | ||
format: int64 | ||
description: A unique value identifying this book. | ||
required: true | ||
tags: | ||
- books | ||
security: | ||
- cookieAuth: [] | ||
- basicAuth: [] | ||
- {} | ||
responses: | ||
'204': | ||
description: No response body | ||
components: | ||
schemas: | ||
Book: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
maxLength: 255 | ||
required: | ||
- name | ||
PatchedBook: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
maxLength: 255 | ||
securitySchemes: | ||
basicAuth: | ||
type: http | ||
scheme: basic | ||
cookieAuth: | ||
type: apiKey | ||
in: cookie | ||
name: sessionid |
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