Projet

Général

Profil

0003-misc-split-some-tests-58796.patch

Lauréline Guérin, 03 mars 2022 11:13

Télécharger (4,29 ko)

Voir les différences:

Subject: [PATCH 3/4] misc: split some tests (#58796)

 tests/admin_pages/test_all.py    | 36 ------------------
 tests/admin_pages/test_studio.py | 64 ++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 36 deletions(-)
 create mode 100644 tests/admin_pages/test_studio.py
tests/admin_pages/test_all.py
162 162
    resp = app.get('/backoffice/menu.json')
163 163
    assert 'Users' not in [x['label'] for x in resp.json]
164 164
    assert 'Roles' not in [x['label'] for x in resp.json]
165

  
166

  
167
def test_studio_home(pub):
168
    create_superuser(pub)
169
    app = login(get_app(pub))
170
    resp = app.get('/backoffice/')
171
    assert 'studio' in resp.text
172
    resp = app.get('/backoffice/studio/')
173
    assert '../forms/' in resp.text
174
    assert '../cards/' in resp.text
175
    assert '../workflows/' in resp.text
176
    assert 'Logged Errors' in resp.text
177

  
178
    pub.cfg['admin-permissions'] = {}
179
    for part in ('forms', 'cards', 'workflows'):
180
        # check section link are not displayed if user has no access right
181
        pub.cfg['admin-permissions'].update({part: ['x']})  # block access
182
        pub.write_cfg()
183
        if part != 'workflows':
184
            resp = app.get('/backoffice/studio/')
185
            assert '../%s/' % part not in resp.text
186
        else:
187
            resp = app.get('/backoffice/studio/', status=403)  # totally closed
188

  
189
    resp = app.get('/backoffice/')
190
    assert 'studio' not in resp.text
191

  
192

  
193
def test_studio_workflows(pub):
194
    create_superuser(pub)
195
    app = login(get_app(pub))
196
    resp = app.get('/backoffice/workflows/')
197
    resp = resp.click(r'Default \(cards\)')
198
    assert 'status/recorded/' in resp.text
199
    assert 'status/deleted/' in resp.text
200
    assert 'This is the default workflow,' in resp.text
tests/admin_pages/test_studio.py
1
import pytest
2

  
3
from wcs.qommon.http_request import HTTPRequest
4

  
5
from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, login
6
from .test_all import create_superuser
7

  
8

  
9
def pytest_generate_tests(metafunc):
10
    if 'pub' in metafunc.fixturenames:
11
        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
12

  
13

  
14
@pytest.fixture
15
def pub(request):
16
    pub = create_temporary_pub(sql_mode=bool('sql' in request.param))
17

  
18
    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
19
    pub.set_app_dir(req)
20
    pub.cfg['identification'] = {'methods': ['password']}
21
    pub.cfg['language'] = {'language': 'en'}
22
    pub.write_cfg()
23

  
24
    return pub
25

  
26

  
27
def teardown_module(module):
28
    clean_temporary_pub()
29

  
30

  
31
def test_studio_home(pub):
32
    create_superuser(pub)
33
    app = login(get_app(pub))
34
    resp = app.get('/backoffice/')
35
    assert 'studio' in resp.text
36
    resp = app.get('/backoffice/studio/')
37
    assert '../forms/' in resp.text
38
    assert '../cards/' in resp.text
39
    assert '../workflows/' in resp.text
40
    assert 'Logged Errors' in resp.text
41

  
42
    pub.cfg['admin-permissions'] = {}
43
    for part in ('forms', 'cards', 'workflows'):
44
        # check section link are not displayed if user has no access right
45
        pub.cfg['admin-permissions'].update({part: ['x']})  # block access
46
        pub.write_cfg()
47
        if part != 'workflows':
48
            resp = app.get('/backoffice/studio/')
49
            assert '../%s/' % part not in resp.text
50
        else:
51
            resp = app.get('/backoffice/studio/', status=403)  # totally closed
52

  
53
    resp = app.get('/backoffice/')
54
    assert 'studio' not in resp.text
55

  
56

  
57
def test_studio_workflows(pub):
58
    create_superuser(pub)
59
    app = login(get_app(pub))
60
    resp = app.get('/backoffice/workflows/')
61
    resp = resp.click(r'Default \(cards\)')
62
    assert 'status/recorded/' in resp.text
63
    assert 'status/deleted/' in resp.text
64
    assert 'This is the default workflow,' in resp.text
0
-