def test_criate_delete(self): self.assertListEqual(User.listAll(), users) User('criate_delete').create() self.assertListEqual(User.listAll(), users + ['criate_delete']) User('criate_delete').delete() self.assertListEqual(User.listAll(), users) self.assertListEqual(Group.listAll(), groups)
def clean(): for x in User.listAll(): if not x in users: User(x).delete() for x in Group.listAll(): if not x in groups: Group(x).delete()
def test_users(self): Group('users', history_timeout=0.1).create() User('usersA').create() User('usersA').enterGroup('users') User('usersB').create() User('usersB').enterGroup('users') myusers = Group('users').users() self.assertListEqual(myusers, ['usersA', 'usersB'])
def test_permissions(self): mypath = '/home/permissions/a/b/c/d/e/f' os.makedirs(mypath, mode=0o000) User('permissions').create() uid = User('permissions').uid() gid = Group('permissions').gid() self.assertEqual(os.stat(mypath).st_gid, gid) self.assertEqual(os.stat(mypath).st_uid, uid) os.removedirs(mypath)
def test_add(self): resp = requests.post('http://api:80/user/addU') self.assertEqual(resp.text, "") self.assertEqual(resp.ok, True) resp = requests.get('http://api:80/user/') data = resp.json() self.assertIn("addU", data['users']) self.assertListEqual(User.listAll(), users + ['addU']) User('addU').delete() self.assertListEqual(User.listAll(), users) self.assertListEqual(Group.listAll(), groups)
def test_populateHome(self): User('populateHome').create() self.assertEqual( os.path.exists('/home/populateHome/Desktop/operacoes'), True)
def test_list(self): self.assertListEqual(User.listAll(), users)
def clean(): for x in User.listAll(): if not x in users: User(x).delete() for x in Group.listAll(): if not x in groups: Group(x).delete() # extra measure to avoid running this in production assert set(groups) == set(Group.listAll()) # extra measure to avoid running this in production assert set(users) == set(User.listAll()) class UserTest(unittest.TestCase): def setUp(self): clean() def tearDown(self): clean() def test_list(self): self.assertListEqual(User.listAll(), users) def test_criate_delete(self): self.assertListEqual(User.listAll(), users) User('criate_delete').create()