From 8bdf12cff184ce364bcbda2b36e9cb6b12f67b5a Mon Sep 17 00:00:00 2001 From: "Langhammer, Jens" Date: Mon, 14 Oct 2019 17:12:56 +0200 Subject: [PATCH] recovery(minor): add unittests --- .../{tests/test_auth_view.py => tests.py} | 0 passbook/factors/tests/__init__.py | 0 passbook/recovery/tests.py | 31 +++++++++++++++++++ 3 files changed, 31 insertions(+) rename passbook/factors/{tests/test_auth_view.py => tests.py} (100%) delete mode 100644 passbook/factors/tests/__init__.py create mode 100644 passbook/recovery/tests.py diff --git a/passbook/factors/tests/test_auth_view.py b/passbook/factors/tests.py similarity index 100% rename from passbook/factors/tests/test_auth_view.py rename to passbook/factors/tests.py diff --git a/passbook/factors/tests/__init__.py b/passbook/factors/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/passbook/recovery/tests.py b/passbook/recovery/tests.py new file mode 100644 index 000000000..9057295e1 --- /dev/null +++ b/passbook/recovery/tests.py @@ -0,0 +1,31 @@ +"""recovery tests""" +from io import StringIO + +from django.core.management import call_command +from django.shortcuts import reverse +from django.test import TestCase + +from passbook.core.models import Nonce, User + + +class TestRecovery(TestCase): + """recovery tests""" + + def setUp(self): + self.user = User.objects.create_user( + username='recovery-test-user') + + def test_create_key(self): + """Test creation of a new key""" + out = StringIO() + self.assertEqual(len(Nonce.objects.all()), 0) + call_command('create_recovery_key', '1', self.user.username, stdout=out) + self.assertIn('https://localhost/recovery/use-nonce/', out.getvalue()) + self.assertEqual(len(Nonce.objects.all()), 1) + + def test_recovery_view(self): + """Test recovery view""" + call_command('create_recovery_key', '1', self.user.username) + nonce = Nonce.objects.first() + self.client.get(reverse('passbook_recovery:use-nonce', kwargs={'uuid': str(nonce.uuid)})) + self.assertEqual(int(self.client.session['_auth_user_id']), nonce.user.pk)