core/auth: fix unittests for flows
This commit is contained in:
parent
2a85e5ae87
commit
273af0f1cb
|
@ -7,6 +7,7 @@ from django.urls import reverse
|
||||||
|
|
||||||
from passbook.core.forms.authentication import LoginForm, SignUpForm
|
from passbook.core.forms.authentication import LoginForm, SignUpForm
|
||||||
from passbook.core.models import User
|
from passbook.core.models import User
|
||||||
|
from passbook.flows.models import Flow, FlowDesignation
|
||||||
|
|
||||||
|
|
||||||
class TestAuthenticationViews(TestCase):
|
class TestAuthenticationViews(TestCase):
|
||||||
|
@ -77,7 +78,11 @@ class TestAuthenticationViews(TestCase):
|
||||||
reverse("passbook_core:auth-login"), data=self.login_data
|
reverse("passbook_core:auth-login"), data=self.login_data
|
||||||
)
|
)
|
||||||
self.assertEqual(login_response.status_code, 302)
|
self.assertEqual(login_response.status_code, 302)
|
||||||
self.assertEqual(login_response.url, reverse("passbook_flows:auth-process"))
|
flow = Flow.objects.get(designation=FlowDesignation.AUTHENTICATION)
|
||||||
|
expected = reverse(
|
||||||
|
"passbook_flows:flow-executor", kwargs={"flow_slug": flow.slug}
|
||||||
|
)
|
||||||
|
self.assertEqual(login_response.url, expected)
|
||||||
|
|
||||||
def test_sign_up_view_post(self):
|
def test_sign_up_view_post(self):
|
||||||
"""Test account.sign_up view POST (Anonymous)"""
|
"""Test account.sign_up view POST (Anonymous)"""
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
{% block beneath_form %}
|
{% block beneath_form %}
|
||||||
{% if show_password_forget_notice %}
|
{% if show_password_forget_notice %}
|
||||||
|
{# TODO: Link to dedicated recovery flow #}
|
||||||
<a href="{% url 'passbook_flows:auth-process' %}?password-forgotten">{% trans 'Forgot password?' %}</a>
|
<a href="{% url 'passbook_flows:auth-process' %}?password-forgotten">{% trans 'Forgot password?' %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-05-08 14:30
|
||||||
|
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
|
||||||
|
from passbook.flows.models import FlowDesignation
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
Flow = apps.get_model("passbook_flows", "Flow")
|
||||||
|
FlowFactorBinding = apps.get_model("passbook_flows", "FlowFactorBinding")
|
||||||
|
PasswordFactor = apps.get_model("passbook_factors_password", "PasswordFactor")
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
if Flow.objects.using(db_alias).all().exists():
|
||||||
|
# Only create default flow when none exist
|
||||||
|
return
|
||||||
|
|
||||||
|
pw_factor = PasswordFactor.objects.using(db_alias).first()
|
||||||
|
flow = Flow.objects.using(db_alias).create(
|
||||||
|
name="default-authentication-flow",
|
||||||
|
slug="default-authentication-flow",
|
||||||
|
designation=FlowDesignation.AUTHENTICATION,
|
||||||
|
)
|
||||||
|
FlowFactorBinding.objects.using(db_alias).create(
|
||||||
|
flow=flow, factor=pw_factor, order=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("passbook_flows", "0003_auto_20200508_1230"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [migrations.RunPython(create_default_flow)]
|
|
@ -2,7 +2,7 @@
|
||||||
isort -rc passbook
|
isort -rc passbook
|
||||||
pyright
|
pyright
|
||||||
black passbook
|
black passbook
|
||||||
# scripts/coverage.sh
|
scripts/coverage.sh
|
||||||
bandit -r passbook
|
bandit -r passbook
|
||||||
pylint passbook
|
pylint passbook
|
||||||
prospector
|
prospector
|
||||||
|
|
Reference in New Issue