-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add formset stuff to tests for user creation
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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='[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') | ||
|