1
1
import contextlib
2
2
from io import StringIO
3
+ import pytest
4
+ import sys
3
5
4
6
from django .core .management import call_command
5
7
from django .test import SimpleTestCase
18
20
]
19
21
20
22
23
+ @pytest .mark .skipif (sys .version_info < (3 , 9 ), reason = "requires python 3.9+" )
21
24
class TestPollExample (SimpleTestCase ):
22
25
q1 = None
23
26
q2 = None
24
27
q3 = None
25
28
26
29
databases = {"default" }
27
30
31
+ typer = ""
32
+
28
33
def setUp (self ):
29
34
self .q1 = Question .objects .create (
30
35
question_text = "Is Putin a war criminal?" ,
@@ -51,15 +56,18 @@ def test_poll_complete(self):
51
56
result1 = StringIO ()
52
57
with contextlib .redirect_stdout (result1 ):
53
58
call_command (
54
- "shellcompletion" , "complete" , shell = shell , cmd_str = "closepoll "
59
+ "shellcompletion" ,
60
+ "complete" ,
61
+ shell = shell ,
62
+ cmd_str = f"closepoll{ self .typer } " ,
55
63
)
56
64
result2 = StringIO ()
57
65
with contextlib .redirect_stdout (result2 ):
58
66
call_command (
59
67
"shellcompletion" ,
60
68
"complete" ,
61
69
shell = shell ,
62
- cmd_str = "./manage.py closepoll " ,
70
+ cmd_str = f "./manage.py closepoll{ self . typer } " ,
63
71
)
64
72
65
73
result = result1 .getvalue ()
@@ -70,23 +78,23 @@ def test_poll_complete(self):
70
78
self .assertTrue (q .question_text in result )
71
79
72
80
def test_tutorial1 (self ):
73
- result = run_command ("closepoll_t1" , str (self .q2 .id ))
81
+ result = run_command (f "closepoll_t1{ self . typer } " , str (self .q2 .id ))
74
82
self .assertFalse (result [1 ])
75
83
self .assertTrue ("Successfully closed poll" in result [0 ])
76
84
77
85
def test_tutorial2 (self ):
78
- result = run_command ("closepoll_t2" , str (self .q2 .id ))
86
+ result = run_command (f "closepoll_t2{ self . typer } " , str (self .q2 .id ))
79
87
self .assertFalse (result [1 ])
80
88
self .assertTrue ("Successfully closed poll" in result [0 ])
81
89
82
90
def test_tutorial_parser (self ):
83
- result = run_command ("closepoll_t3" , str (self .q1 .id ))
91
+ result = run_command (f "closepoll_t3{ self . typer } " , str (self .q1 .id ))
84
92
self .assertFalse (result [1 ])
85
93
86
94
def test_tutorial_parser_cmd (self ):
87
95
log = StringIO ()
88
- call_command ("closepoll_t3" , str (self .q1 .id ), stdout = log )
89
- cmd = get_command ("closepoll_t3" , stdout = log )
96
+ call_command (f "closepoll_t3{ self . typer } " , str (self .q1 .id ), stdout = log )
97
+ cmd = get_command (f "closepoll_t3{ self . typer } " , stdout = log )
90
98
cmd ([self .q1 ])
91
99
cmd (polls = [self .q1 ])
92
100
# these don't work, maybe revisit in future?
@@ -96,13 +104,18 @@ def test_tutorial_parser_cmd(self):
96
104
97
105
def test_tutorial_modelobjparser_cmd (self ):
98
106
log = StringIO ()
99
- call_command ("closepoll_t6" , str (self .q1 .id ), stdout = log )
100
- cmd = get_command ("closepoll_t6" , stdout = log )
107
+ call_command (f "closepoll_t6{ self . typer } " , str (self .q1 .id ), stdout = log )
108
+ cmd = get_command (f "closepoll_t6{ self . typer } " , stdout = log )
101
109
cmd ([self .q1 ])
102
110
cmd (polls = [self .q1 ])
103
111
self .assertEqual (log .getvalue ().count ("Successfully" ), 3 )
104
112
105
113
def test_poll_ex (self ):
106
- result = run_command ("closepoll" , str (self .q2 .id ))
114
+ result = run_command (f "closepoll{ self . typer } " , str (self .q2 .id ))
107
115
self .assertFalse (result [1 ])
108
116
self .assertTrue ("Successfully closed poll" in result [0 ])
117
+
118
+
119
+ @pytest .mark .skipif (sys .version_info < (3 , 9 ), reason = "requires python 3.9+" )
120
+ class TestPollExampleTyper (SimpleTestCase ):
121
+ typer = "_typer"
0 commit comments