Skip to content

Commit fcfca6e

Browse files
committed
Implement tests for HTTPMethod from Python 3.11
1 parent 589b5dc commit fcfca6e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tests/test_decorators.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24
from django.test import TestCase
35

@@ -187,6 +189,20 @@ def test_action(request):
187189

188190
assert str(excinfo.value) == "@action() missing required argument: 'detail'"
189191

192+
@pytest.mark.skipif(sys.version_info < (3, 11), reason="HTTPMethod was added in Python 3.11")
193+
def test_method_mapping_http_method(self):
194+
from http import HTTPMethod
195+
196+
method_names = [getattr(HTTPMethod, name.upper()) for name in APIView.http_method_names]
197+
198+
@action(detail=False, methods=method_names)
199+
def test_action():
200+
raise NotImplementedError
201+
202+
expected_mapping = {name: test_action.__name__ for name in APIView.http_method_names}
203+
204+
assert test_action.mapping == expected_mapping
205+
190206
def test_method_mapping_http_methods(self):
191207
# All HTTP methods should be mappable
192208
@action(detail=False, methods=[])

0 commit comments

Comments
 (0)