Merge ~hloeung/content-cache-charm:master into content-cache-charm:master
- Git
- lp:~hloeung/content-cache-charm
- master
- Merge into master
Proposed by
Haw Loeung
Status: | Merged |
---|---|
Approved by: | Haw Loeung |
Approved revision: | b3c04d1fd674ff31aba84eb1cd6822a46219f9d4 |
Merged at revision: | d4f74487db21d04840171d47bf65494a70425139 |
Proposed branch: | ~hloeung/content-cache-charm:master |
Merge into: | content-cache-charm:master |
Diff against target: |
316 lines (+79/-79) 3 files modified
tests/unit/test_content_cache.py (+66/-66) tests/unit/test_haproxy.py (+9/-9) tests/unit/test_utils.py (+4/-4) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stuart Bishop (community) | Approve | ||
Review via email: mp+365137@code.launchpad.net |
Commit message
Switch unit tests from expected/current to want/got based on reviews
Description of the change
To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Revision history for this message
Stuart Bishop (stub) wrote : | # |
Sure.
Neither Python nor us has a policy or even preferred idiom on this naming, and I'm fine with either what you had or switching to the Go idiom.
review:
Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision d4f74487db21d04
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py |
2 | index 82b1bad..a765bf3 100644 |
3 | --- a/tests/unit/test_content_cache.py |
4 | +++ b/tests/unit/test_content_cache.py |
5 | @@ -59,33 +59,33 @@ class TestCharm(unittest.TestCase): |
6 | '''Test correct flags set via upgrade-charm hook''' |
7 | content_cache.upgrade_charm() |
8 | self.assertFalse(status.maintenance.assert_called()) |
9 | - expected = [mock.call('content_cache.active'), |
10 | - mock.call('content_cache.installed'), |
11 | - mock.call('content_cache.haproxy.configured'), |
12 | - mock.call('content_cache.nginx.configured'), |
13 | - mock.call('nagios-nrpe.configured')] |
14 | - self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
15 | + want = [mock.call('content_cache.active'), |
16 | + mock.call('content_cache.installed'), |
17 | + mock.call('content_cache.haproxy.configured'), |
18 | + mock.call('content_cache.nginx.configured'), |
19 | + mock.call('nagios-nrpe.configured')] |
20 | + self.assertFalse(clear_flag.assert_has_calls(want, any_order=True)) |
21 | |
22 | @mock.patch('charms.reactive.clear_flag') |
23 | @mock.patch('charms.reactive.set_flag') |
24 | def test_hook_install_flags(self, set_flag, clear_flag): |
25 | '''Test correct flags are set via install charm hook''' |
26 | content_cache.install() |
27 | - expected = [mock.call('content_cache.installed')] |
28 | - self.assertFalse(set_flag.assert_has_calls(expected, any_order=True)) |
29 | + want = [mock.call('content_cache.installed')] |
30 | + self.assertFalse(set_flag.assert_has_calls(want, any_order=True)) |
31 | |
32 | - expected = [mock.call('content_cache.active'), |
33 | - mock.call('content_cache.haproxy.configured'), |
34 | - mock.call('content_cache.nginx.configured')] |
35 | - self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
36 | + want = [mock.call('content_cache.active'), |
37 | + mock.call('content_cache.haproxy.configured'), |
38 | + mock.call('content_cache.nginx.configured')] |
39 | + self.assertFalse(clear_flag.assert_has_calls(want, any_order=True)) |
40 | |
41 | @mock.patch('charms.reactive.clear_flag') |
42 | def test_hook_config_changed_flags(self, clear_flag): |
43 | '''Test correct flags are set via config-changed charm hook''' |
44 | content_cache.config_changed() |
45 | - expected = [mock.call('content_cache.haproxy.configured'), |
46 | - mock.call('content_cache.nginx.configured')] |
47 | - self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True)) |
48 | + want = [mock.call('content_cache.haproxy.configured'), |
49 | + mock.call('content_cache.nginx.configured')] |
50 | + self.assertFalse(clear_flag.assert_has_calls(want, any_order=True)) |
51 | |
52 | @mock.patch('charms.reactive.set_flag') |
53 | def test_hook_set_active(self, set_flag): |
54 | @@ -145,11 +145,11 @@ class TestCharm(unittest.TestCase): |
55 | for site in ['site1.local', 'site2.local', 'site3.local']: |
56 | with open('tests/unit/files/nginx_config_rendered_test_output-{}.txt'.format(site), |
57 | 'r', encoding='utf-8') as f: |
58 | - expected = f.read() |
59 | + want = f.read() |
60 | with open(os.path.join(self.tmpdir, 'sites-available/{}.conf'.format(site)), |
61 | 'r', encoding='utf-8') as f: |
62 | - current = f.read() |
63 | - self.assertEqual(expected, current) |
64 | + got = f.read() |
65 | + self.assertEqual(got, want) |
66 | |
67 | @mock.patch('reactive.content_cache.service_start_or_restart') |
68 | def test_configure_nginx_sites_secrets(self, service_start_or_restart): |
69 | @@ -179,11 +179,11 @@ site1.local: |
70 | for site in ['site1.local']: |
71 | with open('tests/unit/files/nginx_config_rendered_test_output-{}-secrets.txt'.format(site), |
72 | 'r', encoding='utf-8') as f: |
73 | - expected = f.read() |
74 | + want = f.read() |
75 | with open(os.path.join(self.tmpdir, 'sites-available/{}.conf'.format(site)), |
76 | 'r', encoding='utf-8') as f: |
77 | - current = f.read() |
78 | - self.assertEqual(expected, current) |
79 | + got = f.read() |
80 | + self.assertEqual(got, want) |
81 | |
82 | @mock.patch('charms.reactive.clear_flag') |
83 | @mock.patch('charms.reactive.set_flag') |
84 | @@ -218,10 +218,10 @@ site1.local: |
85 | self.assertFalse(service_start_or_restart.assert_not_called()) |
86 | |
87 | with open('tests/unit/files/content_cache_rendered_haproxy_test_output.txt', 'r', encoding='utf-8') as f: |
88 | - expected = f.read() |
89 | + want = f.read() |
90 | with open(os.path.join(self.tmpdir, 'haproxy.cfg'), 'r', encoding='utf-8') as f: |
91 | - current = f.read() |
92 | - self.assertEqual(expected, current) |
93 | + got = f.read() |
94 | + self.assertEqual(got, want) |
95 | |
96 | @mock.patch('charms.reactive.clear_flag') |
97 | @mock.patch('charms.reactive.set_flag') |
98 | @@ -246,41 +246,41 @@ site1.local: |
99 | content_cache.configure_nagios() |
100 | self.assertFalse(status.maintenance.assert_called()) |
101 | |
102 | - expected = [mock.call('site_site1_local_listen', 'site1.local site listen check', |
103 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 80 -j HEAD' |
104 | - ' -u http://site1.local/?token=1868533200_bd98d0a61eb5006de53d00549ba0f78b365b72ad'), |
105 | - mock.call('site_site1_local_cache', 'site1.local cache check', |
106 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 6080 -j HEAD' |
107 | - ' -u http://site1.local/?token=1868533200_bd98d0a61eb5006de53d00549ba0f78b365b72ad'), |
108 | - mock.call('site_site1_local_backend_proxy', 'site1.local backend proxy check', |
109 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 8080 -j HEAD' |
110 | - ' -u http://site1.local/')] |
111 | - self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(expected, any_order=True)) |
112 | - expected = [mock.call('site_site2_local_listen', 'site2.local site listen check', |
113 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 443 -S --sni' |
114 | - ' -j GET -u https://site2.local/check/'), |
115 | - mock.call('site_site2_local_cache', 'site2.local cache check', |
116 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 6081' |
117 | - ' -j GET -u https://site2.local/check/'), |
118 | - mock.call('site_site2_local_backend_proxy', 'site2.local backend proxy check', |
119 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 8081' |
120 | - ' -j GET -u https://site2.local/check/')] |
121 | - self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(expected, any_order=True)) |
122 | - expected = [mock.call('site_site3_local_listen', 'site3.local site listen check', |
123 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 80 -j HEAD' |
124 | - ' -u http://site3.local/'), |
125 | - mock.call('site_site3_local_cache', 'site3.local cache check', |
126 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 6082 -j HEAD' |
127 | - ' -u http://site3.local/'), |
128 | - mock.call('site_site3_local_backend_proxy', 'site3.local backend proxy check', |
129 | - '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 8082 -j HEAD' |
130 | - ' -u http://site3.local/')] |
131 | - self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(expected, any_order=True)) |
132 | + want = [mock.call('site_site1_local_listen', 'site1.local site listen check', |
133 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 80 -j HEAD' |
134 | + ' -u http://site1.local/?token=1868533200_bd98d0a61eb5006de53d00549ba0f78b365b72ad'), |
135 | + mock.call('site_site1_local_cache', 'site1.local cache check', |
136 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 6080 -j HEAD' |
137 | + ' -u http://site1.local/?token=1868533200_bd98d0a61eb5006de53d00549ba0f78b365b72ad'), |
138 | + mock.call('site_site1_local_backend_proxy', 'site1.local backend proxy check', |
139 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site1.local -p 8080 -j HEAD' |
140 | + ' -u http://site1.local/')] |
141 | + self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(want, any_order=True)) |
142 | + want = [mock.call('site_site2_local_listen', 'site2.local site listen check', |
143 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 443 -S --sni' |
144 | + ' -j GET -u https://site2.local/check/'), |
145 | + mock.call('site_site2_local_cache', 'site2.local cache check', |
146 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 6081' |
147 | + ' -j GET -u https://site2.local/check/'), |
148 | + mock.call('site_site2_local_backend_proxy', 'site2.local backend proxy check', |
149 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site2.local -p 8081' |
150 | + ' -j GET -u https://site2.local/check/')] |
151 | + self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(want, any_order=True)) |
152 | + want = [mock.call('site_site3_local_listen', 'site3.local site listen check', |
153 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 80 -j HEAD' |
154 | + ' -u http://site3.local/'), |
155 | + mock.call('site_site3_local_cache', 'site3.local cache check', |
156 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 6082 -j HEAD' |
157 | + ' -u http://site3.local/'), |
158 | + mock.call('site_site3_local_backend_proxy', 'site3.local backend proxy check', |
159 | + '/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -H site3.local -p 8082 -j HEAD' |
160 | + ' -u http://site3.local/')] |
161 | + self.assertFalse(nrpe_instance_mock.add_check.assert_has_calls(want, any_order=True)) |
162 | |
163 | self.assertFalse(nrpe_instance_mock.write.assert_called()) |
164 | |
165 | - expected = [mock.call('nagios-nrpe.configured')] |
166 | - self.assertFalse(set_flag.assert_has_calls(expected, any_order=True)) |
167 | + want = [mock.call('nagios-nrpe.configured')] |
168 | + self.assertFalse(set_flag.assert_has_calls(want, any_order=True)) |
169 | |
170 | def test_sites_from_config(self): |
171 | config_yaml = ''' |
172 | @@ -297,7 +297,7 @@ site3.local: |
173 | backends: |
174 | - 91.189.88.152:80 |
175 | ''' |
176 | - expected = { |
177 | + want = { |
178 | 'site1.local': { |
179 | 'port': 80, |
180 | 'cache_port': 6080, |
181 | @@ -317,7 +317,7 @@ site3.local: |
182 | 'backends': ['91.189.88.152:80'], |
183 | } |
184 | } |
185 | - self.assertEqual(content_cache.sites_from_config(config_yaml), expected) |
186 | + self.assertEqual(want, content_cache.sites_from_config(config_yaml)) |
187 | config_yaml = ''' |
188 | site1.local: |
189 | port: 80 |
190 | @@ -340,14 +340,14 @@ site1.local: |
191 | origin-headers: |
192 | X-Some-Header: myvalue |
193 | ''' |
194 | - expected = { |
195 | + want = { |
196 | 'site1.local': { |
197 | 'origin-headers': { |
198 | 'X-Some-Header': 'myvalue', |
199 | } |
200 | } |
201 | } |
202 | - self.assertEqual(content_cache.secrets_from_config(secrets_yaml), expected) |
203 | + self.assertEqual(content_cache.secrets_from_config(secrets_yaml), want) |
204 | self.assertEqual(content_cache.secrets_from_config(''), {}) |
205 | self.assertEqual(content_cache.secrets_from_config('invalid YAML'), {}) |
206 | self.assertEqual(content_cache.secrets_from_config('invalid\n\tYAML'), {}) |
207 | @@ -367,17 +367,17 @@ site1.local: |
208 | 'signed-url-hmac-key': '${secret}', |
209 | } |
210 | } |
211 | - expected = { |
212 | + want = { |
213 | 'site1.local': { |
214 | 'origin-headers': [{'X-Origin-Key': 'Sae6oob2aethuosh'}], |
215 | 'signed-url-hmac-key': 'Maiqu7ohmeiSh6ooroa0', |
216 | } |
217 | } |
218 | - self.assertEqual(content_cache.interpolate_secrets(config, secrets), expected) |
219 | + self.assertEqual(content_cache.interpolate_secrets(config, secrets), want) |
220 | |
221 | # No secrets to interpolate |
222 | - config = expected |
223 | - self.assertEqual(content_cache.interpolate_secrets(config, secrets), expected) |
224 | + config = want |
225 | + self.assertEqual(content_cache.interpolate_secrets(config, secrets), want) |
226 | |
227 | # No origin headers, just signed-url-hmac-key. |
228 | config = { |
229 | @@ -385,9 +385,9 @@ site1.local: |
230 | 'signed-url-hmac-key': '${secret}', |
231 | } |
232 | } |
233 | - expected = { |
234 | + want = { |
235 | 'site1.local': { |
236 | 'signed-url-hmac-key': 'Maiqu7ohmeiSh6ooroa0', |
237 | } |
238 | } |
239 | - self.assertEqual(content_cache.interpolate_secrets(config, secrets), expected) |
240 | + self.assertEqual(content_cache.interpolate_secrets(config, secrets), want) |
241 | diff --git a/tests/unit/test_haproxy.py b/tests/unit/test_haproxy.py |
242 | index 66f62fc..8e96702 100644 |
243 | --- a/tests/unit/test_haproxy.py |
244 | +++ b/tests/unit/test_haproxy.py |
245 | @@ -42,13 +42,13 @@ class TestLibHAProxy(unittest.TestCase): |
246 | config = self.site_config |
247 | with open('tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt', 'r', |
248 | encoding='utf-8') as f: |
249 | - expected = f.read() |
250 | - self.assertEqual(''.join(haproxy.render_stanza_listen(config)), expected) |
251 | + want = f.read() |
252 | + self.assertEqual(''.join(haproxy.render_stanza_listen(config)), want) |
253 | |
254 | # Test overriding backend-names |
255 | for site in config.keys(): |
256 | config[site]['backend-name'] = site |
257 | - self.assertEqual(''.join(haproxy.render_stanza_listen(config)), expected) |
258 | + self.assertEqual(''.join(haproxy.render_stanza_listen(config)), want) |
259 | |
260 | @freezegun.freeze_time("2019-03-22") |
261 | def test_haproxy_config_rendered_backend_stanzas(self): |
262 | @@ -56,8 +56,8 @@ class TestLibHAProxy(unittest.TestCase): |
263 | config = self.site_config |
264 | with open('tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output.txt', 'r', |
265 | encoding='utf-8') as f: |
266 | - expected = f.read() |
267 | - self.assertEqual(''.join(haproxy.render_stanza_backend(config)), expected) |
268 | + want = f.read() |
269 | + self.assertEqual(''.join(haproxy.render_stanza_backend(config)), want) |
270 | |
271 | @freezegun.freeze_time("2019-03-22") |
272 | def test_haproxy_config_rendered_full_config(self): |
273 | @@ -68,8 +68,8 @@ class TestLibHAProxy(unittest.TestCase): |
274 | with open(haproxy.conf_file, 'r') as f: |
275 | new_conf = f.read() |
276 | with open('tests/unit/files/haproxy_config_rendered_test_output.txt', 'r') as f: |
277 | - expected = f.read() |
278 | - self.assertEqual(new_conf, expected) |
279 | + want = f.read() |
280 | + self.assertEqual(new_conf, want) |
281 | |
282 | def test_haproxy_config_write(self): |
283 | haproxy = HAProxy.HAProxyConf(self.tmpdir) |
284 | @@ -89,7 +89,7 @@ class TestLibHAProxy(unittest.TestCase): |
285 | 'site4.local': {'port': 443}, |
286 | 'site5.local': {'tls-cert-bundle-path': '/tmp/somepath'}, |
287 | } |
288 | - expected = { |
289 | + want = { |
290 | 80: { |
291 | 'site1.local': {'port': 80}, |
292 | 'site2.local': {'port': 80}, |
293 | @@ -101,4 +101,4 @@ class TestLibHAProxy(unittest.TestCase): |
294 | 'tls-cert-bundle-path': '/tmp/somepath'}, |
295 | }, |
296 | } |
297 | - self.assertEqual(haproxy._merge_listen_stanzas(config), expected) |
298 | + self.assertEqual(haproxy._merge_listen_stanzas(config), want) |
299 | diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py |
300 | index a0f5bc0..55736dd 100644 |
301 | --- a/tests/unit/test_utils.py |
302 | +++ b/tests/unit/test_utils.py |
303 | @@ -57,9 +57,9 @@ class TestLibUtils(unittest.TestCase): |
304 | def test_generate_token(self): |
305 | signing_key = '2KmMh3/rx1LQRdjZIzto07Qaz/+LghG1c2G7od7FC/I=' |
306 | expiry_time = datetime.datetime.now() + datetime.timedelta(hours=1) |
307 | - expected = '1553176800_f8a6667ad994a013645eab53e9a757e65c206ee2' |
308 | - self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), expected) |
309 | + want = '1553176800_f8a6667ad994a013645eab53e9a757e65c206ee2' |
310 | + self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), want) |
311 | |
312 | expiry_time = datetime.datetime.now() + datetime.timedelta(days=1) |
313 | - expected = '1553259600_4cbf405bf08cee57eadcceb2ea98fc6767c6007b' |
314 | - self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), expected) |
315 | + want = '1553259600_4cbf405bf08cee57eadcceb2ea98fc6767c6007b' |
316 | + self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), want) |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.