-
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.
- Loading branch information
1 parent
d78a21c
commit 1a5c039
Showing
8 changed files
with
178 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
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
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,51 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from rest_framework import serializers | ||
|
||
from drf_spectacular.generators import SchemaGenerator | ||
from drf_spectacular.utils import OpenApiResponse, OpenApiWebhook, extend_schema | ||
from tests import assert_schema, generate_schema | ||
|
||
|
||
class EventSerializer(serializers.Serializer): | ||
id = serializers.CharField(read_only=True) | ||
change = serializers.CharField() | ||
external_id = serializers.CharField(write_only=True) | ||
|
||
|
||
urlpatterns = [] # type: ignore | ||
openapi_webhooks = [ | ||
OpenApiWebhook( | ||
name='SubscriptionEvent', | ||
decorator=extend_schema( | ||
summary="some summary", | ||
description='pushes events to callbackUrl as "application/x-www-form-urlencoded"', | ||
request={ | ||
'application/x-www-form-urlencoded': EventSerializer, | ||
}, | ||
responses={ | ||
200: OpenApiResponse(description='event was successfully received'), | ||
'4XX': OpenApiResponse(description='event will be retried shortly'), | ||
}, | ||
), | ||
) | ||
] | ||
|
||
|
||
@mock.patch('drf_spectacular.settings.spectacular_settings.OAS_VERSION', '3.1.0') | ||
def test_webhooks(no_warnings): | ||
assert_schema( | ||
generate_schema(None, patterns=[], webhooks=openapi_webhooks), | ||
'tests/test_webhooks.yml' | ||
) | ||
|
||
|
||
@pytest.mark.urls(__name__) | ||
@mock.patch('drf_spectacular.settings.spectacular_settings.OAS_VERSION', '3.1.0') | ||
@mock.patch('drf_spectacular.settings.spectacular_settings.WEBHOOKS', openapi_webhooks) | ||
def test_webhooks_settings(no_warnings): | ||
assert_schema( | ||
SchemaGenerator().get_schema(request=None, public=True), | ||
'tests/test_webhooks.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,38 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: '' | ||
version: 0.0.0 | ||
paths: {} | ||
components: | ||
schemas: | ||
Event: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
readOnly: true | ||
change: | ||
type: string | ||
external_id: | ||
type: string | ||
writeOnly: true | ||
required: | ||
- change | ||
- external_id | ||
- id | ||
webhooks: | ||
SubscriptionEvent: | ||
post: | ||
description: pushes events to callbackUrl as "application/x-www-form-urlencoded" | ||
summary: some summary | ||
requestBody: | ||
content: | ||
application/x-www-form-urlencoded: | ||
schema: | ||
$ref: '#/components/schemas/Event' | ||
required: true | ||
responses: | ||
'200': | ||
description: event was successfully received | ||
4XX: | ||
description: event will be retried shortly |