diff --git a/tests/integration/blocking/test_auth.py b/tests/integration/blocking/test_auth.py index db153bea..31851d1a 100644 --- a/tests/integration/blocking/test_auth.py +++ b/tests/integration/blocking/test_auth.py @@ -15,16 +15,14 @@ def setUp(self): self.params = TestConnectionParams() self.db = SurrealDB(self.params.url) + self.db.connect() + self.db.use(self.params.namespace, self.params.database) + def tearDown(self): - pass + self.db.close() def login(self, username: str, password: str) -> None: - self.db.sign_in( - { - "username": username, - "password": password, - } - ) + self.db.sign_in(username, password) def test_login_success(self): self.login("root", "root") @@ -33,23 +31,13 @@ def test_login_wrong_password(self): with self.assertRaises(SurrealDbError) as context: self.login("root", "wrong") - if os.environ.get("CONNECTION_PROTOCOL", "http") == "http": - self.assertEqual(True, "(401 Unauthorized)" in str(context.exception)) - else: - self.assertEqual( - '"There was a problem with authentication"', str(context.exception) - ) + self.assertEqual(True, "There was a problem with authentication" in str(context.exception)) def test_login_wrong_username(self): with self.assertRaises(SurrealDbError) as context: self.login("wrong", "root") - if os.environ.get("CONNECTION_PROTOCOL", "http") == "http": - self.assertEqual(True, "(401 Unauthorized)" in str(context.exception)) - else: - self.assertEqual( - '"There was a problem with authentication"', str(context.exception) - ) + self.assertEqual(True, "There was a problem with authentication" in str(context.exception)) if __name__ == "__main__": diff --git a/tests/integration/blocking/test_create.py b/tests/integration/blocking/test_create.py index dda5e96d..f6bf9a69 100644 --- a/tests/integration/blocking/test_create.py +++ b/tests/integration/blocking/test_create.py @@ -16,19 +16,14 @@ def setUp(self): self.queries: List[str] = [] - def login(): - self.db.sign_in( - { - "username": "root", - "password": "root", - } - ) - - login() + self.db.connect() + self.db.use(self.params.namespace, self.params.database) + self.db.sign_in("root", "root") def tearDown(self): for query in self.queries: self.db.query(query) + self.db.close() def test_create_ql(self): self.queries = ["DELETE user;"] @@ -40,7 +35,7 @@ def test_create_ql(self): {"id": "user:jaime", "name": "Jaime"}, {"id": "user:tobie", "name": "Tobie"}, ], - outcome, + outcome[0]["result"], ) def test_delete_ql(self): @@ -50,7 +45,7 @@ def test_delete_ql(self): self.assertEqual([], outcome) outcome = self.db.query("SELECT * FROM user;") - self.assertEqual([], outcome) + self.assertEqual([], outcome[0]["result"]) def test_create_person_with_tags_ql(self): self.queries = ["DELETE person;"] @@ -75,7 +70,7 @@ def test_create_person_with_tags_ql(self): "user": "me", } ], - outcome, + outcome[0]["result"], ) def test_create_person_with_tags(self): diff --git a/tests/integration/blocking/test_merge.py b/tests/integration/blocking/test_merge.py index 9cb457ef..1a5bb600 100644 --- a/tests/integration/blocking/test_merge.py +++ b/tests/integration/blocking/test_merge.py @@ -15,16 +15,15 @@ def setUp(self): self.db = SurrealDB(self.params.url) self.queries: List[str] = [] - self.db.sign_in( - { - "username": "root", - "password": "root", - } - ) + + self.db.connect() + self.db.use(self.params.namespace, self.params.database) + self.db.sign_in("root", "root") def tearDown(self): for query in self.queries: self.db.query(query) + self.db.close() def test_merge_person_with_tags(self): self.queries = ["DELETE user;"] @@ -38,12 +37,14 @@ def test_merge_person_with_tags(self): "active": True, }, ) + + outcome = self.db.query("SELECT * FROM user;") self.assertEqual( [ {"active": True, "id": "user:jaime", "name": "Jaime"}, {"active": True, "id": "user:tobie", "name": "Tobie"}, ], - self.db.query("SELECT * FROM user;"), + outcome[0]["result"], ) diff --git a/tests/integration/blocking/test_set.py b/tests/integration/blocking/test_set.py index f0d819fe..1d5aa8ae 100644 --- a/tests/integration/blocking/test_set.py +++ b/tests/integration/blocking/test_set.py @@ -15,16 +15,15 @@ def setUp(self): self.db = SurrealDB(self.params.url) self.queries: List[str] = [] - self.db.sign_in( - { - "username": "root", - "password": "root", - } - ) + + self.db.connect() + self.db.use(self.params.namespace, self.params.database) + self.db.sign_in("root", "root") def tearDown(self): for query in self.queries: self.db.query(query) + self.db.close() def test_set_ql(self): self.queries = ["DELETE person;"] @@ -39,7 +38,7 @@ def test_set_ql(self): "skills": ["Rust", "Go", "JavaScript"], } ], - outcome, + outcome[0]["result"], ) def test_set(self): @@ -62,7 +61,7 @@ def test_set(self): "name": {"last": "Morgan Hitchcock", "name": "Tobie"}, } ], - outcome, + outcome[0]["result"], ) diff --git a/tests/integration/blocking/test_update.py b/tests/integration/blocking/test_update.py index 625ea667..a4c9d6e7 100644 --- a/tests/integration/blocking/test_update.py +++ b/tests/integration/blocking/test_update.py @@ -16,16 +16,14 @@ def setUp(self): self.queries: List[str] = [] - self.db.sign_in( - { - "username": "root", - "password": "root", - } - ) + self.db.connect() + self.db.use(self.params.namespace, self.params.database) + self.db.sign_in("root", "root") def tearDown(self): for query in self.queries: self.db.query(query) + self.db.close() def test_update_ql(self): self.queries = ["DELETE user;"] @@ -39,7 +37,7 @@ def test_update_ql(self): {"id": "user:jaime", "lastname": "Morgan Hitchcock", "name": "Jaime"}, {"id": "user:tobie", "lastname": "Morgan Hitchcock", "name": "Tobie"}, ], - outcome, + outcome[0]["result"], ) def test_update_person_with_tags(self): diff --git a/tests/unit/test_http_connection.py b/tests/unit/test_http_connection.py index f3b08344..6e50ab37 100644 --- a/tests/unit/test_http_connection.py +++ b/tests/unit/test_http_connection.py @@ -1,10 +1,10 @@ from unittest import TestCase -from surrealdb.http import HTTPConnection +from surrealdb.connection_http import HTTPConnection class TestWSConnection(TestCase): - def setup(self): + async def asyncSetup(self): http_con = HTTPConnection(base_url='http://localhost:8000', namespace='test', database='test') await http_con.connect() await http_con.send('signin', {'user': 'root', 'pass': 'root'}) diff --git a/tests/unit/test_ws_connection.py b/tests/unit/test_ws_connection.py index 8928d599..99505498 100644 --- a/tests/unit/test_ws_connection.py +++ b/tests/unit/test_ws_connection.py @@ -1,10 +1,10 @@ -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase -from surrealdb.ws import WebsocketConnection +from surrealdb.connection_ws import WebsocketConnection -class TestWSConnection(TestCase): - def setup(self): +class TestWSConnection(IsolatedAsyncioTestCase): + async def asyncSetup(self): ws_con = WebsocketConnection(base_url='ws://localhost:8000', namespace='test', database='test') await ws_con.connect() await ws_con.send('signin', {'user': 'root', 'pass': 'root'}) \ No newline at end of file