From 1ddc459ed3a776fabd1eead3d3d5a9beabc72234 Mon Sep 17 00:00:00 2001 From: Trent Palmer Date: Tue, 6 Apr 2021 23:16:54 -0700 Subject: [PATCH] add some more tests --- .gitignore | 1 + accounts/tests.py | 3 -- accounts/tests/__init__.py | 0 accounts/tests/test_email_white_list_model.py | 23 +++++++++++++++ accounts/tests/test_user_model.py | 29 +++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) delete mode 100644 accounts/tests.py create mode 100644 accounts/tests/__init__.py create mode 100644 accounts/tests/test_email_white_list_model.py create mode 100644 accounts/tests/test_user_model.py diff --git a/.gitignore b/.gitignore index 9d14ec9..9075cee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ db.sqlite3 accounts/__pycache__ accounts/migrations/__pycache__ +accounts/tests/__pycache__ audio/__pycache__ audio/migrations/__pycache__ audio/tests/__pycache__ diff --git a/accounts/tests.py b/accounts/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/accounts/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/accounts/tests/__init__.py b/accounts/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/tests/test_email_white_list_model.py b/accounts/tests/test_email_white_list_model.py new file mode 100644 index 0000000..bfe07a7 --- /dev/null +++ b/accounts/tests/test_email_white_list_model.py @@ -0,0 +1,23 @@ +from django.test import TestCase +from uuid import UUID +from accounts.models import EmailWhiteList + + +class EmailWhiteListModelTest(TestCase): + + def setUp(self): + email_a = EmailWhiteList(email='user_a@example.com') + email_a.save() + EmailWhiteList.objects.create(email='user_b@example.com') + + def test_email(self): + white_listed_emails = EmailWhiteList.objects.all() + + self.assertTrue(len(white_listed_emails) == 2) + + email_a = white_listed_emails.filter(pk=1) + self.assertTrue(len(email_a) == 0) + + for i, x in enumerate(white_listed_emails): + self.assertTrue(isinstance(white_listed_emails[i].pk, UUID)) + self.assertTrue(isinstance(white_listed_emails[i].email, str)) diff --git a/accounts/tests/test_user_model.py b/accounts/tests/test_user_model.py new file mode 100644 index 0000000..14b5300 --- /dev/null +++ b/accounts/tests/test_user_model.py @@ -0,0 +1,29 @@ +from django.test import TestCase +from django.contrib.auth.models import User + + +class UserModelTest(TestCase): + + def setUp(self): + user_a = User(email='user_a@example.com', username='user_a') + user_a.set_password('password123456') + user_a.save() + user_b = User(email='user_b@example.com', username='user_b') + user_b.set_password('123456password') + user_b.save() + + def test_user(self): + test_users = User.objects.all() + for i, x in enumerate(test_users): + self.assertTrue(isinstance(test_users[i].email, str)) + self.assertTrue(isinstance(test_users[i].username, str)) + + user_a = User.objects.get(username='user_a') + self.assertTrue(user_a.check_password('password123456')) + self.assertFalse(user_a.check_password('foo')) + self.assertEqual(user_a.pk, 1) + + user_b = User.objects.get(username='user_b') + self.assertTrue(user_b.check_password('123456password')) + self.assertFalse(user_b.check_password('bar')) + self.assertEqual(user_b.pk, 2)