From 90a209a2d7d05ddcba879775f07a3cc351193067 Mon Sep 17 00:00:00 2001 From: Remade Date: Thu, 14 Nov 2024 10:41:01 +0100 Subject: [PATCH] Updated tests --- surrealdb/VERSION.txt | 2 +- surrealdb/__init__.py | 27 +++++++++++++++++++-- surrealdb/async_surrealdb.py | 16 +++++++++++++ surrealdb/connection.py | 26 ++++++++++++-------- surrealdb/connection_factory.py | 9 +++++-- surrealdb/connection_http.py | 1 + surrealdb/connection_ws.py | 8 ++++--- surrealdb/constants.py | 4 ++-- surrealdb/data/models.py | 29 +++++++++++++++++++++-- surrealdb/data/types/geometry.py | 27 +++++++++++++++++++-- surrealdb/data/types/range.py | 2 ++ surrealdb/data/types/record_id.py | 14 ++++++++++- surrealdb/data/types/table.py | 6 +++++ surrealdb/errors.py | 4 ++-- surrealdb/surrealdb.py | 20 ++++++++++++++++ tests/integration/async/test_create.py | 16 ++++++------- tests/integration/async/test_merge.py | 6 ++--- tests/integration/async/test_set.py | 6 ++--- tests/integration/async/test_update.py | 8 +++---- tests/integration/blocking/test_create.py | 8 +++---- tests/integration/blocking/test_merge.py | 6 ++--- tests/integration/blocking/test_set.py | 6 ++--- tests/integration/blocking/test_update.py | 8 +++---- 23 files changed, 200 insertions(+), 59 deletions(-) diff --git a/surrealdb/VERSION.txt b/surrealdb/VERSION.txt index 4742ba03..b217dcd1 100644 --- a/surrealdb/VERSION.txt +++ b/surrealdb/VERSION.txt @@ -1 +1 @@ -VERSION='0.0.2' \ No newline at end of file +VERSION='0.1.0' \ No newline at end of file diff --git a/surrealdb/__init__.py b/surrealdb/__init__.py index 53682e9d..c6f27780 100644 --- a/surrealdb/__init__.py +++ b/surrealdb/__init__.py @@ -1,5 +1,28 @@ from surrealdb.async_surrealdb import AsyncSurrealDB from surrealdb.surrealdb import SurrealDB -from surrealdb.errors import SurrealDbError, SurrealDbConnectionError +from surrealdb.errors import SurrealDbError, SurrealDbConnectionError, SurrealDbDecodeError, SurrealDbEncodeError -__all__ = ("SurrealDB", "AsyncSurrealDB", "SurrealDbError", "SurrealDbConnectionError") +from surrealdb.data.models import Patch, QueryResponse, GraphQLOptions +from surrealdb.data.types.duration import Duration +from surrealdb.data.types.future import Future +from surrealdb.data.types.geometry import Geometry, GeometryPoint, GeometryLine, GeometryPolygon, GeometryMultiPoint, \ + GeometryMultiLine, GeometryMultiPolygon, GeometryCollection +from surrealdb.data.types.range import Bound, BoundIncluded, BoundExcluded, Range +from surrealdb.data.types.record_id import RecordID +from surrealdb.data.types.table import Table + +__all__ = ( + "SurrealDB", "AsyncSurrealDB", + "SurrealDbError", "SurrealDbConnectionError", "SurrealDbDecodeError", "SurrealDbEncodeError", + + "Patch", "QueryResponse", "GraphQLOptions", + + "Duration", + "Future", + "Geometry", "GeometryPoint", "GeometryLine", "GeometryPolygon", "GeometryMultiPoint", + "GeometryMultiLine", "GeometryMultiPolygon", "GeometryCollection", + "Bound", "BoundIncluded", "BoundExcluded", "Range", + "RecordID", + "Table" + +) diff --git a/surrealdb/async_surrealdb.py b/surrealdb/async_surrealdb.py index b3f0e9bf..9b851835 100644 --- a/surrealdb/async_surrealdb.py +++ b/surrealdb/async_surrealdb.py @@ -233,4 +233,20 @@ async def merge(self, thing: Union[str, RecordID, Table], data: dict) -> Union[L """ return await self.__connection.send('update', thing, data) + async def live(self, thing: Union[str, Table], diff: Optional[bool] = False) -> Union[List[dict], dict]: + """ + Live initiates a live query for a specified table name. + + :param thing: The Table tquery. + :param diff: If set to true, live notifications will contain an array of JSON Patches instead of the entire record + :return: the live query uuid + """ + return await self.__connection.send('live', thing, diff) + async def kill(self, live_query_id: str) -> None: + """ + This kills an active live query + + :param live_query_id: The Table or Record ID to merge into. + """ + return await self.__connection.send('kill', live_query_id) diff --git a/surrealdb/connection.py b/surrealdb/connection.py index 6c43f82f..cd899a8b 100644 --- a/surrealdb/connection.py +++ b/surrealdb/connection.py @@ -1,7 +1,8 @@ import secrets import string -from typing import Optional, Tuple +import logging +from typing import Optional, Tuple from surrealdb.constants import REQUEST_ID_LENGTH from surrealdb.data.cbor import encode, decode from surrealdb.errors import SurrealDbConnectionError @@ -11,13 +12,14 @@ class Connection: def __init__( self, base_url: str, - namespace: Optional[str] = None, - database: Optional[str] = None + logger: logging.Logger, ): self._auth_token = None + self._namespace = None + self._database = None + self._base_url = base_url - self._namespace = namespace - self._database = database + self._logger = logger async def use(self, namespace: str, database: str) -> None: pass @@ -38,12 +40,13 @@ async def unset(self, key: str): pass async def send(self, method: str, *params): - # print("Request: ", method, params) + req_id = request_id(REQUEST_ID_LENGTH) request_data = { - 'id': request_id(REQUEST_ID_LENGTH), + 'id': req_id, 'method': method, 'params': params } + self._logger.debug(f"Request {req_id}:", request_data) try: successful, response_data = await self._make_request(encode(request_data)) @@ -55,11 +58,14 @@ async def send(self, method: str, *params): error_msg = response.get("error").get("message") raise SurrealDbConnectionError(error_msg) - # print("Response: ", response) - # print("Result: ", response_data.hex()) - # print("------------------------------------------------------------------------------------------------------------------------") + self._logger.debug(f"Response {req_id}:", response_data.hex()) + self._logger.debug(f"Decoded Result {req_id}:", response) + self._logger.debug("----------------------------------------------------------------------------------") + return response.get("result") except Exception as e: + self._logger.debug(f"Error {req_id}:", e) + self._logger.debug("----------------------------------------------------------------------------------") raise e def set_token(self, token: Optional[str] = None) -> None: diff --git a/surrealdb/connection_factory.py b/surrealdb/connection_factory.py index c45aacd9..94eaa087 100644 --- a/surrealdb/connection_factory.py +++ b/surrealdb/connection_factory.py @@ -1,3 +1,4 @@ +import logging from urllib.parse import urlparse from surrealdb.connection import Connection @@ -8,14 +9,18 @@ def create_connection_factory(url: str) -> Connection: + logger: logging.Logger = logging.getLogger(__name__) + parsed_url = urlparse(url) if parsed_url.scheme not in ALLOWED_CONNECTION_SCHEMES: raise SurrealDbConnectionError("invalid scheme. allowed schemes are", "".join(ALLOWED_CONNECTION_SCHEMES)) if parsed_url.scheme in WS_CONNECTION_SCHEMES: - return WebsocketConnection(url) + logger.debug("websocket url detected, creating a websocket connection") + return WebsocketConnection(url, logger) if parsed_url.scheme in HTTP_CONNECTION_SCHEMES: - return HTTPConnection(url) + logger.debug("http url detected, creating a http connection") + return HTTPConnection(url, logger) raise Exception('no connection type available') diff --git a/surrealdb/connection_http.py b/surrealdb/connection_http.py index a0575411..e1cac7fd 100644 --- a/surrealdb/connection_http.py +++ b/surrealdb/connection_http.py @@ -18,6 +18,7 @@ async def connect(self) -> None: response = requests.get(self._base_url + '/health') if response.status_code != 200: + self._logger.debug("HTTP health check successful") raise SurrealDbConnectionError('connection failed. check server is up and base url is correct') async def _make_request(self, request_payload: bytes) -> Tuple[bool, bytes]: diff --git a/surrealdb/connection_ws.py b/surrealdb/connection_ws.py index 4d2fb5ef..a90c7459 100644 --- a/surrealdb/connection_ws.py +++ b/surrealdb/connection_ws.py @@ -1,13 +1,15 @@ -from typing import Optional, Tuple +import logging +from typing import Tuple from websockets import Subprotocol, ConnectionClosed + from surrealdb.connection import Connection from surrealdb.errors import SurrealDbConnectionError from websockets.asyncio.client import connect class WebsocketConnection(Connection): - def __init__(self, base_url: str, namespace: Optional[str] = None, database: Optional[str] = None): - super().__init__(base_url, namespace, database) + def __init__(self, base_url: str, logger: logging.Logger): + super().__init__(base_url, logger) self._ws = None diff --git a/surrealdb/constants.py b/surrealdb/constants.py index c6a0d35a..c59a118d 100644 --- a/surrealdb/constants.py +++ b/surrealdb/constants.py @@ -1,9 +1,9 @@ REQUEST_ID_LENGTH = 10 -AUTH_TOKEN_KEY = "auth_token" - ALLOWED_CONNECTION_SCHEMES = ['http', 'https', 'ws', 'wss'] HTTP_CONNECTION_SCHEMES = ['http', 'https'] WS_CONNECTION_SCHEMES = ['ws', 'wss'] DEFAULT_CONNECTION_URL = "http://127.0.0.1:8000" + +UNSUPPORTED_HTTP_METHODS = ["kill", "live"] diff --git a/surrealdb/data/models.py b/surrealdb/data/models.py index f2cbfc7e..cf70c091 100644 --- a/surrealdb/data/models.py +++ b/surrealdb/data/models.py @@ -1,5 +1,7 @@ -from dataclasses import dataclass -from typing import Any, Dict, List +from dataclasses import dataclass, field +from typing import Any, Dict, List, Union + +from surrealdb import Table, RecordID @dataclass @@ -31,3 +33,26 @@ class QueryResponse: time: str status: str result: List[Dict[str, Any]] + + +@dataclass +class GraphQLOptions: + """ + Represents the options parameter for graphql method. + + Attributes: + pretty: (optional, default false): A boolean indicating whether the output should be pretty-printed. + format: (optional, default "json"): The response format. Currently, only "json" is supported. + """ + + pretty: bool = field(default=False) + format: str = field(default="json") + + +def table_or_record_id(resource_str: str) -> Union[Table, RecordID]: + table, record_id = resource_str.split(":") if ":" in resource_str else (resource_str, None) + if record_id is not None: + return RecordID(table, record_id) + + return Table(table) + diff --git a/surrealdb/data/types/geometry.py b/surrealdb/data/types/geometry.py index c09c6c67..4c071832 100644 --- a/surrealdb/data/types/geometry.py +++ b/surrealdb/data/types/geometry.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import List, Any, Tuple +from typing import List, Tuple class Geometry: @@ -17,7 +17,7 @@ class GeometryPoint(Geometry): latitude: float def __repr__(self): - return 'GeometryPoint(longitude={self.longitude}, latitude={self.latitude})'.format(self=self) + return f'{self.__class__.__name__}(longitude={self.longitude}, latitude={self.latitude})'.format(self=self) def get_coordinates(self) -> Tuple[float, float]: return self.longitude, self.latitude @@ -27,6 +27,7 @@ def parse_coordinates(coordinates): return GeometryPoint(coordinates[0], coordinates[1]) +@dataclass class GeometryLine(Geometry): def __init__(self, point1: GeometryPoint, point2: GeometryPoint, *other_points: GeometryPoint): @@ -35,11 +36,15 @@ def __init__(self, point1: GeometryPoint, point2: GeometryPoint, *other_points: def get_coordinates(self) -> List[Tuple[float, float]]: return [point.get_coordinates() for point in self.geometry_points] + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometry_points)})' + @staticmethod def parse_coordinates(coordinates): return GeometryLine(*[GeometryPoint.parse_coordinates(point) for point in coordinates]) +@dataclass class GeometryPolygon(Geometry): def __init__(self, line1, line2, *other_lines: GeometryLine): self.geometry_lines = [line1, line2] + list(other_lines) @@ -47,11 +52,15 @@ def __init__(self, line1, line2, *other_lines: GeometryLine): def get_coordinates(self) -> List[List[Tuple[float, float]]]: return [line.get_coordinates() for line in self.geometry_lines] + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometry_lines)})' + @staticmethod def parse_coordinates(coordinates): return GeometryPolygon(*[GeometryLine.parse_coordinates(line) for line in coordinates]) +@dataclass class GeometryMultiPoint(Geometry): def __init__(self, *geometry_points: GeometryPoint): self.geometry_points = geometry_points @@ -59,11 +68,15 @@ def __init__(self, *geometry_points: GeometryPoint): def get_coordinates(self) -> List[Tuple[float, float]]: return [point.get_coordinates() for point in self.geometry_points] + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometry_points)})' + @staticmethod def parse_coordinates(coordinates): return GeometryMultiPoint(*[GeometryPoint.parse_coordinates(point) for point in coordinates]) +@dataclass class GeometryMultiLine(Geometry): def __init__(self, *geometry_lines: GeometryLine): self.geometry_lines = geometry_lines @@ -71,11 +84,15 @@ def __init__(self, *geometry_lines: GeometryLine): def get_coordinates(self) -> List[List[Tuple[float, float]]]: return [line.get_coordinates() for line in self.geometry_lines] + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometry_lines)})' + @staticmethod def parse_coordinates(coordinates): return GeometryMultiLine(*[GeometryLine.parse_coordinates(line) for line in coordinates]) +@dataclass class GeometryMultiPolygon(Geometry): def __init__(self, *geometry_polygons: GeometryPolygon): self.geometry_polygons = geometry_polygons @@ -83,6 +100,9 @@ def __init__(self, *geometry_polygons: GeometryPolygon): def get_coordinates(self) -> List[List[List[Tuple[float, float]]]]: return [polygon.get_coordinates() for polygon in self.geometry_polygons] + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometry_polygons)})' + @staticmethod def parse_coordinates(coordinates): return GeometryMultiPolygon(*[GeometryPolygon.parse_coordinates(polygon) for polygon in coordinates]) @@ -93,3 +113,6 @@ class GeometryCollection: def __init__(self, *geometries: Geometry): self.geometries = geometries + + def __repr__(self): + return f'{self.__class__.__name__}({", ".join(repr(geo) for geo in self.geometries)})' diff --git a/surrealdb/data/types/range.py b/surrealdb/data/types/range.py index bf98fa62..4b3532fb 100644 --- a/surrealdb/data/types/range.py +++ b/surrealdb/data/types/range.py @@ -6,12 +6,14 @@ def __init__(self): pass +@dataclass class BoundIncluded(Bound): def __init__(self, value): super().__init__() self.value = value +@dataclass class BoundExcluded(Bound): def __init__(self, value): super().__init__() diff --git a/surrealdb/data/types/record_id.py b/surrealdb/data/types/record_id.py index 6d680546..3bc62b93 100644 --- a/surrealdb/data/types/record_id.py +++ b/surrealdb/data/types/record_id.py @@ -1,10 +1,22 @@ +from dataclasses import dataclass + +@dataclass class RecordID: def __init__(self, table_name: str, identifier): self.table_name = table_name self.id = identifier - def __repr__(self) -> str: + def __str__(self) -> str: return f"{self.table_name}:{self.id}" + def __repr__(self) -> str: + return f'{self.__class__.__name__}(table_name={self.table_name}, record_id={self.id})'.format(self=self) + + @staticmethod + def parse(record_str: str): + if ":" not in record_str: + raise ValueError('invalid string provided for parse. the expected string format is "table_name:record_id"') + table, record_id = record_str.split(":") + return RecordID(table, record_id) diff --git a/surrealdb/data/types/table.py b/surrealdb/data/types/table.py index 9a172d20..dd940c3d 100644 --- a/surrealdb/data/types/table.py +++ b/surrealdb/data/types/table.py @@ -1,3 +1,9 @@ class Table: def __init__(self, table_name: str): self.table_name = table_name + + def __str__(self) -> str: + return f"{self.table_name}" + + def __repr__(self) -> str: + return f"{self.table_name}" diff --git a/surrealdb/errors.py b/surrealdb/errors.py index 3c5e1aa8..d5de7cc4 100644 --- a/surrealdb/errors.py +++ b/surrealdb/errors.py @@ -10,11 +10,11 @@ class SurrealDbConnectionError(SurrealDbError): class SurrealDbDecodeError(SurrealDbError): """ - Exceptions from connections + Exceptions from Decoding responses """ class SurrealDbEncodeError(SurrealDbError): """ - Exceptions from connections + Exceptions from encoding requests """ diff --git a/surrealdb/surrealdb.py b/surrealdb/surrealdb.py index 250ade48..294fbff7 100644 --- a/surrealdb/surrealdb.py +++ b/surrealdb/surrealdb.py @@ -272,3 +272,23 @@ def merge(self, thing: Union[str, RecordID, Table], data: dict) -> Union[List[di """ loop_manager = AsyncioRuntime() return loop_manager.loop.run_until_complete(self.__connection.send('update', thing, data)) + + def live(self, thing: Union[str, Table], diff: Optional[bool] = False) -> Union[List[dict], dict]: + """ + Live initiates a live query for a specified table name. + + :param thing: The Table tquery. + :param diff: If set to true, live notifications will contain an array of JSON Patches instead of the entire record + :return: the live query uuid + """ + loop_manager = AsyncioRuntime() + return loop_manager.loop.run_until_complete(self.__connection.send('live', thing, diff)) + + def kill(self, live_query_id: str) -> None: + """ + This kills an active live query + + :param live_query_id: The Table or Record ID to merge into. + """ + loop_manager = AsyncioRuntime() + return loop_manager.loop.run_until_complete(self.__connection.send('kill', live_query_id)) diff --git a/tests/integration/async/test_create.py b/tests/integration/async/test_create.py index 9d11fd01..d681c985 100644 --- a/tests/integration/async/test_create.py +++ b/tests/integration/async/test_create.py @@ -5,7 +5,7 @@ from typing import List from unittest import IsolatedAsyncioTestCase, main -from surrealdb import AsyncSurrealDB +from surrealdb import AsyncSurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -35,8 +35,8 @@ async def test_create_ql(self): outcome = await self.db.query("SELECT * FROM user;") self.assertEqual( [ - {"id": "user:jaime", "name": "Jaime"}, - {"id": "user:tobie", "name": "Tobie"}, + {"id": RecordID('user', 'jaime'), "name": "Jaime"}, + {"id": RecordID('user', 'tobie'), "name": "Tobie"}, ], outcome[0]['result'], ) @@ -46,10 +46,10 @@ async def test_delete_ql(self): await self.test_create_ql() outcome = await self.db.query("DELETE user;") - self.assertEqual([], outcome) + self.assertEqual([], outcome[0]['result']) outcome = await self.db.query("SELECT * FROM user;") - self.assertEqual([], outcome) + self.assertEqual([], outcome[0]['result']) async def test_create_person_with_tags_ql(self): self.queries = ["DELETE person;"] @@ -68,14 +68,14 @@ async def test_create_person_with_tags_ql(self): self.assertEqual( [ { - "id": "person:⟨失败⟩", + "id": RecordID.parse("person:⟨失败⟩"), "pass": "*æ失败", "really": True, "tags": ["python", "documentation"], "user": "me", } ], - outcome, + outcome[0]['result'], ) async def test_create_person_with_tags(self): @@ -92,7 +92,7 @@ async def test_create_person_with_tags(self): ) self.assertEqual( { - "id": "person:⟨失败⟩", + "id": RecordID.parse("person:⟨失败⟩"), "pass": "*æ失败", "really": False, "tags": ["python", "test"], diff --git a/tests/integration/async/test_merge.py b/tests/integration/async/test_merge.py index e9055668..8899feee 100644 --- a/tests/integration/async/test_merge.py +++ b/tests/integration/async/test_merge.py @@ -5,7 +5,7 @@ from typing import List from unittest import IsolatedAsyncioTestCase, main -from surrealdb import AsyncSurrealDB +from surrealdb import AsyncSurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -42,8 +42,8 @@ async def test_merge_person_with_tags(self): outcome = await self.db.query("SELECT * FROM user;") self.assertEqual( [ - {"active": True, "id": "user:jaime", "name": "Jaime"}, - {"active": True, "id": "user:tobie", "name": "Tobie"}, + {"active": True, "id": RecordID.parse("user:jaime"), "name": "Jaime"}, + {"active": True, "id": RecordID.parse("user:tobie"), "name": "Tobie"}, ], outcome[0]['result'] diff --git a/tests/integration/async/test_set.py b/tests/integration/async/test_set.py index 9aa76050..25580e52 100644 --- a/tests/integration/async/test_set.py +++ b/tests/integration/async/test_set.py @@ -5,7 +5,7 @@ from typing import List from unittest import main, IsolatedAsyncioTestCase -from surrealdb import AsyncSurrealDB +from surrealdb import AsyncSurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -34,7 +34,7 @@ async def test_set_ql(self): self.assertEqual( [ { - "id": "person:100", + "id": RecordID.parse("person:100"), "name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go", "JavaScript"], @@ -59,7 +59,7 @@ async def test_set(self): self.assertEqual( [ { - "id": "person:100", + "id": RecordID.parse("person:100"), "name": {"last": "Morgan Hitchcock", "name": "Tobie"}, } ], diff --git a/tests/integration/async/test_update.py b/tests/integration/async/test_update.py index f12d6f6e..87aa0b7a 100644 --- a/tests/integration/async/test_update.py +++ b/tests/integration/async/test_update.py @@ -6,7 +6,7 @@ from typing import List from unittest import IsolatedAsyncioTestCase, main -from surrealdb import AsyncSurrealDB +from surrealdb import AsyncSurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -37,12 +37,12 @@ async def test_update_ql(self): self.assertEqual( [ { - "id": "user:jaime", + "id": RecordID.parse("user:jaime"), "lastname": "Morgan Hitchcock", "name": "Jaime", }, { - "id": "user:tobie", + "id": RecordID.parse("user:tobie"), "lastname": "Morgan Hitchcock", "name": "Tobie", }, @@ -77,7 +77,7 @@ async def test_update_person_with_tags(self): ) self.assertEqual( { - "id": "person:⟨失败⟩", + "id": RecordID.parse("person:⟨失败⟩"), "user": "still me", "pass": "*æ失败", "really": False, diff --git a/tests/integration/blocking/test_create.py b/tests/integration/blocking/test_create.py index f6bf9a69..9c601b8f 100644 --- a/tests/integration/blocking/test_create.py +++ b/tests/integration/blocking/test_create.py @@ -5,7 +5,7 @@ from typing import List from unittest import TestCase, main -from surrealdb import SurrealDB +from surrealdb import SurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -32,8 +32,8 @@ def test_create_ql(self): outcome = self.db.query("SELECT * FROM user;") self.assertEqual( [ - {"id": "user:jaime", "name": "Jaime"}, - {"id": "user:tobie", "name": "Tobie"}, + {"id": RecordID.parse("user:jaime"), "name": "Jaime"}, + {"id": RecordID.parse("user:tobie"), "name": "Tobie"}, ], outcome[0]["result"], ) @@ -86,7 +86,7 @@ def test_create_person_with_tags(self): ) self.assertEqual( { - "id": "person:⟨失败⟩", + "id": RecordID.parse("person:⟨失败⟩"), "pass": "*æ失败", "really": False, "tags": ["python", "test"], diff --git a/tests/integration/blocking/test_merge.py b/tests/integration/blocking/test_merge.py index 1a5bb600..5e968a0d 100644 --- a/tests/integration/blocking/test_merge.py +++ b/tests/integration/blocking/test_merge.py @@ -5,7 +5,7 @@ from typing import List from unittest import TestCase, main -from surrealdb import SurrealDB +from surrealdb import SurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -41,8 +41,8 @@ def test_merge_person_with_tags(self): outcome = self.db.query("SELECT * FROM user;") self.assertEqual( [ - {"active": True, "id": "user:jaime", "name": "Jaime"}, - {"active": True, "id": "user:tobie", "name": "Tobie"}, + {"active": True, "id": RecordID.parse("user:jaime"), "name": "Jaime"}, + {"active": True, "id": RecordID.parse("user:tobie"), "name": "Tobie"}, ], outcome[0]["result"], ) diff --git a/tests/integration/blocking/test_set.py b/tests/integration/blocking/test_set.py index 1d5aa8ae..f121ae2c 100644 --- a/tests/integration/blocking/test_set.py +++ b/tests/integration/blocking/test_set.py @@ -5,7 +5,7 @@ from typing import List from unittest import TestCase, main -from surrealdb import SurrealDB +from surrealdb import SurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -32,7 +32,7 @@ def test_set_ql(self): self.assertEqual( [ { - "id": "person:100", + "id": RecordID.parse("person:100"), "name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go", "JavaScript"], @@ -57,7 +57,7 @@ def test_set(self): self.assertEqual( [ { - "id": "person:100", + "id": RecordID.parse("person:100"), "name": {"last": "Morgan Hitchcock", "name": "Tobie"}, } ], diff --git a/tests/integration/blocking/test_update.py b/tests/integration/blocking/test_update.py index a4c9d6e7..9bbd2dc6 100644 --- a/tests/integration/blocking/test_update.py +++ b/tests/integration/blocking/test_update.py @@ -5,7 +5,7 @@ from typing import List from unittest import TestCase, main -from surrealdb import SurrealDB +from surrealdb import SurrealDB, RecordID from tests.integration.connection_params import TestConnectionParams @@ -34,8 +34,8 @@ def test_update_ql(self): ) self.assertEqual( [ - {"id": "user:jaime", "lastname": "Morgan Hitchcock", "name": "Jaime"}, - {"id": "user:tobie", "lastname": "Morgan Hitchcock", "name": "Tobie"}, + {"id": RecordID.parse("user:jaime"), "lastname": "Morgan Hitchcock", "name": "Jaime"}, + {"id": RecordID.parse("user:tobie"), "lastname": "Morgan Hitchcock", "name": "Tobie"}, ], outcome[0]["result"], ) @@ -65,7 +65,7 @@ def test_update_person_with_tags(self): ) self.assertEqual( { - "id": "person:⟨失败⟩", + "id": RecordID.parse("person:⟨失败⟩"), "user": "still me", "pass": "*æ失败", "really": False,