Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Aug 26, 2024
1 parent bb98b45 commit d7aed1b
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions Tests/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,59 @@ async def asyncSetUp(self):
self.db_path = Path("test_dir")
self.db_path.mkdir(parents=True, exist_ok=True)

self.server = Server('localhost', 8888, self.db_path, 'test_owner_password')
await self.server._init_db()
Server()

Server.set_host('localhost')
Server.set_port(5000)
Server.set_db_path(self.db_path)

Server.set_owner_password('test_owner_password')
await Server._init_db()

async def asyncTearDown(self):
await self.server.stop()
await Server.stop()
shutil.rmtree(self.db_path)

async def test_init_db(self):
access = await self.server.db_get_access('owner')
access = await Server.db_get_access('owner')
self.assertIsNotNone(access)
self.assertIn('full_access', access)
self.assertTrue(access['full_access'])

async def test_db_add_user(self):
await self.server.db_add_user('test_user', 'password123', {'read': True})
access = await self.server.db_get_access('test_user')
await Server.db_add_user('test_user', 'password123', {'read': True})
access = await Server.db_get_access('test_user')
self.assertIsNotNone(access)
self.assertIn('read', access)
self.assertTrue(access['read'])

async def test_db_login_user(self):
await self.server.db_add_user('test_user', 'password123', {'read': True})
login_result = await self.server.db_login_user('test_user', 'password123')
await Server.db_add_user('test_user', 'password123', {'read': True})
login_result = await Server.db_login_user('test_user', 'password123')
self.assertEqual(login_result, 'test_user')

wrong_login_result = await self.server.db_login_user('test_user', 'wrongpassword')
wrong_login_result = await Server.db_login_user('test_user', 'wrongpassword')
self.assertIsNone(wrong_login_result)

async def test_db_change_password(self):
await self.server.db_add_user('test_user', 'password123', {'read': True})
await self.server.db_change_password('test_user', 'newpassword123')
login_result = await self.server.db_login_user('test_user', 'newpassword123')
await Server.db_add_user('test_user', 'password123', {'read': True})
await Server.db_change_password('test_user', 'newpassword123')
login_result = await Server.db_login_user('test_user', 'newpassword123')
self.assertEqual(login_result, 'test_user')

async def test_db_change_access(self):
await self.server.db_add_user('test_user', 'password123', {'read': True})
await self.server.db_change_access('test_user', {'write': True})
access = await self.server.db_get_access('test_user')
await Server.db_add_user('test_user', 'password123', {'read': True})
await Server.db_change_access('test_user', {'write': True})
access = await Server.db_get_access('test_user')
self.assertIsNotNone(access)
self.assertIn('write', access)
self.assertTrue(access['write'])
self.assertNotIn('read', access)

async def test_db_delete_user(self):
await self.server.db_add_user('test_user', 'password123', {'read': True})
await self.server.db_delete_user('test_user')
access = await self.server.db_get_access('test_user')
await Server.db_add_user('test_user', 'password123', {'read': True})
await Server.db_delete_user('test_user')
access = await Server.db_get_access('test_user')
self.assertIsNone(access)

if __name__ == '__main__':
Expand Down

0 comments on commit d7aed1b

Please sign in to comment.