tests: add more
gitea/ants-hub/pipeline/head This commit looks good
Details
gitea/ants-hub/pipeline/head This commit looks good
Details
This commit is contained in:
parent
52e0f1d6a8
commit
789e5aa6e9
|
@ -4,3 +4,4 @@ pytest-django
|
||||||
freezegun
|
freezegun
|
||||||
django-webtest
|
django-webtest
|
||||||
responses
|
responses
|
||||||
|
pyquery
|
||||||
|
|
|
@ -1,5 +1,111 @@
|
||||||
# ANTS-Hub - Copyright (C) Entr'ouvert
|
# ANTS-Hub - Copyright (C) Entr'ouvert
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
def test_dummy():
|
|
||||||
pass
|
def table_text(table):
|
||||||
|
content = []
|
||||||
|
for row in table.find('tr').items():
|
||||||
|
content.append([cell.text() for cell in (row.find('td, th')).items()])
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
|
def setup(django_db_blocker):
|
||||||
|
with django_db_blocker.unblock():
|
||||||
|
with transaction.atomic():
|
||||||
|
call_command('loaddata', 'fixtures/admin.json')
|
||||||
|
call_command('loaddata', 'fixtures/example1.json')
|
||||||
|
with django_db_blocker.block():
|
||||||
|
yield
|
||||||
|
transaction.set_rollback(True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def freezer(freezer):
|
||||||
|
freezer.move_to('2023-04-12T12:00:00+02:00')
|
||||||
|
return freezer
|
||||||
|
|
||||||
|
|
||||||
|
def test_login(django_app, db):
|
||||||
|
resp = django_app.get('/').maybe_follow()
|
||||||
|
resp.form.set('username', 'admin')
|
||||||
|
resp.form.set('password', 'admin')
|
||||||
|
resp = resp.form.submit()
|
||||||
|
|
||||||
|
|
||||||
|
class TestLogged:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, django_app, db):
|
||||||
|
test_login(django_app, db)
|
||||||
|
return django_app
|
||||||
|
|
||||||
|
def test_create_raccordement(self, app):
|
||||||
|
resp = app.get('/').maybe_follow()
|
||||||
|
resp = resp.click('Ajouter', href='raccordement')
|
||||||
|
resp.form.set('name', 'Plateforme Y')
|
||||||
|
resp.form.set('apikey', 'a' * 32)
|
||||||
|
resp.form.set('notes', 'Penser à facturer.')
|
||||||
|
resp = resp.form.submit('_save').follow()
|
||||||
|
assert table_text(resp.pyquery('#result_list')) == [
|
||||||
|
['', 'Nom', 'API key', 'Création', 'Dernière mise à jour'],
|
||||||
|
['', 'Plateforme X', '01a5…', '3 avril 2023 12:14', '3 avril 2023 19:57'],
|
||||||
|
['', 'Plateforme Y', 'aaaa…', '12 avril 2023 12:00', '12 avril 2023 12:00'],
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_collectivite(self, app):
|
||||||
|
resp = app.get('/').maybe_follow()
|
||||||
|
resp = resp.click('Collectivités')
|
||||||
|
assert table_text(resp.pyquery('#result_list')) == [
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'Raccordement',
|
||||||
|
'Nom',
|
||||||
|
'URL du portail',
|
||||||
|
'Identifiant de la collectivité à la source',
|
||||||
|
'Création',
|
||||||
|
'Dernière mise à jour',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'Plateforme X',
|
||||||
|
'Saint-Didier',
|
||||||
|
'https://saint-didier.fr/',
|
||||||
|
'saint-didier',
|
||||||
|
'3 avril 2023 12:14',
|
||||||
|
'3 avril 2023 12:14',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_lieux(self, app):
|
||||||
|
resp = app.get('/').maybe_follow()
|
||||||
|
resp = resp.click('Lieux')
|
||||||
|
assert table_text(resp.pyquery('#result_list')) == [
|
||||||
|
['', 'Collectivité', 'Nom', 'Création', 'Dernière mise à jour'],
|
||||||
|
['', 'Saint-Didier', 'Mairie', '3 avril 2023 12:15', '3 avril 2023 12:15'],
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_plages(self, app):
|
||||||
|
resp = app.get('/').maybe_follow()
|
||||||
|
resp = resp.click('Lieux')
|
||||||
|
assert table_text(resp.pyquery('#result_list')) == [
|
||||||
|
['', 'Collectivité', 'Nom', 'Création', 'Dernière mise à jour'],
|
||||||
|
['', 'Saint-Didier', 'Mairie', '3 avril 2023 12:15', '3 avril 2023 12:15'],
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_rdvs(self, app):
|
||||||
|
resp = app.get('/').maybe_follow()
|
||||||
|
resp = resp.click('Rendez-vous')
|
||||||
|
assert table_text(resp.pyquery('#result_list')) == [
|
||||||
|
['', '1\nDate', 'Lieu', '2\nIdentifiant de prédemande', 'Création', 'Dernière mise à jour'],
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'3 avril 2023 12:15',
|
||||||
|
'Mairie / 2 rue du four / Saint-Didier',
|
||||||
|
'abcd',
|
||||||
|
'3 avril 2023 12:16',
|
||||||
|
'3 avril 2023 12:16',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
# ANTS-Hub - Copyright (C) Entr'ouvert
|
# ANTS-Hub - Copyright (C) Entr'ouvert
|
||||||
|
|
||||||
from ants_hub.data.models import Raccordement, TypeDeRdv
|
import pytest
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
from ants_hub.data.models import Config, Raccordement, TypeDeRdv
|
||||||
|
|
||||||
|
|
||||||
def test_raccordement(db):
|
def test_raccordement(db):
|
||||||
apikey = Raccordement.objects.create(name='Example')
|
raccordement = Raccordement.objects.create(name='Example')
|
||||||
assert len(apikey.apikey) >= 32
|
assert len(raccordement.apikey) >= 32
|
||||||
|
old_apikey = raccordement.apikey
|
||||||
|
raccordement.apikey = 'NEW'
|
||||||
|
raccordement.clean()
|
||||||
|
assert len(raccordement.apikey) >= 32 and raccordement.apikey != old_apikey
|
||||||
|
|
||||||
|
raccordement.apikey = 'abcd'
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
raccordement.clean()
|
||||||
|
|
||||||
|
|
||||||
def test_type_de_rdv():
|
def test_type_de_rdv():
|
||||||
|
@ -20,3 +31,11 @@ def test_type_de_rdv():
|
||||||
assert TypeDeRdv.from_ants_name('CNI') == TypeDeRdv.CNI
|
assert TypeDeRdv.from_ants_name('CNI') == TypeDeRdv.CNI
|
||||||
assert TypeDeRdv.from_ants_name('PASSPORT') == TypeDeRdv.PASSPORT
|
assert TypeDeRdv.from_ants_name('PASSPORT') == TypeDeRdv.PASSPORT
|
||||||
assert TypeDeRdv.from_ants_name('CNI-PASSPORT') == TypeDeRdv.CNI_PASSPORT
|
assert TypeDeRdv.from_ants_name('CNI-PASSPORT') == TypeDeRdv.CNI_PASSPORT
|
||||||
|
|
||||||
|
|
||||||
|
def test_config(db):
|
||||||
|
Config.set(Config.REQUEST_FROM_ANTS_AUTH_TOKEN, 'xyz')
|
||||||
|
assert Config.get(Config.REQUEST_FROM_ANTS_AUTH_TOKEN) == 'xyz'
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
Config.set('unknown', '1')
|
||||||
|
assert 'authentification' in str(Config.objects.get())
|
||||||
|
|
Loading…
Reference in New Issue