-
Notifications
You must be signed in to change notification settings - Fork 11
/
test-cases.py
184 lines (141 loc) · 5.2 KB
/
test-cases.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import unittest
from subprocess import Popen, PIPE
def run(args):
command = ['coverage', 'run', '--branch', '-a', '../make-prefetch.py'] + args
process = Popen(command, stdout=PIPE, stderr=PIPE)
(stdout, stderr) = process.communicate();
return (process.returncode, stdout, stderr)
class TestHelp(unittest.TestCase):
def test_help_short(self):
(exitcode, stdout, stderr) = run(['-h'])
self.assertEqual(exitcode, 0)
self.assertTrue(b'Create a prefetch statement' in stdout)
def test_help_long(self):
(exitcode, stdout, stderr) = run(['--help'])
self.assertEqual(exitcode, 0)
self.assertTrue(b'Create a prefetch statement' in stdout)
class TestURL(unittest.TestCase):
def test_url(self):
(exitcode, stdout, stderr) = run(['http://localhost:36465/hodor.txt'])
expected = (
b'prefetch '
b'hodor.txt '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://localhost:36465/hodor.txt '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_url_name(self):
(exitcode, stdout, stderr) = run(['--name', 'bran.txt',
'http://localhost:36465/hodor.txt'])
expected = (
b'prefetch '
b'bran.txt '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://localhost:36465/hodor.txt '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_url_no_name(self):
(exitcode, stdout, stderr) = run(['http://localhost:36465/'])
expected = (
b'prefetch '
b'REPLACEME '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://localhost:36465/ '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
class TestFile(unittest.TestCase):
def test_file(self):
(exitcode, stdout, stderr) = run(['hodor.txt'])
expected = (
b'prefetch '
b'hodor.txt '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://REPLACEME '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_sha1(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-a', 'sha1'])
expected = (
b'prefetch '
b'hodor.txt '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://REPLACEME'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_sha256(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-a', 'sha256'])
expected = (
b'prefetch '
b'hodor.txt '
b'size:5 '
b'http://REPLACEME '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_url(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-u', 'http://example.com'])
expected = (
b'prefetch '
b'hodor.txt '
b'sha1:c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size:5 '
b'http://example.com '
b'sha256:aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_value_sha1(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-o', 'value', '-a', 'sha1'])
expected = b'c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687'
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_value_sha256(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-o', 'value', '-a',
'sha256'])
expected = (
b'aa116aa7b00b3006a1cf72219634cb1edbfad6abb1708c2e01b0409800f958b5'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_value_error(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-o', 'value'])
expected = b'You must specify a hash algorithm to use'
self.assertEqual(exitcode, 2)
self.assertEqual(expected, stderr.strip())
def test_file_value_davis(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-o', 'davis'])
expected = (
b'begin prefetch block\n'
b'add prefetch item '
b'name=hodor.txt '
b'sha1=c6447b82fbb4b8e7dbcf2d28a4d7372f5dc32687 '
b'size=5 '
b'url=http://REPLACEME\n'
b'collect prefetch items\n'
b'end prefetch block'
)
self.assertEqual(exitcode, 0)
self.assertEqual(expected, stdout.strip())
def test_file_value_davis_error(self):
(exitcode, stdout, stderr) = run(['hodor.txt', '-o', 'davis', '-a',
'sha256'])
expected = b'Algorithm sha256 is not supported in davis downloads'
self.assertEqual(exitcode, 2)
self.assertEqual(expected, stderr.strip())
if __name__ == '__main__':
unittest.main()