Projet

Général

Profil

0002-cook-add-tests-using-tenants-for-cook.py-32886.patch

Nicolas Roche, 09 mai 2019 16:40

Télécharger (4,97 ko)

Voir les différences:

Subject: [PATCH 2/2] cook: add tests using tenants for cook.py (#32886)

 tests_schemas/conftest.py         | 31 ++++++++++++++
 tests_schemas/ozwillo_recipe.json | 67 +++++++++++++++++++++++++++++++
 tests_schemas/test_cook.py        | 17 +++++++-
 3 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 tests_schemas/ozwillo_recipe.json
tests_schemas/conftest.py
1
import os
2
import shutil
3
import tempfile
4

  
1 5
import pytest
2 6

  
3 7
from django.core.management import call_command
......
47 51
    monkeypatch.setattr(Command, 'wait_operationals', fake_wait)
48 52

  
49 53
    return services
54

  
55
@pytest.fixture
56
def fake_themes(request, settings):
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 = tempfile.mkdtemp('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)
77

  
78
    def fin():
79
        shutil.rmtree(themes_dir)
80
    request.addfinalizer(fin)
tests_schemas/ozwillo_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
            }
14
        },
15
        {
16
            "set-idp": {}
17
        },
18
        {
19
            "create-combo": {
20
                "template_name": "portal-user",
21
                "title": "Compte citoyen",
22
                "url": "https://${combo}/"
23
            }
24
        },
25
        {
26
            "create-combo": {
27
                "slug": "portal-agent",
28
                "template_name": "portal-agent",
29
                "title": "Portail agent",
30
                "url": "https://${combo_agent}/"
31
            }
32
        },
33
        {
34
            "create-wcs": {
35
                "template_name": "export.zip",
36
                "title": "D\u00e9marches",
37
                "url": "https://${wcs}/"
38
            }
39
        },
40
        {
41
            "create-fargo": {
42
                "title": "Porte documents",
43
                "url": "https://${fargo}/"
44
            }
45
        },
46
        {
47
            "create-passerelle": {
48
                "title": "Passerelle",
49
                "url": "https://${passerelle}/"
50
            }
51
        },
52
        {
53
            "set-theme": {
54
                "theme": "publik"
55
            }
56
        }
57
    ],
58
    "variables": {
59
        "authentic": "connexion-instance-name.sictiam.dev.entrouvert.org",
60
        "combo": "instance-name.sictiam.dev.entrouvert.org",
61
        "combo_agent": "agents-instance-name.sictiam.dev.entrouvert.org",
62
        "fargo": "porte-documents-instance-name.sictiam.dev.entrouvert.org",
63
        "hobo": "hobo-instance-name.sictiam.dev.entrouvert.org",
64
        "passerelle": "passerelle-instance-name.sictiam.dev.entrouvert.org",
65
        "wcs": "demarches-instance-name.sictiam.dev.entrouvert.org"
66
    }
67
}
tests_schemas/test_cook.py
1 1
import pytest
2
import mock
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

  
......
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_ozwillo(db, fake_notify, monkeypatch, fake_themes):
26
    """hobo/cook (before rabbitmq) scenario having.
27
    (cf hobo/contrib/ozwillo/examples)
28
    the resulting JSON may be helpfull to test hobo/deploy (after rabbitmq)
29
    """
30
    monkeypatch.setattr(ServiceBase, 'is_resolvable', lambda x: True)
31
    monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: True)
32
    call_command('cook', 'tests_schemas/ozwillo_recipe.json')
33
    assert len(fake_notify) == 7
34
    environment = get_hobo_json()
35
    assert environment['services'][4]['template_name'] == 'portal-user'
21
-