Projet

Général

Profil

0004-tests-add-test-to-home-views-40098.patch

Nicolas Roche, 27 février 2020 01:09

Télécharger (3,41 ko)

Voir les différences:

Subject: [PATCH 4/6] tests: add test to home views (#40098)

 tests/test_home_views.py | 95 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 tests/test_home_views.py
tests/test_home_views.py
1
# -*- coding: utf-8 -*-
2
import mock
3
import pytest
4

  
5
from django.contrib.auth.models import User
6

  
7
from hobo.environment.models import Authentic
8

  
9
from test_manager import login
10

  
11
pytestmark = pytest.mark.django_db
12

  
13

  
14
@pytest.fixture
15
def user(db):
16
    return User.objects.create_user('jhon', email='jhon@doe.love', password='xxx')
17

  
18
def test_home_view(app, admin_user):
19
    app = login(app)
20
    resp = app.get('/')
21
    assert resp.html.find('h1').text == 'System'
22
    assert resp.html.find('h2').text == 'System'
23

  
24
def test_home_view_with_normal_user(app, user):
25
    app = login(app, 'jhon', 'xxx')
26
    app.get('/', status=403)
27

  
28
def test_home_view_with_not_auth(app):
29
    resp = app.get('/')
30
    assert resp.location == '/login/?next=/'
31

  
32
def test_hobo_view(app, user):
33
    app = login(app, 'jhon', 'xxx')
34
    resp = app.get('/hobos.json')
35
    assert resp.json == ['http://testserver/']
36

  
37
def test_idp_login(app, user):
38
    Authentic.objects.create(
39
        title='bar',
40
        slug='bar',
41
        base_url='http://bar.example.net',
42
        use_as_idp_for_self=True,
43
        last_operational_success_timestamp='2022-2-22',
44
        last_operational_check_timestamp='2022-2-22'
45
    )
46
    resp = app.get('/login/')
47
    assert resp.location == '/accounts/mellon/login/?'
48

  
49
@mock.patch('hobo.views.auth_logout')
50
def test_logout_view(mocked_logout, app):
51
    resp = app.get('/logout/')
52
    assert mocked_logout.called
53
    assert resp.location == 'http://testserver/'
54

  
55
    Authentic.objects.create(
56
        title='bar',
57
        slug='bar',
58
        base_url='http://bar.example.net',
59
        use_as_idp_for_self=True,
60
        last_operational_success_timestamp='2022-2-22',
61
        last_operational_check_timestamp='2022-2-22'
62
    )
63
    resp = app.get('/logout/')
64
    assert resp.location == '/accounts/mellon/logout/?'
65

  
66
def test_healt_view(app):
67
    resp = app.get('/api/health/')
68
    assert resp.json == {'data': {}}
69
    Authentic.objects.create(
70
        title='bar',
71
        slug='bar',
72
        base_url='http://bar.example.net',
73
        last_operational_success_timestamp='2022-2-22',
74
        last_operational_check_timestamp='2022-2-22'
75
    )
76
    resp = app.get('/api/health/')
77
    assert resp.json == {
78
        'data': {
79
            'bar': {
80
                'has_valid_certificate': False,
81
                'is_operational': True,
82
                'is_resolvable': False,
83
                'is_running': False
84
            }}}
85

  
86
def test_menu_view(app, admin_user):
87
    json_str = [{"slug": "system", "label": "System", "url": "http://testserver/"}]
88
    app = login(app)
89
    resp = app.get('/menu.json')
90
    assert resp.content_type == 'application/json'
91
    assert resp.json == json_str
92

  
93
    resp = app.get('/menu.json?callback=foo')
94
    assert resp.content_type == 'application/javascript'
95
    assert resp.text == ('foo(%s);' % json_str).replace("'", '"')
0
-