0001-cook-add-unit-tests-for-cook.py-32886.patch
hobo/environment/management/commands/cook.py | ||
---|---|---|
188 | 188 |
service_type=obj_type, |
189 | 189 |
service_pk=obj.id, |
190 | 190 |
defaults={'label': label or variable_name}) |
191 |
variable.service_type = obj_type |
|
192 |
variable.service_pk = obj.id |
|
193 | 191 |
if label: |
194 | 192 |
variable.label = label |
195 | 193 |
value = variables[variable_name].get('value') |
tests/test_cook.py | ||
---|---|---|
1 |
import pytest
|
|
2 |
import mock
|
|
1 |
import os
|
|
2 |
import json
|
|
3 | 3 |
import StringIO |
4 | 4 | |
5 |
import pytest |
|
6 |
from mock import call, mock_open, patch, Mock |
|
7 | ||
8 |
from django.contrib.auth.models import User |
|
9 |
from django.contrib.contenttypes.models import ContentType |
|
5 | 10 |
from django.core.management.base import CommandError |
6 | 11 | |
7 |
from hobo.environment.models import ServiceBase |
|
12 |
from hobo.environment.models import (Authentic, BiJoe, Chrono, Combo, Corbo, Fargo, |
|
13 |
Hobo, Passerelle, ServiceBase, Variable, Wcs, Welco) |
|
8 | 14 |
from hobo.environment.management.commands.cook import Command |
15 |
from hobo.profile.models import AttributeDefinition |
|
9 | 16 | |
10 | 17 | |
11 | 18 |
def test_check_action(monkeypatch): |
... | ... | |
55 | 62 |
command.check_action(action, action_args) |
56 | 63 |
assert 'has no valid certificate' in str(e_info.value) |
57 | 64 | |
58 |
@mock.patch('hobo.environment.management.commands.cook.open') |
|
59 |
def test_having_several_action_args(mocked_open): |
|
60 |
"""load variables from a file""" |
|
61 |
receipe = """{ |
|
62 |
"steps": [ |
|
63 |
{"create-authentic": { |
|
64 |
"url": "https://entrouvert.org/", |
|
65 |
"title": "Connexion" |
|
66 |
}} |
|
67 |
] |
|
68 |
}""" |
|
69 |
expected_a2 = "[call(title=u'Connexion', url=u'https://entrouvert.org/')]" |
|
65 |
def test_handle(): |
|
66 |
kwargs = {'verbosity': 'verbosity value', |
|
67 |
'timeout': 'timeout value', |
|
68 |
'permissive': 'permissive value'} |
|
69 |
command = Command() |
|
70 |
command.run_cook = Mock() |
|
71 | ||
72 |
command.handle('recipe.json', **kwargs) |
|
73 |
assert command.verbosity == 'verbosity value' |
|
74 |
assert command.timeout == 'timeout value' |
|
75 |
assert command.permissive == 'permissive value' |
|
76 |
assert command.run_cook.mock_calls == [call('recipe.json')] |
|
77 | ||
78 |
@patch('hobo.environment.management.commands.cook.notify_agents') |
|
79 |
def test_run_cook(mocked_notify_agents, tmpdir): |
|
80 |
command = Command() |
|
81 |
command.permissive = False |
|
82 |
command.must_notify = True |
|
83 |
command.timeout = 42 |
|
84 |
command.check_action = Mock() |
|
85 |
command.create_hobo = Mock() |
|
86 |
mocked_notify_agents = Mock() |
|
87 |
command.wait_operationals = Mock() |
|
88 | ||
89 |
recipe = {'steps': [{'create-hobo': {'url': 'https://entrouvert.org/'}}]} |
|
90 |
recipe_path = os.path.join(str(tmpdir), 'recipe.json') |
|
91 |
with open(recipe_path, 'w') as handler: |
|
92 |
handler.write(json.dumps(recipe)) |
|
93 | ||
94 |
command.run_cook(recipe_path) |
|
95 |
assert command.check_action.mock_calls == [ |
|
96 |
call(u'create-hobo', {u'url': u'https://entrouvert.org/'})] |
|
97 |
assert command.create_hobo.mock_calls == [call(url=u'https://entrouvert.org/')] |
|
98 |
assert mocked_notify_agents.mock_calls == [] |
|
99 |
assert command.wait_operationals.mock_calls == [call(timeout=42)] |
|
70 | 100 | |
101 |
def test_having_several_action_args(tmpdir): |
|
71 | 102 |
command = Command() |
72 | 103 |
command.permissive = True |
73 |
command.create_authentic = mock.MagicMock() |
|
104 |
command.create_authentic = Mock() |
|
105 | ||
106 |
recipe = {'steps': [{'create-authentic': { |
|
107 |
'url': 'https://entrouvert.org/', |
|
108 |
'title': 'Connexion' |
|
109 |
}}]} |
|
110 |
recipe_path = os.path.join(str(tmpdir), 'recipe.json') |
|
111 |
with open(recipe_path, 'w') as handler: |
|
112 |
handler.write(json.dumps(recipe)) |
|
113 | ||
114 |
command.run_cook(recipe_path) |
|
115 |
assert command.create_authentic.mock_calls == [ |
|
116 |
call(title=u'Connexion', url=u'https://entrouvert.org/')] |
|
117 | ||
118 |
def test_load_variables_from(db, tmpdir): |
|
119 |
"""load variables from a file""" |
|
120 |
command = Command() |
|
121 |
command.permissive = True |
|
122 |
command.create_hobo = Mock() |
|
123 |
command.create_authentic = Mock() |
|
124 |
command.create_combo = Mock() |
|
125 | ||
126 |
variables = {'foo': 'foo1', 'bar': 'bar1'} |
|
127 |
variables_path = os.path.join(str(tmpdir), 'variable.json') |
|
128 |
with open(variables_path, 'w') as handler: |
|
129 |
handler.write(json.dumps(variables)) |
|
130 | ||
131 |
recipe = { |
|
132 |
'load-variables-from': variables_path, |
|
133 |
'variables': { |
|
134 |
'domain': 'entrouvert.org', |
|
135 |
'bar': 'bar2' |
|
136 |
}, |
|
137 |
'steps':[ |
|
138 |
{'create-hobo': {'url': 'https://${domain}/'}}, |
|
139 |
{'create-authentic': {'url': 'https://${foo}/'}}, |
|
140 |
{'create-combo': {'url': 'https://${bar}/', 'not_a_string': []}} |
|
141 |
]} |
|
142 |
recipe_path = os.path.join(str(tmpdir), 'recipe.json') |
|
143 |
with open(recipe_path, 'w') as handler: |
|
144 |
handler.write(json.dumps(recipe)) |
|
145 | ||
146 |
command.run_cook(recipe_path) |
|
147 |
assert command.create_hobo.mock_calls == [call(url=u'https://entrouvert.org/')] |
|
148 |
assert command.create_authentic.mock_calls == [call(url=u'https://foo1/')] |
|
149 |
assert command.create_combo.mock_calls == [ |
|
150 |
call(not_a_string=[], url=u'https://bar2/')] |
|
151 | ||
152 |
def test_wait_operationals(db, monkeypatch): |
|
153 |
service1 = Mock() |
|
154 |
service2 = Mock() |
|
155 |
obj1 = Mock() |
|
156 |
obj2 = Mock() |
|
157 | ||
158 |
def do_nothing(*args, **kwargs): |
|
159 |
pass |
|
160 | ||
161 |
obj1.check_operational = do_nothing |
|
162 |
obj2.check_operational = do_nothing |
|
163 |
obj1.base_url = 'url1' |
|
164 |
obj2.base_url = 'url2' |
|
165 | ||
166 |
service1.objects.all = Mock(return_value=[obj1]) |
|
167 |
service2.objects.all = Mock(return_value=[obj2]) |
|
168 |
monkeypatch.setattr( |
|
169 |
'hobo.environment.management.commands.cook.AVAILABLE_SERVICES', |
|
170 |
[service1, service2]) |
|
171 |
command = Command() |
|
172 | ||
173 |
# already operational |
|
174 |
obj1.last_operational_success_timestamp = 'some date' |
|
175 |
obj2.last_operational_success_timestamp = 'some date' |
|
176 |
command.wait_operationals(2) |
|
177 |
assert True |
|
178 | ||
179 |
# not operational |
|
180 |
obj2.last_operational_success_timestamp = None |
|
181 |
with pytest.raises(CommandError) as e_info: |
|
182 |
command.wait_operationals(.6) |
|
183 |
assert str(e_info).find('CommandError: timeout waiting for url2') != -1 |
|
184 | ||
185 |
def test_set_variable(db): |
|
186 |
command = Command() |
|
187 | ||
188 |
command.set_variable('foo', 'bar') |
|
189 |
var = Variable.objects.get(name='foo') |
|
190 |
assert var.value == 'bar' |
|
191 |
assert var.label == 'foo' |
|
192 | ||
193 |
command.set_variable('foo', 'bar', label='FOO') |
|
194 |
var = Variable.objects.get(name='foo') |
|
195 |
assert var.value == 'bar' |
|
196 |
assert var.label == 'FOO' |
|
197 | ||
198 |
command.set_variable('foo', ['bar', 'baz']) |
|
199 |
var = Variable.objects.get(name='foo') |
|
200 |
assert var.value == '["bar", "baz"]' |
|
201 | ||
202 |
command.set_variable('foo', {'key1': 'bar', 'key2': 'baz'}) |
|
203 |
var = Variable.objects.get(name='foo') |
|
204 |
ordered_dump = json.dumps(json.loads(var.value), sort_keys=True) |
|
205 |
assert ordered_dump == '{"key1": "bar", "key2": "baz"}' |
|
206 | ||
207 |
def test_set_attribute(db): |
|
208 |
command = Command() |
|
209 |
command.set_attribute('foo_name', 'foo_label') |
|
210 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
211 |
assert values.count() == 1 |
|
212 |
assert values[0].label == 'foo_label' |
|
213 |
assert values[0].disabled is False |
|
214 | ||
215 |
command.set_attribute('foo_name', 'foo_label', disabled=True) |
|
216 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
217 |
assert values.count() == 1 |
|
218 |
assert values[0].label == 'foo_label' |
|
219 |
assert values[0].disabled is True |
|
220 | ||
221 |
def test_disable_attribute(db): |
|
222 |
command = Command() |
|
223 |
command.set_attribute('foo_name', 'foo_label') |
|
224 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
225 |
assert values.count() == 1 |
|
226 |
assert values[0].label == 'foo_label' |
|
227 |
assert values[0].disabled is False |
|
228 | ||
229 |
command.disable_attribute('foo_name') |
|
230 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
231 |
assert values[0].disabled is True |
|
232 | ||
233 |
command.disable_attribute('not_defined') |
|
234 |
values = AttributeDefinition.objects.filter(name='not_defined') |
|
235 |
assert values.count() == 0 |
|
236 | ||
237 |
def test_enable_attribute(db): |
|
238 |
command = Command() |
|
239 |
command.set_attribute('foo_name', 'foo_label', disabled=True) |
|
240 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
241 |
assert values.count() == 1 |
|
242 |
assert values[0].label == 'foo_label' |
|
243 |
assert values[0].disabled is True |
|
244 | ||
245 |
command.enable_attribute('foo_name') |
|
246 |
values = AttributeDefinition.objects.filter(name='foo_name') |
|
247 |
assert values[0].disabled is False |
|
248 | ||
249 |
command.enable_attribute('not_defined') |
|
250 |
values = AttributeDefinition.objects.filter(name='not_defined') |
|
251 |
assert values.count() == 0 |
|
252 | ||
253 |
def test_create_superuser(db): |
|
254 |
command = Command() |
|
255 |
command.create_superuser() |
|
256 |
assert User.objects.count() == 1 |
|
257 |
user = User.objects.all()[0] |
|
258 |
assert user.username == 'admin' |
|
259 |
assert user.is_superuser is True |
|
260 | ||
261 |
def test_create_site(db): |
|
262 |
command = Command() |
|
263 |
base_url = 'http://entrouvert.org' |
|
264 |
title = 'site title' |
|
265 |
slug = None |
|
266 |
template_name = '' |
|
267 |
variables = {'foo': {'label': 'FOO', 'value': {'key': 'bar'}}} |
|
268 |
command.create_site(Combo, base_url, title, slug, template_name, |
|
269 |
variables) |
|
270 | ||
271 |
# Combo object |
|
272 |
assert Combo.objects.count() == 1 |
|
273 |
combo = Combo.objects.all()[0] |
|
274 |
assert combo.title == title |
|
275 |
assert combo.base_url == base_url + '/' |
|
276 |
assert combo.template_name == '' |
|
277 | ||
278 |
# ContentType object |
|
279 |
obj_type = ContentType.objects.get_for_model(Combo) |
|
280 | ||
281 |
# Variables |
|
282 |
var = Variable.objects.get(name='foo') |
|
283 |
assert var.label == 'FOO' |
|
284 |
assert var.value == '{"key": "bar"}' |
|
285 |
assert var.service_type == obj_type |
|
286 |
assert var.service_pk == combo.id |
|
287 | ||
288 |
with pytest.raises(CommandError) as e_info: |
|
289 |
command.create_site(Combo, 'unvalid_url', 'site title', 'a slug', '', '') |
|
290 |
assert 'Enter a valid URL.' in str(e_info.value) |
|
291 | ||
292 |
@patch('hobo.environment.management.commands.cook.connection') |
|
293 |
@patch('hobo.environment.management.commands.cook.call_command') |
|
294 |
@patch('hobo.environment.management.commands.cook.TenantMiddleware') |
|
295 |
def test_create_hobo_primary(mocked_TenantMiddleware, mocked_call_command, |
|
296 |
mocked_connection): |
|
297 |
command = Command() |
|
298 |
command.create_site = Mock() |
|
299 |
tenant = Mock() |
|
300 |
tenant.schema_name = 'public' |
|
301 |
tenant.get_directory = Mock(return_value='/foo') |
|
302 |
mocked_connection.get_tenant = Mock(return_value=tenant) |
|
303 |
mocked_connection.set_tenant = Mock() |
|
304 |
mocked_TenantMiddleware.get_tenant_by_hostname = Mock(return_value=tenant) |
|
305 |
mocked_call_command.side_effect = CommandError |
|
306 | ||
307 |
mocked_open = mock_open() |
|
308 |
with patch('hobo.environment.management.commands.cook.open', mocked_open, |
|
309 |
create=True): |
|
310 |
command.create_hobo('http://entrouvert.org/and_much') |
|
311 |
assert command.create_site.mock_calls == [] |
|
312 |
assert mocked_call_command.mock_calls == [ |
|
313 |
call('create_hobo_tenant', 'entrouvert.org')] |
|
314 |
assert len(mocked_connection.set_tenant.mock_calls) == 1 |
|
315 |
assert mocked_open.mock_calls == [ |
|
316 |
call('/foo/base_url', 'w'), |
|
317 |
call().write('http://entrouvert.org/and_much'), |
|
318 |
call().close()] |
|
319 | ||
320 |
@patch('hobo.environment.management.commands.cook.connection') |
|
321 |
@patch('hobo.environment.management.commands.cook.call_command') |
|
322 |
@patch('hobo.environment.management.commands.cook.TenantMiddleware') |
|
323 |
def test_create_hobo_not_primary(mocked_TenantMiddleware, mocked_call_command, |
|
324 |
mocked_connection): |
|
325 |
command = Command() |
|
326 |
command.create_site = Mock() |
|
327 |
tenant = Mock() |
|
328 |
tenant.schema_name = 'other than public' |
|
329 |
tenant.get_directory = Mock(return_value='/foo') |
|
330 |
mocked_connection.get_tenant = Mock(return_value=tenant) |
|
331 |
mocked_connection.set_tenant = Mock() |
|
332 |
mocked_TenantMiddleware.get_tenant_by_hostname = Mock(return_value=tenant) |
|
333 | ||
334 |
mocked_open = mock_open() |
|
335 |
with patch('hobo.environment.management.commands.cook.open', mocked_open, |
|
336 |
create=True): |
|
337 |
command.create_hobo('http://entrouvert.org/and_much') |
|
338 |
assert command.create_site.mock_calls == [ |
|
339 |
call(Hobo, 'http://entrouvert.org/and_much', None, u'hobo-none', |
|
340 |
template_name='', variables=None)] |
|
341 |
assert mocked_call_command.mock_calls == [] |
|
342 |
assert len(mocked_connection.set_tenant.mock_calls) == 1 |
|
343 |
assert mocked_open.mock_calls == [] |
|
344 | ||
345 |
def test_create_services(): |
|
346 |
command = Command() |
|
347 |
command.create_site = Mock() |
|
348 |
command.create_authentic('url', 'title') |
|
349 |
command.create_combo('url', 'title') |
|
350 |
command.create_wcs('url', 'title') |
|
351 |
command.create_passerelle('url', 'title') |
|
352 |
command.create_fargo('url', 'title') |
|
353 |
command.create_welco('url', 'title') |
|
354 |
command.create_chrono('url', 'title') |
|
355 |
command.create_corbo('url', 'title') |
|
356 |
command.create_bijoe('url', 'title') |
|
357 | ||
358 |
assert len(command.create_site.mock_calls) == 9 |
|
359 |
assert command.create_site.mock_calls == [ |
|
360 |
call(Authentic, 'url', 'title', None, '', None), |
|
361 |
call(Combo, 'url', 'title', None, '', None), |
|
362 |
call(Wcs, 'url', 'title', None, '', None), |
|
363 |
call(Passerelle, 'url', 'title', None, '', None), |
|
364 |
call(Fargo, 'url', 'title', None, '', None), |
|
365 |
call(Welco, 'url', 'title', None, '', None), |
|
366 |
call(Chrono, 'url', 'title', None, '', None), |
|
367 |
call(Corbo, 'url', 'title', None, '', None), |
|
368 |
call(BiJoe, 'url', 'title', None, '', None)] |
|
369 | ||
370 |
def test_set_idp(db): |
|
371 |
command = Command() |
|
372 | ||
373 |
# exceptions maybe we should handle into cook.py ? |
|
374 |
with pytest.raises(Authentic.DoesNotExist, |
|
375 |
match='Authentic matching query does not exist'): |
|
376 |
command.set_idp('url') |
|
377 |
with pytest.raises(IndexError, match='list index out of range'): |
|
378 |
command.set_idp() |
|
379 | ||
380 |
# objects sorted on title: [obj1, obj2] |
|
381 |
obj1, ignored = Authentic.objects.get_or_create( |
|
382 |
slug='slug1', defaults={'title': 'bar'}) |
|
383 |
obj2, ignored = Authentic.objects.get_or_create( |
|
384 |
slug='slug2', defaults={'title': 'foo', 'base_url': 'http://example.org'}) |
|
385 |
assert obj1.use_as_idp_for_self is False |
|
386 |
assert obj2.use_as_idp_for_self is False |
|
387 | ||
388 |
# set first |
|
389 |
command.set_idp('') |
|
390 |
obj = Authentic.objects.get(title='bar') |
|
391 |
assert obj.use_as_idp_for_self is True |
|
392 | ||
393 |
# set using url |
|
394 |
command.set_idp('http://example.org/') |
|
395 |
obj = Authentic.objects.get(title='foo') |
|
396 |
assert obj.use_as_idp_for_self is True |
|
397 | ||
398 |
@patch('hobo.environment.management.commands.cook.set_theme') |
|
399 |
@patch('hobo.environment.management.commands.cook.connection') |
|
400 |
@patch('hobo.agent.common.management.commands.hobo_deploy.Command.configure_theme') |
|
401 |
def test_set_theme(mocked_configure_theme, mocked_connection, mocked_set_theme): |
|
402 |
mocked_connection.get_tenant = Mock(return_value='the tenant') |
|
403 |
command = Command() |
|
404 |
command.set_theme('the theme') |
|
405 | ||
406 |
assert mocked_set_theme.mock_calls == [call('the theme')] |
|
407 |
assert len(mocked_connection.get_tenant.mock_calls) == 1 |
|
408 |
assert mocked_configure_theme.mock_calls == [ |
|
409 |
call({'variables': {'theme': 'the theme'}}, 'the tenant')] |
|
410 | ||
411 |
@patch('hobo.environment.management.commands.cook.connection') |
|
412 |
def test_cook(mocked_connection): |
|
413 |
mocked_connection.get_tenant = Mock(return_value='the tenant') |
|
414 |
mocked_connection.set_tenant = Mock() |
|
415 |
command = Command() |
|
416 |
command.run_cook = Mock() |
|
417 |
command.cook('a-recipe-file.json') |
|
74 | 418 | |
75 |
mocked_open.side_effect = [StringIO.StringIO(receipe)] |
|
76 |
command.run_cook('recipe_me.json') |
|
77 |
assert str(command.create_authentic.mock_calls) == expected_a2 |
|
419 |
assert len(mocked_connection.get_tenant.mock_calls) == 1 |
|
420 |
assert command.run_cook.mock_calls == [call('a-recipe-file.json')] |
|
421 |
assert mocked_connection.set_tenant.mock_calls == [call('the tenant')] |
tests_schemas/conftest.py | ||
---|---|---|
1 |
import os |
|
2 |
import shutil |
|
3 | ||
1 | 4 |
import pytest |
2 | 5 | |
3 | 6 |
from django.core.management import call_command |
... | ... | |
47 | 50 |
monkeypatch.setattr(Command, 'wait_operationals', fake_wait) |
48 | 51 | |
49 | 52 |
return services |
53 | ||
54 | ||
55 |
@pytest.fixture |
|
56 |
def fake_themes(settings, tmpdir): |
|
57 |
THEMES=""" |
|
58 |
[ |
|
59 |
{ |
|
60 |
"id": "publik", |
|
61 |
"label": "Publik", |
|
62 |
"variables": { |
|
63 |
"css_variant": "publik", |
|
64 |
"no_extra_js": false, |
|
65 |
"theme_color": "#E80E89" |
|
66 |
} |
|
67 |
} |
|
68 |
] |
|
69 |
""" |
|
70 |
base_dir = str(tmpdir.mkdir('themes')) |
|
71 |
settings.THEMES_DIRECTORY = base_dir |
|
72 | ||
73 |
themes_dir = os.path.join(base_dir, 'publik-base') |
|
74 |
os.mkdir(themes_dir) |
|
75 |
with open(os.path.join(themes_dir, 'themes.json'), 'w') as handler: |
|
76 |
handler.write(THEMES) |
tests_schemas/example_env.json | ||
---|---|---|
1 |
{ |
|
2 |
"profile": { |
|
3 |
"fields": [ |
|
4 |
{ |
|
5 |
"asked_on_registration": false, |
|
6 |
"description": "", |
|
7 |
"disabled": false, |
|
8 |
"kind": "title", |
|
9 |
"label": "Civilit\u00e9", |
|
10 |
"name": "title", |
|
11 |
"required": false, |
|
12 |
"searchable": false, |
|
13 |
"user_editable": true, |
|
14 |
"user_visible": true |
|
15 |
}, |
|
16 |
{ |
|
17 |
"asked_on_registration": true, |
|
18 |
"description": "", |
|
19 |
"disabled": false, |
|
20 |
"kind": "string", |
|
21 |
"label": "Pr\u00e9nom", |
|
22 |
"name": "first_name", |
|
23 |
"required": true, |
|
24 |
"searchable": false, |
|
25 |
"user_editable": true, |
|
26 |
"user_visible": true |
|
27 |
}, |
|
28 |
{ |
|
29 |
"asked_on_registration": true, |
|
30 |
"description": "", |
|
31 |
"disabled": false, |
|
32 |
"kind": "string", |
|
33 |
"label": "Nom", |
|
34 |
"name": "last_name", |
|
35 |
"required": true, |
|
36 |
"searchable": false, |
|
37 |
"user_editable": true, |
|
38 |
"user_visible": true |
|
39 |
}, |
|
40 |
{ |
|
41 |
"asked_on_registration": false, |
|
42 |
"description": "", |
|
43 |
"disabled": false, |
|
44 |
"kind": "email", |
|
45 |
"label": "Adresse \u00e9lectronique", |
|
46 |
"name": "email", |
|
47 |
"required": true, |
|
48 |
"searchable": false, |
|
49 |
"user_editable": true, |
|
50 |
"user_visible": true |
|
51 |
}, |
|
52 |
{ |
|
53 |
"asked_on_registration": false, |
|
54 |
"description": "", |
|
55 |
"disabled": false, |
|
56 |
"kind": "string", |
|
57 |
"label": "Adresse", |
|
58 |
"name": "address", |
|
59 |
"required": false, |
|
60 |
"searchable": false, |
|
61 |
"user_editable": true, |
|
62 |
"user_visible": true |
|
63 |
}, |
|
64 |
{ |
|
65 |
"asked_on_registration": false, |
|
66 |
"description": "", |
|
67 |
"disabled": false, |
|
68 |
"kind": "string", |
|
69 |
"label": "Code postal", |
|
70 |
"name": "zipcode", |
|
71 |
"required": false, |
|
72 |
"searchable": false, |
|
73 |
"user_editable": true, |
|
74 |
"user_visible": true |
|
75 |
}, |
|
76 |
{ |
|
77 |
"asked_on_registration": false, |
|
78 |
"description": "", |
|
79 |
"disabled": false, |
|
80 |
"kind": "string", |
|
81 |
"label": "Commune", |
|
82 |
"name": "city", |
|
83 |
"required": false, |
|
84 |
"searchable": false, |
|
85 |
"user_editable": true, |
|
86 |
"user_visible": true |
|
87 |
}, |
|
88 |
{ |
|
89 |
"asked_on_registration": false, |
|
90 |
"description": "", |
|
91 |
"disabled": true, |
|
92 |
"kind": "string", |
|
93 |
"label": "Pays", |
|
94 |
"name": "country", |
|
95 |
"required": false, |
|
96 |
"searchable": false, |
|
97 |
"user_editable": true, |
|
98 |
"user_visible": true |
|
99 |
}, |
|
100 |
{ |
|
101 |
"asked_on_registration": false, |
|
102 |
"description": "", |
|
103 |
"disabled": true, |
|
104 |
"kind": "birthdate", |
|
105 |
"label": "Date de naissance", |
|
106 |
"name": "birthdate", |
|
107 |
"required": false, |
|
108 |
"searchable": false, |
|
109 |
"user_editable": true, |
|
110 |
"user_visible": true |
|
111 |
}, |
|
112 |
{ |
|
113 |
"asked_on_registration": false, |
|
114 |
"description": "", |
|
115 |
"disabled": false, |
|
116 |
"kind": "string", |
|
117 |
"label": "T\u00e9l\u00e9phone", |
|
118 |
"name": "phone", |
|
119 |
"required": false, |
|
120 |
"searchable": false, |
|
121 |
"user_editable": true, |
|
122 |
"user_visible": true |
|
123 |
}, |
|
124 |
{ |
|
125 |
"asked_on_registration": false, |
|
126 |
"description": "", |
|
127 |
"disabled": false, |
|
128 |
"kind": "string", |
|
129 |
"label": "Mobile", |
|
130 |
"name": "mobile", |
|
131 |
"required": false, |
|
132 |
"searchable": false, |
|
133 |
"user_editable": true, |
|
134 |
"user_visible": true |
|
135 |
} |
|
136 |
] |
|
137 |
}, |
|
138 |
"services": [ |
|
139 |
{ |
|
140 |
"backoffice-menu-url": "https://hobo-instance-name.dev.signalpublik.com/menu.json", |
|
141 |
"base_url": "https://hobo-instance-name.dev.signalpublik.com/", |
|
142 |
"saml-sp-metadata-url": "https://hobo-instance-name.dev.signalpublik.com/accounts/mellon/metadata/", |
|
143 |
"service-id": "hobo", |
|
144 |
"slug": "hobo", |
|
145 |
"title": "Hobo" |
|
146 |
}, |
|
147 |
{ |
|
148 |
"backoffice-menu-url": "https://connexion-instance-name.dev.signalpublik.com/manage/menu.json", |
|
149 |
"base_url": "https://connexion-instance-name.dev.signalpublik.com/", |
|
150 |
"id": 1, |
|
151 |
"saml-idp-metadata-url": "https://connexion-instance-name.dev.signalpublik.com/idp/saml2/metadata", |
|
152 |
"secondary": false, |
|
153 |
"secret_key": "k_a)vo)a&8xugbzjl#%^s8vfkm2+#yhz#if4m+xu!qqv=04x9q", |
|
154 |
"service-id": "authentic", |
|
155 |
"service-label": "Authentic", |
|
156 |
"slug": "idp", |
|
157 |
"template_name": "signal-publik", |
|
158 |
"title": "Connexion", |
|
159 |
"variables": {} |
|
160 |
}, |
|
161 |
{ |
|
162 |
"backoffice-menu-url": "https://demarches-instance-name.dev.signalpublik.com/backoffice/menu.json", |
|
163 |
"base_url": "https://demarches-instance-name.dev.signalpublik.com/", |
|
164 |
"id": 1, |
|
165 |
"saml-sp-metadata-url": "https://demarches-instance-name.dev.signalpublik.com/saml/metadata", |
|
166 |
"secondary": false, |
|
167 |
"secret_key": "uhipz^y38a*w#rrnio_-i=+7p47aq#$+dntm*i@nz(y)n57153", |
|
168 |
"service-id": "wcs", |
|
169 |
"service-label": "w.c.s.", |
|
170 |
"slug": "eservices", |
|
171 |
"template_name": "", |
|
172 |
"title": "D\u00e9marches", |
|
173 |
"variables": {} |
|
174 |
}, |
|
175 |
{ |
|
176 |
"backoffice-menu-url": "https://passerelle-instance-name.dev.signalpublik.com/manage/menu.json", |
|
177 |
"base_url": "https://passerelle-instance-name.dev.signalpublik.com/", |
|
178 |
"id": 1, |
|
179 |
"saml-sp-metadata-url": "https://passerelle-instance-name.dev.signalpublik.com/accounts/mellon/metadata/", |
|
180 |
"secondary": false, |
|
181 |
"secret_key": "vz&g(p1bhzw35iltrrl$^6013*+q80l&l4)b)tsr=+ko__js_v", |
|
182 |
"service-id": "passerelle", |
|
183 |
"service-label": "Passerelle", |
|
184 |
"slug": "passerelle", |
|
185 |
"template_name": "signal-publik", |
|
186 |
"title": "Passerelle", |
|
187 |
"variables": {} |
|
188 |
}, |
|
189 |
{ |
|
190 |
"backoffice-menu-url": "https://instance-name.dev.signalpublik.com/manage/menu.json", |
|
191 |
"base_url": "https://instance-name.dev.signalpublik.com/", |
|
192 |
"id": 1, |
|
193 |
"saml-sp-metadata-url": "https://instance-name.dev.signalpublik.com/accounts/mellon/metadata/", |
|
194 |
"secondary": false, |
|
195 |
"secret_key": "^0!psa-ijq4*va0a4&_)solvils#hig2vtof(%3iy#!6p5!f6e", |
|
196 |
"service-id": "combo", |
|
197 |
"service-label": "Combo", |
|
198 |
"slug": "portal", |
|
199 |
"template_name": "signal-publik-portal-user", |
|
200 |
"title": "Compte citoyen", |
|
201 |
"variables": {} |
|
202 |
}, |
|
203 |
{ |
|
204 |
"backoffice-menu-url": "https://agents-instance-name.dev.signalpublik.com/manage/menu.json", |
|
205 |
"base_url": "https://agents-instance-name.dev.signalpublik.com/", |
|
206 |
"id": 2, |
|
207 |
"saml-sp-metadata-url": "https://agents-instance-name.dev.signalpublik.com/accounts/mellon/metadata/", |
|
208 |
"secondary": false, |
|
209 |
"secret_key": "m1&vql=pm-clw)0wcnk=q4g1-#flrus!dui$gr$7ug2%xw@ko$", |
|
210 |
"service-id": "combo", |
|
211 |
"service-label": "Combo", |
|
212 |
"slug": "portal-agent", |
|
213 |
"template_name": "signal-publik-portal-agent", |
|
214 |
"title": "Portail agent", |
|
215 |
"variables": {} |
|
216 |
} |
|
217 |
], |
|
218 |
"timestamp": "1558975192.98", |
|
219 |
"users": [], |
|
220 |
"variables": { |
|
221 |
"css_variant": "publik", |
|
222 |
"no_extra_js": false, |
|
223 |
"theme": "publik", |
|
224 |
"theme_color": "#E80E89" |
|
225 |
} |
|
226 |
} |
tests_schemas/example_recipe.json | ||
---|---|---|
1 |
{ |
|
2 |
"steps": [ |
|
3 |
{ |
|
4 |
"create-hobo": { |
|
5 |
"url": "https://${hobo}/", |
|
6 |
"primary": true |
|
7 |
} |
|
8 |
}, |
|
9 |
{ |
|
10 |
"create-authentic": { |
|
11 |
"title": "Connexion", |
|
12 |
"url": "https://${authentic}/", |
|
13 |
"template_name": "signal-publik" |
|
14 |
} |
|
15 |
}, |
|
16 |
{ |
|
17 |
"set-idp": {} |
|
18 |
}, |
|
19 |
{ |
|
20 |
"create-combo": { |
|
21 |
"template_name": "signal-publik-portal-user", |
|
22 |
"title": "Compte citoyen", |
|
23 |
"url": "https://${combo}/" |
|
24 |
} |
|
25 |
}, |
|
26 |
{ |
|
27 |
"create-combo": { |
|
28 |
"slug": "portal-agent", |
|
29 |
"template_name": "signal-publik-portal-agent", |
|
30 |
"title": "Portail agent", |
|
31 |
"url": "https://${combo_agent}/" |
|
32 |
} |
|
33 |
}, |
|
34 |
{ |
|
35 |
"create-wcs": { |
|
36 |
"title": "D\u00e9marches", |
|
37 |
"url": "https://${wcs}/" |
|
38 |
} |
|
39 |
}, |
|
40 |
{ |
|
41 |
"create-passerelle": { |
|
42 |
"title": "Passerelle", |
|
43 |
"template_name": "signal-publik", |
|
44 |
"url": "https://${passerelle}/" |
|
45 |
} |
|
46 |
}, |
|
47 |
{ |
|
48 |
"set-theme": { |
|
49 |
"theme": "publik" |
|
50 |
} |
|
51 |
} |
|
52 |
], |
|
53 |
"variables": { |
|
54 |
"authentic": "connexion-instance-name.dev.signalpublik.com", |
|
55 |
"combo": "instance-name.dev.signalpublik.com", |
|
56 |
"combo_agent": "agents-instance-name.dev.signalpublik.com", |
|
57 |
"fargo": "porte-documents-instance-name.dev.signalpublik.com", |
|
58 |
"hobo": "hobo-instance-name.dev.signalpublik.com", |
|
59 |
"passerelle": "passerelle-instance-name.dev.signalpublik.com", |
|
60 |
"wcs": "demarches-instance-name.dev.signalpublik.com" |
|
61 |
} |
|
62 |
} |
tests_schemas/test_cook.py | ||
---|---|---|
1 |
import json |
|
1 | 2 |
import pytest |
2 | 3 | |
3 |
from django.core.management import call_command |
|
4 |
from django.core.management import call_command, load_command_class
|
|
4 | 5 |
from django.core.management.base import CommandError |
5 | 6 | |
7 |
from hobo.deploy.utils import get_hobo_json |
|
6 | 8 |
from hobo.environment.models import ServiceBase |
7 | 9 | |
8 | 10 | |
... | ... | |
10 | 12 |
monkeypatch.setattr(ServiceBase, 'is_resolvable', lambda x: True) |
11 | 13 |
monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: True) |
12 | 14 |
call_command('cook', 'tests_schemas/recipe.json') |
13 |
assert(len(fake_notify) == 3)
|
|
15 |
assert len(fake_notify) == 3
|
|
14 | 16 | |
15 | 17 | |
16 | 18 |
def test_cook_unresolvable(db, fake_notify, monkeypatch): |
... | ... | |
18 | 20 |
with pytest.raises(CommandError) as e_info: |
19 | 21 |
call_command('cook', 'tests_schemas/recipe.json') |
20 | 22 |
assert 'is not resolvable' in str(e_info.value) |
23 | ||
24 | ||
25 |
def test_cook_example(db, fake_notify, monkeypatch, fake_themes): |
|
26 |
"""hobo/cook (before rabbitmq) scenario having templates. |
|
27 |
the resulting JSON may be helpfull to manually invoque hobo-deploy (after rabbitmq) |
|
28 |
""" |
|
29 |
monkeypatch.setattr(ServiceBase, 'is_resolvable', lambda x: True) |
|
30 |
monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: True) |
|
31 |
call_command('cook', 'tests_schemas/example_recipe.json') |
|
32 | ||
33 |
# notify_agents was call |
|
34 |
assert len(fake_notify) == 6 |
|
35 | ||
36 |
# here is the JSON environment spread by notify_agents |
|
37 |
environment = get_hobo_json() |
|
38 | ||
39 |
# below JSON file was created by this instruction |
|
40 |
#json.dump(environment, open('tests_schemas/example_env.json', 'w'), |
|
41 |
# sort_keys=True, indent=4, separators=(',', ': ')) |
|
42 | ||
43 |
expected = json.load(open('tests_schemas/example_env.json', 'r')) |
|
44 |
assert json.dumps(environment, sort_keys=True), json.dumps(expected, sort_keys=True) |
|
21 |
- |