Skip to content

Commit

Permalink
Improve code coverage rockstor#688
Browse files Browse the repository at this point in the history
  • Loading branch information
Mchakravartula committed Jun 30, 2015
1 parent 541bed0 commit 42dacac
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/rockstor/storageadmin/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_get(self):
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response)

def test_post_requests(self):

data = {'username': 'user1','password': 'pwuser1',}
invalid_user_names = ('User $', '-user', '.user', '', ' ',)
for uname in invalid_user_names:
Expand Down Expand Up @@ -131,6 +132,22 @@ def test_post_requests(self):
e_msg = ("user: admin already exists. Please choose a different username")
self.assertEqual(response.data['detail'], e_msg)

# create user with existing username admin2
data = {'username': 'admin2','password': 'pwadmin2',}
response = self.client.post(self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data)
e_msg = ("{'username': [u'User with this Username already exists.']}")
self.assertEqual(response.data['detail'], e_msg)

# create user with existing username admin2 and uid
data = {'username': 'admin2', 'password': 'pwadmin2', 'uid':'0000'}
response = self.client.post(self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data)
e_msg = ("user: admin2 already exists. Please choose a different username")
self.assertEqual(response.data['detail'], e_msg)

# create a user with existing uid (admin2 has uid 1001)
data = {'username': 'newUser','password': 'pwuser2', 'group': 'admin', 'uid':'1001','pubic_key':'xxx'}
response = self.client.post(self.BASE_URL, data=data)
Expand Down Expand Up @@ -203,7 +220,7 @@ def test_put_requests(self):
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)

data = {'password': 'admin2','group':'admin', 'admin': True, 'user':'uadmin2'}
data = {'password': 'admin2','group':'admin', 'admin': True, 'user':'uadmin2', 'public_key': self.valid_pubkey}
response = self.client.put('%s/admin2' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)
Expand All @@ -222,7 +239,8 @@ def test_delete_requests(self):
status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data)
e_msg = ("User(admin5) does not exist")
self.assertEqual(response.data['detail'], e_msg)



# delete user that does not exists
username = 'bin'
response = self.client.delete('%s/%s' % (self.BASE_URL,username))
Expand Down Expand Up @@ -260,3 +278,8 @@ def test_delete_requests(self):
response = self.client.delete('%s/%s' % (self.BASE_URL,username))
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)

username = 'chrony'
response = self.client.delete('%s/%s' % (self.BASE_URL,username))
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)

0 comments on commit 42dacac

Please sign in to comment.