Skip to content

Commit

Permalink
Add tests for empty string and None
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-dileo committed Sep 8, 2015
1 parent d75d5b8 commit cc75028
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyeapi/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def set_sshkey(self, name, value=None):
True if the operation was successful otherwise False
"""
cmd = 'username %s' % name
if value is not None:
if value:
cmd += ' sshkey %s' % value
else:
cmd = 'no username %s sshkey' % name
Expand Down
20 changes: 20 additions & 0 deletions test/system/test_api_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ def test_set_sshkey_with_value(self):
self.assertTrue(result)
self.assertIn('username test sshkey %s' % TEST_SSH_KEY, api.config)

def test_set_sshkey_with_empty_string(self):
for dut in self.duts:
dut.config(['no username test', 'username test nopassword'])
api = dut.api('users')
self.assertIn('username test privilege 1 nopassword', api.config)
self.assertNotIn('username test sshkey', api.config)
result = api.set_sshkey('test', '')
self.assertTrue(result)
self.assertNotIn('username test sshkey %s' % TEST_SSH_KEY, api.config)

def test_set_sshkey_with_None(self):
for dut in self.duts:
dut.config(['no username test', 'username test nopassword'])
api = dut.api('users')
self.assertIn('username test privilege 1 nopassword', api.config)
self.assertNotIn('username test sshkey', api.config)
result = api.set_sshkey('test', None)
self.assertTrue(result)
self.assertNotIn('username test sshkey %s' % TEST_SSH_KEY, api.config)

def test_set_sshkey_with_no_value(self):
for dut in self.duts:
dut.config(['no username test',
Expand Down

0 comments on commit cc75028

Please sign in to comment.