From 273af0f1cb1c82779e7928d70682741c1040b34a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 8 May 2020 16:43:22 +0200 Subject: [PATCH] core/auth: fix unittests for flows --- .../core/tests/test_views_authentication.py | 7 +++- .../templates/factors/password/backend.html | 1 + .../flows/migrations/0004_default_flows.py | 37 +++++++++++++++++++ scripts/pre-commit.sh | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 passbook/flows/migrations/0004_default_flows.py diff --git a/passbook/core/tests/test_views_authentication.py b/passbook/core/tests/test_views_authentication.py index 870484223..1144abbd7 100644 --- a/passbook/core/tests/test_views_authentication.py +++ b/passbook/core/tests/test_views_authentication.py @@ -7,6 +7,7 @@ from django.urls import reverse from passbook.core.forms.authentication import LoginForm, SignUpForm from passbook.core.models import User +from passbook.flows.models import Flow, FlowDesignation class TestAuthenticationViews(TestCase): @@ -77,7 +78,11 @@ class TestAuthenticationViews(TestCase): reverse("passbook_core:auth-login"), data=self.login_data ) 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): """Test account.sign_up view POST (Anonymous)""" diff --git a/passbook/factors/password/templates/factors/password/backend.html b/passbook/factors/password/templates/factors/password/backend.html index 2115e9682..e270a5bbc 100644 --- a/passbook/factors/password/templates/factors/password/backend.html +++ b/passbook/factors/password/templates/factors/password/backend.html @@ -4,6 +4,7 @@ {% block beneath_form %} {% if show_password_forget_notice %} +{# TODO: Link to dedicated recovery flow #} {% trans 'Forgot password?' %} {% endif %} {% endblock %} diff --git a/passbook/flows/migrations/0004_default_flows.py b/passbook/flows/migrations/0004_default_flows.py new file mode 100644 index 000000000..c04d55df1 --- /dev/null +++ b/passbook/flows/migrations/0004_default_flows.py @@ -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)] diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index c5f6a7636..e97bac37c 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -2,7 +2,7 @@ isort -rc passbook pyright black passbook -# scripts/coverage.sh +scripts/coverage.sh bandit -r passbook pylint passbook prospector