Skip to content

Commit 47d3873

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

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_decorators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
import unittest
3+
14
import pytest
25
from django.test import TestCase
36

@@ -187,6 +190,20 @@ def test_action(request):
187190

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

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

0 commit comments

Comments
 (0)