-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature #159687667] Enable manager to delete from a gym and add alre…
…ady existing users to the gym. The following changes have been made: * Modified the UI to enable addition of already existing users to the gym. * Enabled deletion of users from the gym only but not the entire app. * Created form to verify if the user already exists. * added tests. [Delivers #159687667]
- Loading branch information
Showing
5 changed files
with
194 additions
and
8 deletions.
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
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 |
---|---|---|
|
@@ -142,6 +142,69 @@ def test_new_user_data_export(self): | |
self.new_user_data_export(fail=True) | ||
|
||
|
||
class GymAddExistingUserTestCase(WorkoutManagerTestCase): | ||
''' | ||
Tests admin adding users to gyms | ||
''' | ||
def add_existing_user(self, fail=False, logged_in=True, role='admin'): | ||
''' | ||
Helper function to add users | ||
''' | ||
GymAdminConfig.objects.all().delete() | ||
count_after = User.objects.all().count() | ||
|
||
self.client.post(reverse('gym:gym:add-user', kwargs={'gym_pk': 1}), | ||
{'first_name': 'Cletus', | ||
'last_name': 'Spuckle', | ||
'username': 'cletus', | ||
'email': '[email protected]', | ||
'role': str(role)}) | ||
|
||
response = self.client.post(reverse('gym:gym:add-user-existing', kwargs={'gym_pk': 1}), | ||
{'username': 'cletus', 'role': str(role)}) | ||
|
||
count_before = User.objects.all().count() | ||
|
||
if fail: | ||
self.assertEqual(response.status_code, 403) | ||
self.assertEqual(count_before, count_after) | ||
self.assertFalse(self.client.session.get('gym.user')) | ||
else: | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(self.client.session['gym.user']['user_pk'], 3) | ||
self.assertTrue(self.client.session['gym.user']['password']) | ||
|
||
def test_delete_user_authorized(self): | ||
""" | ||
Tests deleting a user an authorized user | ||
""" | ||
self.user_login('admin') | ||
self.add_existing_user() | ||
|
||
def test_delete_user_unauthorized(self): | ||
""" | ||
Tests deleting a user an unauthorized user | ||
""" | ||
self.user_login('test') | ||
self.add_existing_user(fail=True) | ||
|
||
def test_delete_user_not_logged_in(self): | ||
""" | ||
Tests deleting a user an unauthorized user | ||
""" | ||
self.add_existing_user(fail=True, logged_in=False) | ||
|
||
def test_adds_right_roles(self): | ||
self.user_login('admin') | ||
self.add_existing_user(role='trainer') | ||
|
||
self.user_login('admin') | ||
self.add_existing_user(role='user') | ||
|
||
self.user_login('admin') | ||
self.add_existing_user(role='manager') | ||
|
||
|
||
class TrainerLoginTestCase(WorkoutManagerTestCase): | ||
''' | ||
Tests the trainer login view (switching to user ID) | ||
|
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