Skip to content

Commit

Permalink
Added admin panel to add/remove superusers. Removed superuser option …
Browse files Browse the repository at this point in the history
…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.
48 changes: 46 additions & 2 deletions omi_security/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

0 comments on commit f5b4958

Please sign in to comment.