-
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
6 changed files
with
191 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.core.urlresolvers import reverse | ||
from wger.core.tests.base_testcase import WorkoutManagerTestCase | ||
from wger.gym.models import GymAdminConfig | ||
from django.contrib.auth.models import User | ||
|
||
|
||
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() | ||
|
||
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)}) | ||
|
||
user = GymAdminConfig.objects.first() | ||
if not fail: | ||
user_pk = user.user_id if user else 4 | ||
self.client.post( | ||
reverse('gym:gym:delete-user', kwargs={'user_pk': user_pk})) | ||
|
||
response = self.client.post(reverse('gym:gym:add-user-existing', kwargs={'gym_pk': 1}), | ||
{'username': 'cletus', 'role': str(role)}) | ||
|
||
if fail: | ||
self.assertEqual(response.status_code, 403) | ||
else: | ||
self.assertEqual(response.status_code, 302) | ||
|
||
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) |
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