diff --git a/tests/test_wizard.py b/tests/test_wizard.py new file mode 100644 index 000000000..e189a9ed5 --- /dev/null +++ b/tests/test_wizard.py @@ -0,0 +1,25 @@ +from django.template.loader import render_to_string +from django.test import SimpleTestCase + +class TestWizardActionsTemplate(SimpleTestCase): + def test_render_template_authenticated(self): + template_name = 'two_factor/_wizard_actions.html' + + # Render the template + rendered_template = self.render_template(template_name, {'user': {'is_authenticated': True}, 'cancel_url': '/cancel', 'wizard': {'steps': {'prev': 'previous_step'}}}) + + # Assert that the "Sign in" button is not present for authenticated users + self.assertNotIn('', rendered_template) + + def test_render_template_not_authenticated(self): + template_name = 'two_factor/_wizard_actions.html' + + # Render the template + rendered_template = self.render_template(template_name, {'user': {'is_authenticated': False}}) + + # Assert that the "Sign in" button is present for non-authenticated users + self.assertIn('Sign in', rendered_template) + + def render_template(self, template_name, context): + # Render the template with the context + return render_to_string(template_name, context) diff --git a/two_factor/templates/two_factor/_wizard_actions.html b/two_factor/templates/two_factor/_wizard_actions.html index fac484edd..00dce6a13 100644 --- a/two_factor/templates/two_factor/_wizard_actions.html +++ b/two_factor/templates/two_factor/_wizard_actions.html @@ -1,14 +1,25 @@ {% load i18n %} -{% if cancel_url %} - {% trans "Cancel" %} +{% if user.is_authenticated %} + {% if cancel_url %} + {% trans "Cancel" %} + {% endif %} + {% if wizard.steps.prev %} + + {% else %} + + {% endif %} + {% endif %} -{% if wizard.steps.prev %} - + +{% if user.is_authenticated %} + {# User is authenticated, don't show the "Sign in" button #} {% else %} - +