From d7aed1b502a0460369fb127d420336a9437da7f3 Mon Sep 17 00:00:00 2001 From: themanyfaceddemon Date: Mon, 26 Aug 2024 17:27:28 +0300 Subject: [PATCH] fix tests --- Tests/Server.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Tests/Server.py b/Tests/Server.py index 7a93ca5..a063ee2 100644 --- a/Tests/Server.py +++ b/Tests/Server.py @@ -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__':