mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 09:01:31 -08:00
add accounts/tests/test_disable_totp_view.py
This commit is contained in:
parent
20ce2c493b
commit
f199e8f173
45
accounts/tests/test_disable_totp_view.py
Normal file
45
accounts/tests/test_disable_totp_view.py
Normal file
@ -0,0 +1,45 @@
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from accounts.models import Account
|
||||
from django.urls import reverse
|
||||
import pyotp
|
||||
|
||||
|
||||
class TestDisableTOTPViewTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
user_a = User.objects.create(username='user_a')
|
||||
user_a.set_password('password_user_a')
|
||||
user_a.save()
|
||||
Account.objects.create(user=user_a)
|
||||
user_b = User.objects.create(username='user_b')
|
||||
user_b.set_password('password_user_b')
|
||||
user_b.save()
|
||||
Account.objects.create(
|
||||
user=user_b,
|
||||
use_totp=True, totp_key=pyotp.random_base32())
|
||||
|
||||
def test_dsable_totp_view_no_login(self):
|
||||
response = self.client.post(reverse('accounts:disable_totp'), follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'audio/index.html')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/')
|
||||
|
||||
def test_dsable_totp_view_not_enabled(self):
|
||||
self.client.login(username='user_a', password='password_user_a')
|
||||
response = self.client.post(reverse('accounts:disable_totp'), follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'audio/index.html')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/')
|
||||
|
||||
def test_dsable_totp_view(self):
|
||||
self.client.login(username='user_b', password='password_user_b')
|
||||
response = self.client.post(reverse('accounts:disable_totp'), follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
||||
user_b = User.objects.get(username='user_b')
|
||||
self.assertFalse(user_b.account.use_totp)
|
||||
self.assertIsNone(user_b.account.totp_key)
|
||||
msg = "Thanks for disabling 2fa!"
|
||||
self.assertEquals(response.content.decode('utf-8').count(msg), 1)
|
Loading…
Reference in New Issue
Block a user