From 0ef2fc71387c8d88f5e795e495e6e2162f7e8003 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:02:10 +0000 Subject: [PATCH 1/7] Fix issues with signup and signin --- src/surrealdb/connections/async_http.py | 62 ++++++++------ src/surrealdb/connections/async_template.py | 38 ++++----- src/surrealdb/connections/async_ws.py | 85 +++++++++---------- src/surrealdb/connections/blocking_http.py | 50 +++++++---- src/surrealdb/connections/blocking_ws.py | 75 +++++++++------- src/surrealdb/connections/sync_template.py | 38 ++++----- tests/__init__.py | 5 ++ tests/unit_tests/__init__.py | 5 ++ .../connections/signin/test_async_http.py | 13 +-- .../connections/signin/test_async_ws.py | 12 ++- .../connections/signup/test_async_http.py | 4 +- .../connections/signup/test_async_ws.py | 4 +- 12 files changed, 218 insertions(+), 173 deletions(-) diff --git a/src/surrealdb/connections/async_http.py b/src/surrealdb/connections/async_http.py index 9047f9d4..5f6ca293 100644 --- a/src/surrealdb/connections/async_http.py +++ b/src/surrealdb/connections/async_http.py @@ -98,6 +98,30 @@ def set_token(self, token: str) -> None: """ self.token = token + async def authenticate(self) -> None: + message = RequestMessage( + self.id, + RequestMethod.AUTHENTICATE, + token=token + ) + return await self._send(message, "authenticating") + + async def invalidate(self) -> None: + message = RequestMessage(self.id, RequestMethod.INVALIDATE) + await self._send(message, "invalidating") + self.token = None + + async def signup(self, vars: Dict) -> str: + message = RequestMessage( + self.id, + RequestMethod.SIGN_UP, + data=vars + ) + response = await self._send(message, "signup") + self.check_response_for_result(response, "signup") + self.token = response["result"] + return response["result"] + async def signin(self, vars: dict) -> dict: message = RequestMessage( self.id, @@ -112,9 +136,16 @@ async def signin(self, vars: dict) -> dict: response = await self._send(message, "signing in") self.check_response_for_result(response, "signing in") self.token = response["result"] - package = dict() - package["token"] = self.token - return package + return response["result"] + + async def info(self) -> dict: + message = RequestMessage( + self.id, + RequestMethod.INFO + ) + response = await self._send(message, "getting database information") + self.check_response_for_result(response, "getting database information") + return response["result"] async def use(self, namespace: str, database: str) -> None: message = RequestMessage( @@ -187,15 +218,6 @@ async def delete( self.check_response_for_result(response, "delete") return response["result"] - async def info(self) -> dict: - message = RequestMessage( - self.id, - RequestMethod.INFO - ) - response = await self._send(message, "getting database information") - self.check_response_for_result(response, "getting database information") - return response["result"] - async def insert( self, table: Union[str, Table], data: Union[List[dict], dict] ) -> Union[List[dict], dict]: @@ -222,11 +244,6 @@ async def insert_relation( self.check_response_for_result(response, "insert_relation") return response["result"] - async def invalidate(self) -> None: - message = RequestMessage(self.id, RequestMethod.INVALIDATE) - await self._send(message, "invalidating") - self.token = None - async def let(self, key: str, value: Any) -> None: self.vars[key] = value @@ -306,17 +323,6 @@ async def upsert( self.check_response_for_result(response, "upsert") return response["result"] - async def signup(self, vars: Dict) -> str: - message = RequestMessage( - self.id, - RequestMethod.SIGN_UP, - data=vars - ) - response = await self._send(message, "signup") - self.check_response_for_result(response, "signup") - self.token = response["result"] - return response["result"] - async def __aenter__(self) -> "AsyncHttpSurrealConnection": """ Asynchronous context manager entry. diff --git a/src/surrealdb/connections/async_template.py b/src/surrealdb/connections/async_template.py index af5e7246..2aea2e30 100644 --- a/src/surrealdb/connections/async_template.py +++ b/src/surrealdb/connections/async_template.py @@ -40,6 +40,25 @@ async def use(self, namespace: str, database: str) -> None: """ raise NotImplementedError(f"query not implemented for: {self}") + async def authenticate(self, token: str) -> None: + """Authenticate the current connection with a JWT token. + + Args: + token: The JWT authentication token. + + Example: + await db.authenticate('insert token here') + """ + raise NotImplementedError(f"authenticate not implemented for: {self}") + + async def invalidate(self) -> None: + """Invalidate the authentication for the current connection. + + Example: + await db.invalidate() + """ + raise NotImplementedError(f"invalidate not implemented for: {self}") + async def signup(self, vars: Dict) -> str: """Sign this connection up to a specific authentication scope. [See the docs](https://surrealdb.com/docs/sdk/python/methods/signup) @@ -77,25 +96,6 @@ async def signin(self, vars: Dict) -> str: """ raise NotImplementedError(f"query not implemented for: {self}") - async def invalidate(self) -> None: - """Invalidate the authentication for the current connection. - - Example: - await db.invalidate() - """ - raise NotImplementedError(f"invalidate not implemented for: {self}") - - async def authenticate(self, token: str) -> None: - """Authenticate the current connection with a JWT token. - - Args: - token: The JWT authentication token. - - Example: - await db.authenticate('insert token here') - """ - raise NotImplementedError(f"authenticate not implemented for: {self}") - async def let(self, key: str, value: Any) -> None: """Assign a value as a variable for this connection. diff --git a/src/surrealdb/connections/async_ws.py b/src/surrealdb/connections/async_ws.py index ca1b84f1..16427b9d 100644 --- a/src/surrealdb/connections/async_ws.py +++ b/src/surrealdb/connections/async_ws.py @@ -80,7 +80,28 @@ async def connect(self, url: Optional[str] = None, max_size: Optional[int] = Non subprotocols=[websockets.Subprotocol("cbor")] ) - # async def signup(self, vars: Dict[str, Any]) -> str: + async def authenticate(self, token: str) -> dict: + message = RequestMessage( + self.id, + RequestMethod.AUTHENTICATE, + token=token + ) + return await self._send(message, "authenticating") + + async def invalidate(self) -> None: + message = RequestMessage(self.id, RequestMethod.INVALIDATE) + await self._send(message, "invalidating") + self.token = None + + async def signup(self, vars: Dict) -> str: + message = RequestMessage( + self.id, + RequestMethod.SIGN_UP, + data=vars + ) + response = await self._send(message, "signup") + self.check_response_for_result(response, "signup") + return response["result"] async def signin(self, vars: Dict[str, Any]) -> str: message = RequestMessage( @@ -96,9 +117,25 @@ async def signin(self, vars: Dict[str, Any]) -> str: response = await self._send(message, "signing in") self.check_response_for_result(response, "signing in") self.token = response["result"] - if response.get("id") is None: - raise Exception(f"no id signing in: {response}") - self.id = response["id"] + return response["result"] + + async def info(self) -> Optional[dict]: + message = RequestMessage( + self.id, + RequestMethod.INFO + ) + outcome = await self._send(message, "getting database information") + self.check_response_for_result(outcome, "getting database information") + return outcome["result"] + + async def use(self, namespace: str, database: str) -> None: + message = RequestMessage( + self.id, + RequestMethod.USE, + namespace=namespace, + database=database, + ) + await self._send(message, "use") async def query(self, query: str, params: Optional[dict] = None) -> dict: if params is None: @@ -125,24 +162,6 @@ async def query_raw(self, query: str, params: Optional[dict] = None) -> dict: response = await self._send(message, "query", bypass=True) return response - async def use(self, namespace: str, database: str) -> None: - message = RequestMessage( - self.id, - RequestMethod.USE, - namespace=namespace, - database=database, - ) - await self._send(message, "use") - - async def info(self) -> Optional[dict]: - message = RequestMessage( - self.id, - RequestMethod.INFO - ) - outcome = await self._send(message, "getting database information") - self.check_response_for_result(outcome, "getting database information") - return outcome["result"] - async def version(self) -> str: message = RequestMessage( self.id, @@ -152,18 +171,6 @@ async def version(self) -> str: self.check_response_for_result(response, "getting database version") return response["result"] - async def authenticate(self, token: str) -> dict: - message = RequestMessage( - self.id, - RequestMethod.AUTHENTICATE, - token=token - ) - return await self._send(message, "authenticating") - - async def invalidate(self) -> None: - message = RequestMessage(self.id, RequestMethod.INVALIDATE) - await self._send(message, "invalidating") - async def let(self, key: str, value: Any) -> None: message = RequestMessage( self.id, @@ -331,16 +338,6 @@ async def kill(self, query_uuid: Union[str, UUID]) -> None: ) await self._send(message, "kill") - async def signup(self, vars: Dict) -> str: - message = RequestMessage( - self.id, - RequestMethod.SIGN_UP, - data=vars - ) - response = await self._send(message, "signup") - self.check_response_for_result(response, "signup") - return response["result"] - async def upsert( self, thing: Union[str, RecordID, Table], data: Optional[Dict] = None ) -> Union[List[dict], dict]: diff --git a/src/surrealdb/connections/blocking_http.py b/src/surrealdb/connections/blocking_http.py index 89ebd6cd..078e93f2 100644 --- a/src/surrealdb/connections/blocking_http.py +++ b/src/surrealdb/connections/blocking_http.py @@ -51,6 +51,29 @@ def _send(self, message: RequestMessage, operation: str, bypass: bool = False) - def set_token(self, token: str) -> None: self.token = token + def authenticate(self, token: str) -> dict: + message = RequestMessage( + self.id, + RequestMethod.AUTHENTICATE, + token=token + ) + return self._send(message, "authenticating") + + def invalidate(self) -> None: + message = RequestMessage(self.id, RequestMethod.INVALIDATE) + self._send(message, "invalidating") + self.token = None + + def signup(self, vars: Dict) -> str: + message = RequestMessage( + self.id, + RequestMethod.SIGN_UP, + data=vars + ) + response = await self._send(message, "signup") + self.check_response_for_result(response, "signup") + return response["result"] + def signin(self, vars: dict) -> dict: message = RequestMessage( self.id, @@ -65,9 +88,16 @@ def signin(self, vars: dict) -> dict: response = self._send(message, "signing in") self.check_response_for_result(response, "signing in") self.token = response["result"] - package = dict() - package["token"] = self.token - return package + return response["result"] + + def info(self): + message = RequestMessage( + self.id, + RequestMethod.INFO + ) + response = self._send(message, "getting database information") + self.check_response_for_result(response, "getting database information") + return response["result"] def use(self, namespace: str, database: str) -> None: message = RequestMessage( @@ -140,15 +170,6 @@ def delete( self.check_response_for_result(response, "delete") return response["result"] - def info(self): - message = RequestMessage( - self.id, - RequestMethod.INFO - ) - response = self._send(message, "getting database information") - self.check_response_for_result(response, "getting database information") - return response["result"] - def insert( self, table: Union[str, Table], data: Union[List[dict], dict] ) -> Union[List[dict], dict]: @@ -175,11 +196,6 @@ def insert_relation( self.check_response_for_result(response, "insert_relation") return response["result"] - def invalidate(self) -> None: - message = RequestMessage(self.id, RequestMethod.INVALIDATE) - self._send(message, "invalidating") - self.token = None - def let(self, key: str, value: Any) -> None: self.vars[key] = value diff --git a/src/surrealdb/connections/blocking_ws.py b/src/surrealdb/connections/blocking_ws.py index fc15580b..72fce464 100644 --- a/src/surrealdb/connections/blocking_ws.py +++ b/src/surrealdb/connections/blocking_ws.py @@ -65,6 +65,29 @@ def _send(self, message: RequestMessage, process: str, bypass: bool = False) -> self.check_response_for_error(response, process) return response + def authenticate(self, token: str) -> dict: + message = RequestMessage( + self.id, + RequestMethod.AUTHENTICATE, + token=token + ) + return self._send(message, "authenticating") + + def invalidate(self) -> None: + message = RequestMessage(self.id, RequestMethod.INVALIDATE) + self._send(message, "invalidating") + self.token = None + + def signup(self, vars: Dict) -> str: + message = RequestMessage( + self.id, + RequestMethod.SIGN_UP, + data=vars + ) + response = await self._send(message, "signup") + self.check_response_for_result(response, "signup") + return response["result"] + def signin(self, vars: Dict[str, Any]) -> str: message = RequestMessage( self.id, @@ -79,9 +102,25 @@ def signin(self, vars: Dict[str, Any]) -> str: response = self._send(message, "signing in") self.check_response_for_result(response, "signing in") self.token = response["result"] - if response.get("id") is None: - raise Exception(f"No ID signing in: {response}") - self.id = response["id"] + return response["result"] + + def info(self) -> dict: + message = RequestMessage( + self.id, + RequestMethod.INFO + ) + response = self._send(message, "getting database information") + self.check_response_for_result(response, "getting database information") + return response["result"] + + def use(self, namespace: str, database: str) -> None: + message = RequestMessage( + self.id, + RequestMethod.USE, + namespace=namespace, + database=database, + ) + self._send(message, "use") def query(self, query: str, params: Optional[dict] = None) -> dict: if params is None: @@ -108,24 +147,6 @@ def query_raw(self, query: str, params: Optional[dict] = None) -> dict: response = self._send(message, "query", bypass=True) return response - def use(self, namespace: str, database: str) -> None: - message = RequestMessage( - self.id, - RequestMethod.USE, - namespace=namespace, - database=database, - ) - self._send(message, "use") - - def info(self) -> dict: - message = RequestMessage( - self.id, - RequestMethod.INFO - ) - response = self._send(message, "getting database information") - self.check_response_for_result(response, "getting database information") - return response["result"] - def version(self) -> str: message = RequestMessage( self.id, @@ -135,18 +156,6 @@ def version(self) -> str: self.check_response_for_result(response, "getting database version") return response["result"] - def authenticate(self, token: str) -> dict: - message = RequestMessage( - self.id, - RequestMethod.AUTHENTICATE, - token=token - ) - return self._send(message, "authenticating") - - def invalidate(self) -> None: - message = RequestMessage(self.id, RequestMethod.INVALIDATE) - self._send(message, "invalidating") - def let(self, key: str, value: Any) -> None: message = RequestMessage( self.id, diff --git a/src/surrealdb/connections/sync_template.py b/src/surrealdb/connections/sync_template.py index 0decebb5..15863716 100644 --- a/src/surrealdb/connections/sync_template.py +++ b/src/surrealdb/connections/sync_template.py @@ -46,6 +46,25 @@ def use(self, namespace: str, database: str) -> None: """ raise NotImplementedError(f"use not implemented for: {self}") + def authenticate(self, token: str) -> None: + """Authenticate the current connection with a JWT token. + + Args: + token: The JWT authentication token. + + Example: + db.authenticate('insert token here') + """ + raise NotImplementedError(f"authenticate not implemented for: {self}") + + def invalidate(self) -> None: + """Invalidate the authentication for the current connection. + + Example: + db.invalidate() + """ + raise NotImplementedError(f"invalidate not implemented for: {self}") + def signup(self, vars: Dict) -> str: """Sign this connection up to a specific authentication scope. [See the docs](https://surrealdb.com/docs/sdk/python/methods/signup) @@ -83,25 +102,6 @@ def signin(self, vars: Dict) -> str: """ raise NotImplementedError(f"signin not implemented for: {self}") - def invalidate(self) -> None: - """Invalidate the authentication for the current connection. - - Example: - db.invalidate() - """ - raise NotImplementedError(f"invalidate not implemented for: {self}") - - def authenticate(self, token: str) -> None: - """Authenticate the current connection with a JWT token. - - Args: - token: The JWT authentication token. - - Example: - db.authenticate('insert token here') - """ - raise NotImplementedError(f"authenticate not implemented for: {self}") - def let(self, key: str, value: Any) -> None: """Assign a value as a variable for this connection. diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..9464070e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,5 @@ +import sys +import os + +# Add the src directory to the Python path +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))) \ No newline at end of file diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py index e69de29b..7c1c8950 100644 --- a/tests/unit_tests/__init__.py +++ b/tests/unit_tests/__init__.py @@ -0,0 +1,5 @@ +import sys +import os + +# Add the src directory to the Python path +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) \ No newline at end of file diff --git a/tests/unit_tests/connections/signin/test_async_http.py b/tests/unit_tests/connections/signin/test_async_http.py index fb8c015c..a07c9764 100644 --- a/tests/unit_tests/connections/signin/test_async_http.py +++ b/tests/unit_tests/connections/signin/test_async_http.py @@ -43,8 +43,8 @@ async def asyncSetUp(self): async def test_signin_root(self): connection = AsyncHttpSurrealConnection(self.url) - outcome = await connection.signin(self.vars_params) - self.assertIn("token", outcome) # Check that the response contains a token + response = await connection.signin(self.vars_params) + self.assertIn("token", response) async def test_signin_namespace(self): connection = AsyncHttpSurrealConnection(self.url) @@ -53,7 +53,8 @@ async def test_signin_namespace(self): "username": "test", "password": "test", } - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") @@ -65,7 +66,8 @@ async def test_signin_database(self): "username": "test", "password": "test", } - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") @@ -81,7 +83,8 @@ async def test_signin_record(self): } connection = AsyncHttpSurrealConnection(self.url) # for below if client is HTTP then persist and attach to all headers - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signin/test_async_ws.py b/tests/unit_tests/connections/signin/test_async_ws.py index d8e0ba8c..5a9bb519 100644 --- a/tests/unit_tests/connections/signin/test_async_ws.py +++ b/tests/unit_tests/connections/signin/test_async_ws.py @@ -43,7 +43,8 @@ async def asyncSetUp(self): async def test_signin_root(self): connection = AsyncWsSurrealConnection(self.url) - _ = await connection.signin(self.vars_params) + response = await connection.signin(self.vars_params) + self.assertIn("token", response) await self.connection.socket.close() await connection.socket.close() @@ -54,7 +55,8 @@ async def test_signin_namespace(self): "username": "test", "password": "test", } - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") await self.connection.socket.close() @@ -68,7 +70,8 @@ async def test_signin_database(self): "username": "test", "password": "test", } - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") await self.connection.socket.close() @@ -86,7 +89,8 @@ async def test_signin_record(self): } connection = AsyncWsSurrealConnection(self.url) # for below if client is HTTP then persist and attach to all headers - _ = await connection.signin(vars) + response = await connection.signin(vars) + self.assertIn("token", response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_async_http.py b/tests/unit_tests/connections/signup/test_async_http.py index 7d2ff3e4..b526e98c 100644 --- a/tests/unit_tests/connections/signup/test_async_http.py +++ b/tests/unit_tests/connections/signup/test_async_http.py @@ -48,8 +48,8 @@ async def test_signup(self): } } connection = AsyncHttpSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = await connection.signup(vars) + response = await connection.signup(vars) + self.assertIn("token", response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_async_ws.py b/tests/unit_tests/connections/signup/test_async_ws.py index e9ad96a1..3eab753c 100644 --- a/tests/unit_tests/connections/signup/test_async_ws.py +++ b/tests/unit_tests/connections/signup/test_async_ws.py @@ -48,8 +48,8 @@ async def test_signup(self): } } connection = AsyncWsSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = await connection.signup(vars) + response = await connection.signup(vars) + self.assertIn("token", response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") From a6f8f7a782339bd4424b15aacb79a37111144117 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:05:03 +0000 Subject: [PATCH 2/7] Remove test directory import fix --- tests/__init__.py | 7 +++---- tests/unit_tests/__init__.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 9464070e..e92300d4 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,4 @@ -import sys -import os +# import sys +# import os -# Add the src directory to the Python path -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))) \ No newline at end of file +# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))) \ No newline at end of file diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py index 7c1c8950..8cb03c75 100644 --- a/tests/unit_tests/__init__.py +++ b/tests/unit_tests/__init__.py @@ -1,5 +1,4 @@ -import sys -import os +# import sys +# import os -# Add the src directory to the Python path -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) \ No newline at end of file +# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) \ No newline at end of file From 2102c158bdd4bed4b1b98b71f95730cdfbed632d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:08:02 +0000 Subject: [PATCH 3/7] Fix indentation --- src/surrealdb/connections/async_template.py | 2 +- src/surrealdb/connections/sync_template.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/surrealdb/connections/async_template.py b/src/surrealdb/connections/async_template.py index 2aea2e30..ec8ae0ee 100644 --- a/src/surrealdb/connections/async_template.py +++ b/src/surrealdb/connections/async_template.py @@ -51,7 +51,7 @@ async def authenticate(self, token: str) -> None: """ raise NotImplementedError(f"authenticate not implemented for: {self}") - async def invalidate(self) -> None: + async def invalidate(self) -> None: """Invalidate the authentication for the current connection. Example: diff --git a/src/surrealdb/connections/sync_template.py b/src/surrealdb/connections/sync_template.py index 15863716..7b5ba1c9 100644 --- a/src/surrealdb/connections/sync_template.py +++ b/src/surrealdb/connections/sync_template.py @@ -57,7 +57,7 @@ def authenticate(self, token: str) -> None: """ raise NotImplementedError(f"authenticate not implemented for: {self}") - def invalidate(self) -> None: + def invalidate(self) -> None: """Invalidate the authentication for the current connection. Example: From 66ec338f4fc8708f7cf98417ae6c36e64210057e Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:09:58 +0000 Subject: [PATCH 4/7] Remove `await` from blocking client --- src/surrealdb/connections/blocking_http.py | 2 +- src/surrealdb/connections/blocking_ws.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/surrealdb/connections/blocking_http.py b/src/surrealdb/connections/blocking_http.py index 078e93f2..e0872246 100644 --- a/src/surrealdb/connections/blocking_http.py +++ b/src/surrealdb/connections/blocking_http.py @@ -70,7 +70,7 @@ def signup(self, vars: Dict) -> str: RequestMethod.SIGN_UP, data=vars ) - response = await self._send(message, "signup") + response = self._send(message, "signup") self.check_response_for_result(response, "signup") return response["result"] diff --git a/src/surrealdb/connections/blocking_ws.py b/src/surrealdb/connections/blocking_ws.py index 72fce464..f9a1d824 100644 --- a/src/surrealdb/connections/blocking_ws.py +++ b/src/surrealdb/connections/blocking_ws.py @@ -84,7 +84,7 @@ def signup(self, vars: Dict) -> str: RequestMethod.SIGN_UP, data=vars ) - response = await self._send(message, "signup") + response = self._send(message, "signup") self.check_response_for_result(response, "signup") return response["result"] From 9069b7f655b3755a1f962660ee4a5f5f1b2eaaad Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:12:00 +0000 Subject: [PATCH 5/7] Fix indentation --- src/surrealdb/connections/sync_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/surrealdb/connections/sync_template.py b/src/surrealdb/connections/sync_template.py index 7b5ba1c9..10db2b96 100644 --- a/src/surrealdb/connections/sync_template.py +++ b/src/surrealdb/connections/sync_template.py @@ -46,7 +46,7 @@ def use(self, namespace: str, database: str) -> None: """ raise NotImplementedError(f"use not implemented for: {self}") - def authenticate(self, token: str) -> None: + def authenticate(self, token: str) -> None: """Authenticate the current connection with a JWT token. Args: From d81fff40f799fc4295f4b72fcd71ac78e1000ef2 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:49:02 +0000 Subject: [PATCH 6/7] Fix tests --- .../unit_tests/connections/signin/test_async_http.py | 11 ++++++----- tests/unit_tests/connections/signin/test_async_ws.py | 11 ++++++----- .../unit_tests/connections/signup/test_async_http.py | 2 +- tests/unit_tests/connections/signup/test_async_ws.py | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/unit_tests/connections/signin/test_async_http.py b/tests/unit_tests/connections/signin/test_async_http.py index a07c9764..c3741c2b 100644 --- a/tests/unit_tests/connections/signin/test_async_http.py +++ b/tests/unit_tests/connections/signin/test_async_http.py @@ -44,7 +44,9 @@ async def asyncSetUp(self): async def test_signin_root(self): connection = AsyncHttpSurrealConnection(self.url) response = await connection.signin(self.vars_params) - self.assertIn("token", response) + self.assertIsNotNone(response) + _ = await self.connection.query("DELETE user;") + _ = await self.connection.query("REMOVE TABLE user;") async def test_signin_namespace(self): connection = AsyncHttpSurrealConnection(self.url) @@ -54,7 +56,7 @@ async def test_signin_namespace(self): "password": "test", } response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") @@ -67,7 +69,7 @@ async def test_signin_database(self): "password": "test", } response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") @@ -82,9 +84,8 @@ async def test_signin_record(self): } } connection = AsyncHttpSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signin/test_async_ws.py b/tests/unit_tests/connections/signin/test_async_ws.py index 5a9bb519..23245bdc 100644 --- a/tests/unit_tests/connections/signin/test_async_ws.py +++ b/tests/unit_tests/connections/signin/test_async_ws.py @@ -44,7 +44,9 @@ async def asyncSetUp(self): async def test_signin_root(self): connection = AsyncWsSurrealConnection(self.url) response = await connection.signin(self.vars_params) - self.assertIn("token", response) + self.assertIsNotNone(response) + _ = await self.connection.query("DELETE user;") + _ = await self.connection.query("REMOVE TABLE user;") await self.connection.socket.close() await connection.socket.close() @@ -56,7 +58,7 @@ async def test_signin_namespace(self): "password": "test", } response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") await self.connection.socket.close() @@ -71,7 +73,7 @@ async def test_signin_database(self): "password": "test", } response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) _ = await self.connection.query("DELETE user;") _ = await self.connection.query("REMOVE TABLE user;") await self.connection.socket.close() @@ -88,9 +90,8 @@ async def test_signin_record(self): } } connection = AsyncWsSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers response = await connection.signin(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_async_http.py b/tests/unit_tests/connections/signup/test_async_http.py index b526e98c..81c38e66 100644 --- a/tests/unit_tests/connections/signup/test_async_http.py +++ b/tests/unit_tests/connections/signup/test_async_http.py @@ -49,7 +49,7 @@ async def test_signup(self): } connection = AsyncHttpSurrealConnection(self.url) response = await connection.signup(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_async_ws.py b/tests/unit_tests/connections/signup/test_async_ws.py index 3eab753c..c7c982c4 100644 --- a/tests/unit_tests/connections/signup/test_async_ws.py +++ b/tests/unit_tests/connections/signup/test_async_ws.py @@ -49,7 +49,7 @@ async def test_signup(self): } connection = AsyncWsSurrealConnection(self.url) response = await connection.signup(vars) - self.assertIn("token", response) + self.assertIsNotNone(response) outcome = await connection.info() self.assertEqual(outcome["email"], "test@gmail.com") From 9ee16aa2bdd8b090fe0405212351dacfe01aa012 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 1 Feb 2025 22:53:19 +0000 Subject: [PATCH 7/7] Fix tests --- .github/workflows/unit_tests.yml | 2 +- .../connections/signin/test_blocking_http.py | 16 ++++++++++------ .../connections/signin/test_blocking_ws.py | 13 ++++++++----- .../connections/signup/test_blocking_http.py | 4 ++-- .../connections/signup/test_blocking_ws.py | 4 ++-- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 4cc12314..cf0dfbaa 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -1,4 +1,4 @@ -name: unit-tests +name: Unit tests on: push: diff --git a/tests/unit_tests/connections/signin/test_blocking_http.py b/tests/unit_tests/connections/signin/test_blocking_http.py index 8f832fe6..58d89f41 100644 --- a/tests/unit_tests/connections/signin/test_blocking_http.py +++ b/tests/unit_tests/connections/signin/test_blocking_http.py @@ -43,8 +43,10 @@ def setUp(self): def test_signin_root(self): connection = BlockingHttpSurrealConnection(self.url) - outcome = connection.signin(self.vars_params) - self.assertIn("token", outcome) # Check that the response contains a token + response = connection.signin(self.vars_params) + self.assertIsNotNone(response) + _ = self.connection.query("DELETE user;") + _ = self.connection.query("REMOVE TABLE user;") def test_signin_namespace(self): connection = BlockingHttpSurrealConnection(self.url) @@ -53,7 +55,8 @@ def test_signin_namespace(self): "username": "test", "password": "test", } - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) _ = self.connection.query("DELETE user;") _ = self.connection.query("REMOVE TABLE user;") @@ -65,7 +68,8 @@ def test_signin_database(self): "username": "test", "password": "test", } - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) _ = self.connection.query("DELETE user;") _ = self.connection.query("REMOVE TABLE user;") @@ -80,8 +84,8 @@ def test_signin_record(self): } } connection = BlockingHttpSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) outcome = connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signin/test_blocking_ws.py b/tests/unit_tests/connections/signin/test_blocking_ws.py index bdc01851..c0b571da 100644 --- a/tests/unit_tests/connections/signin/test_blocking_ws.py +++ b/tests/unit_tests/connections/signin/test_blocking_ws.py @@ -43,7 +43,8 @@ def setUp(self): def test_signin_root(self): connection = BlockingWsSurrealConnection(self.url) - _ = connection.signin(self.vars_params) + response = connection.signin(self.vars_params) + self.assertIsNotNone(response) self.connection.socket.close() connection.close() @@ -54,7 +55,8 @@ def test_signin_namespace(self): "username": "test", "password": "test", } - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) _ = self.connection.query("DELETE user;") _ = self.connection.query("REMOVE TABLE user;") self.connection.socket.close() @@ -68,7 +70,8 @@ def test_signin_database(self): "username": "test", "password": "test", } - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) _ = self.connection.query("DELETE user;") _ = self.connection.query("REMOVE TABLE user;") self.connection.socket.close() @@ -85,8 +88,8 @@ def test_signin_record(self): } } connection = BlockingWsSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = connection.signin(vars) + response = connection.signin(vars) + self.assertIsNotNone(response) outcome = connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_blocking_http.py b/tests/unit_tests/connections/signup/test_blocking_http.py index 148a7ea6..0a14b4da 100644 --- a/tests/unit_tests/connections/signup/test_blocking_http.py +++ b/tests/unit_tests/connections/signup/test_blocking_http.py @@ -48,8 +48,8 @@ def test_signup(self): } } connection = BlockingHttpSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = connection.signup(vars) + response = connection.signup(vars) + self.assertIsNotNone(response) outcome = connection.info() self.assertEqual(outcome["email"], "test@gmail.com") diff --git a/tests/unit_tests/connections/signup/test_blocking_ws.py b/tests/unit_tests/connections/signup/test_blocking_ws.py index cdf01eb6..32d8545c 100644 --- a/tests/unit_tests/connections/signup/test_blocking_ws.py +++ b/tests/unit_tests/connections/signup/test_blocking_ws.py @@ -48,8 +48,8 @@ def test_signup(self): } } connection = BlockingWsSurrealConnection(self.url) - # for below if client is HTTP then persist and attach to all headers - _ = connection.signup(vars) + response = connection.signup(vars) + self.assertIsNotNone(response) outcome = connection.info() self.assertEqual(outcome["email"], "test@gmail.com")