Skip to content

Commit

Permalink
[#20] Code refine and test case for FreeBSDUtils.user_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Sep 4, 2015
1 parent 3c58b6c commit b45175b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cloudbaseinit/osutils/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ def reboot(self):
raise OSError('Reboot failed')

def user_exists(self, username):
'''
:return: bool
'''
try:
subprocess.check_output(["id", username])
subprocess.check_output(['id', username])
except CalledProcessError:
return False
return True
Expand Down
4 changes: 4 additions & 0 deletions cloudbaseinit/tests/osutils/test_freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ def teardown_method(self, method):
def test_reboot(self, system):
with raises(OSError):
self.bsd.reboot()

def test_user_exists(self):
assert not self.bsd.user_exists('stranger')
assert self.bsd.user_exists('root')

0 comments on commit b45175b

Please sign in to comment.