Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
remade committed Nov 13, 2024
1 parent bb294eb commit 9b8a429
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 59 deletions.
26 changes: 7 additions & 19 deletions tests/integration/blocking/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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__":
Expand Down
19 changes: 7 additions & 12 deletions tests/integration/blocking/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"]
Expand All @@ -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):
Expand All @@ -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;"]
Expand All @@ -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):
Expand Down
15 changes: 8 additions & 7 deletions tests/integration/blocking/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"]
Expand All @@ -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"],
)


Expand Down
15 changes: 7 additions & 8 deletions tests/integration/blocking/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"]
Expand All @@ -39,7 +38,7 @@ def test_set_ql(self):
"skills": ["Rust", "Go", "JavaScript"],
}
],
outcome,
outcome[0]["result"],
)

def test_set(self):
Expand All @@ -62,7 +61,7 @@ def test_set(self):
"name": {"last": "Morgan Hitchcock", "name": "Tobie"},
}
],
outcome,
outcome[0]["result"],
)


Expand Down
12 changes: 5 additions & 7 deletions tests/integration/blocking/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"]
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_http_connection.py
Original file line number Diff line number Diff line change
@@ -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'})
8 changes: 4 additions & 4 deletions tests/unit/test_ws_connection.py
Original file line number Diff line number Diff line change
@@ -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'})

0 comments on commit 9b8a429

Please sign in to comment.