From d7fa21a37c647af861b2b990ca1c03ea10b0c0f8 Mon Sep 17 00:00:00 2001 From: Joey Chatelain Date: Wed, 4 Dec 2024 10:48:02 -0800 Subject: [PATCH] add formset stuff to tests for user creation --- tom_common/apps.py | 1 - tom_common/tests.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tom_common/apps.py b/tom_common/apps.py index bad46be50..fae63b5fc 100644 --- a/tom_common/apps.py +++ b/tom_common/apps.py @@ -7,7 +7,6 @@ class TomCommonConfig(AppConfig): name = 'tom_common' def ready(self): - # Set default plotly theme on startup valid_themes = ['plotly', 'plotly_white', 'plotly_dark', 'ggplot2', 'seaborn', 'simple_white', 'none'] diff --git a/tom_common/tests.py b/tom_common/tests.py index 105b952a8..dae42f6c5 100644 --- a/tom_common/tests.py +++ b/tom_common/tests.py @@ -38,6 +38,8 @@ def test_user_list(self): def test_user_create(self): user_data = { + 'profile-TOTAL_FORMS': '1', + 'profile-INITIAL_FORMS': '0', 'username': 'testuser', 'first_name': 'first', 'last_name': 'last', @@ -83,6 +85,8 @@ def test_user_can_update_self(self): user = User.objects.create(username='luke', password='forc3') self.client.force_login(user) user_data = { + 'profile-TOTAL_FORMS': '1', + 'profile-INITIAL_FORMS': '0', 'username': 'luke', 'first_name': 'Luke', 'last_name': 'Skywalker', @@ -99,6 +103,8 @@ def test_user_cannot_update_other(self): user = User.objects.create(username='luke', password='forc3') self.client.force_login(user) user_data = { + 'profile-TOTAL_FORMS': '1', + 'profile-INITIAL_FORMS': '0', 'username': 'luke', 'first_name': 'Luke', 'last_name': 'Skywalker', @@ -111,6 +117,37 @@ def test_user_cannot_update_other(self): self.assertRedirects(response, reverse('user-update', kwargs={'pk': user.id})) self.assertNotEqual(self.admin.username, user_data['username']) + def test_user_can_delete_self(self): + user = User.objects.create(username='luke', password='forc3') + self.client.force_login(user) + self.assertTrue(User.objects.filter(username='luke').exists()) + response = self.client.post(reverse('user-delete', kwargs={'pk': user.id}), follow=True) + self.assertEqual(response.status_code, 200) + self.assertFalse(User.objects.filter(username='luke').exists()) + + +class TestUserProfile(TestCase): + def setUp(self): + self.admin = User.objects.create_superuser(username='admin', password='admin', email='test@example.com') + self.client.force_login(self.admin) + + def test_user_profile(self): + user_data = { + 'profile-TOTAL_FORMS': '1', + 'profile-INITIAL_FORMS': '0', + 'username': 'testuser', + 'first_name': 'first', + 'last_name': 'last', + 'email': 'testuser@example.com', + 'password1': 'suchsecure543', + 'password2': 'suchsecure543', + 'profile-0-affiliation': 'Test University', + } + response = self.client.post(reverse('user-create'), data=user_data, follow=True) + self.assertEqual(response.status_code, 200) + user = User.objects.get(username='testuser') + self.assertEqual(user.profile.affiliation, 'Test University') + class TestAuthScheme(TestCase): @override_settings(AUTH_STRATEGY='LOCKED')