Skip to content

Commit

Permalink
add formset stuff to tests for user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Dec 4, 2024
1 parent 021f9e8 commit d7fa21a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 0 additions & 1 deletion tom_common/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
37 changes: 37 additions & 0 deletions tom_common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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='[email protected]')
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': '[email protected]',
'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')
Expand Down

0 comments on commit d7fa21a

Please sign in to comment.