Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from django.test import TestCase

from two_factor.forms import AuthenticationTokenForm
from tests.utils import method_registry
from two_factor.forms import AuthenticationTokenForm, MethodForm


class FormTests(TestCase):
def test_auth_token_form(self):
form = AuthenticationTokenForm(None, None, data={'otp_token': '005428'})
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['otp_token'], '005428')

@method_registry([])
def test_method_form_empty_registry(self):
form = MethodForm()
self.assertEqual(form.fields['method'].choices, [])
self.assertIsNone(form.fields['method'].initial)
7 changes: 7 additions & 0 deletions tests/test_views_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def test_form(self):
self.assertContains(response, 'Follow the steps in this wizard to '
'enable two-factor')

@method_registry([])
def test_setup_no_methods_available(self):
response = self.client.post(
reverse('two_factor:setup'),
data={'setup_view-current_step': 'welcome'})
self.assertEqual(response.status_code, 200)

@method_registry(['generator'])
def test_setup_only_generator_available(self):
response = self.client.post(
Expand Down
3 changes: 2 additions & 1 deletion two_factor/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(self, **kwargs):
method.choices = [
(m.code, m.verbose_name) for m in registry.get_methods()
]
method.initial = method.choices[0][0]
if method.choices:
method.initial = method.choices[0][0]


class DeviceValidationForm(forms.Form):
Expand Down