-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_runs.py
158 lines (141 loc) · 4.24 KB
/
test_runs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
Miscellaneous tests - mostly for coverage
"""
from io import StringIO
import sys
import subprocess
from django.core.management import call_command
from django.test import TestCase
import pexpect
import platform
class TestDeploy(TestCase):
def test_deploy_routine(self):
out = StringIO()
err = StringIO()
call_command("routine", "deploy", "--prepare", stdout=out, stderr=err)
self.assertTrue(out.getvalue())
self.assertTrue(
"makemigrations" in out.getvalue()
and "migrate" in out.getvalue()
and "renderstatic" in out.getvalue()
and "collectstatic" in out.getvalue()
)
self.assertFalse(err.getvalue().strip())
def test_deploy_routine_subprocess(self):
out = StringIO()
err = StringIO()
call_command(
"routine", "deploy", "--prepare", stdout=out, stderr=err, subprocess=True
)
self.assertTrue(out.getvalue())
self.assertTrue(
"makemigrations" in out.getvalue()
and "migrate" in out.getvalue()
and "renderstatic" in out.getvalue()
and "collectstatic" in out.getvalue()
)
self.assertFalse(err.getvalue().strip())
def test_subprocess_error():
result = subprocess.run(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_subproc_error",
"subproc-error",
"--subprocess",
],
text=True,
capture_output=True,
)
assert "panic!" in result.stderr
assert "Subprocess command failed" in result.stderr
def test_subprocess_opt_error():
result = subprocess.run(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_subproc_opt_error",
"subproc-opt-error",
"--subprocess",
],
text=True,
capture_output=True,
)
assert (
"CommandError: Failed to convert collectstatic options to CLI format: {'not-an-option': False}"
in result.stderr
)
if platform.system() == "Windows":
from winpty import PtyProcess
import time
def test_option_toggle():
result = subprocess.run(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_option_toggle",
"option-on",
"--subprocess",
],
text=True,
capture_output=True,
)
assert "static files copied." in result.stdout
proc = PtyProcess.spawn(
" ".join(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_option_toggle",
"option-off",
"--subprocess",
]
)
)
time.sleep(3)
initial_output = proc.read(1024)
assert "Type 'yes' to continue, or 'no' to cancel:" in initial_output
proc.write("yes\r\n")
time.sleep(3)
dir_output = proc.read(4096)
assert "static files copied." in dir_output
else:
def test_option_toggle():
child = pexpect.spawn(
" ".join(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_option_toggle",
"option-on",
"--subprocess",
]
)
)
child.expect("static files copied.")
child = pexpect.spawn(
" ".join(
[
sys.executable,
"./manage.py",
"routine",
"--settings",
"tests.settings_option_toggle",
"option-off",
"--subprocess",
]
)
)
child.expect("Type 'yes' to continue, or 'no' to cancel:")
child.sendline("yes")
child.expect("static files copied.")