-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added admin panel to add/remove superusers. Removed superuser option …
…from sign up page.
- Loading branch information
Aisha Saeed
committed
Jul 10, 2018
1 parent
e089078
commit f5b4958
Showing
1 changed file
with
46 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,17 @@ def form_params(self): | |
'email': '[email protected]', | ||
'password': 'foobar', | ||
'password1': 'foobar', | ||
} | ||
|
||
def form_params_admin_panel(self): | ||
return {'first_name': 'hellobar', | ||
'last_name': 'hellobar', | ||
'username': 'hellobar', | ||
'email': '[email protected]', | ||
'password': 'hellobar', | ||
'password1': 'hellobar', | ||
'is_superuser': True, | ||
'superuser_secret': 'Iamsuperuser12345',} | ||
} | ||
|
||
def test_login(self): | ||
user_login = self.client.login(username="testuser", password="secret") | ||
|
@@ -65,4 +74,39 @@ def test_post_signup(self): | |
|
||
#you = User.objects.filter(username=expected_username) | ||
#for y in you: | ||
#print(y.__dict__) | ||
#print(y.__dict__) | ||
def test_admin_panel(self): | ||
password = 'adminpassword' | ||
my_admin = User.objects.create_superuser('adminuser', '[email protected]', password) | ||
self.client.login(username=my_admin.username, password=password) | ||
response = self.client.get("/create_oauth_token") | ||
self.assertEqual(response.status_code, 302) | ||
u = User.objects.get(username='adminuser') | ||
self.assertTrue(u.is_superuser) | ||
response = self.client.get("/superusers_panel") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_admin_panel_normal_user(self): | ||
self.client.login(username='testuser', password='secret') | ||
response = self.client.get("/create_oauth_token") | ||
self.assertEqual(response.status_code, 302) | ||
u = User.objects.get(username='testuser') | ||
self.assertFalse(u.is_superuser) | ||
response = self.client.get("/superusers_panel") | ||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_post_admin_panel(self): | ||
params = self.form_params_admin_panel() | ||
expected_username = params['username'] | ||
|
||
password = 'adminpassword' | ||
my_admin = User.objects.create_superuser('adminuser', '[email protected]', password) | ||
self.client.login(username=my_admin.username, password=password) | ||
self.client.get("/create_oauth_token") | ||
self.client.post("/superusers_panel", params) | ||
|
||
self.assertTrue(User.objects.filter(username=expected_username).exists(), | ||
"SuperUser was not created.") | ||
|
||
new_user = User.objects.get(username=expected_username) | ||
self.assertTrue(new_user.is_superuser) |