Skip to content

Commit

Permalink
Improve workflows and tests (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiemh authored Feb 1, 2025
1 parent b8c097f commit 7adba41
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 168 deletions.
46 changes: 0 additions & 46 deletions .github/actions/action.yml

This file was deleted.

33 changes: 17 additions & 16 deletions .github/workflows/stability.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
name: Code Stability
name: Code stability

on:
push:
branches:
- main
pull_request:
branches:
- main
- "*"

concurrency:
group: stability-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
stability:
name: Code Stability
name: Code stability
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build Python
uses: ./.github/actions
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.13

- name: Install tools
run: poetry install --only dev
run: pip install black ruff

- id: ruff
if: always()
run: poetry run ruff check surrealdb/
- name: Run ruff checks
run: ruff check src/

- id: Black
if: always()
run: poetry run black surrealdb/ --check --verbose --diff --color
- name: Run black checks
run: black --check --verbose --diff --color src/

- id: mypy
if: always()
run: poetry run mypy surrealdb/
- name: Run mypy checks
run: mypy src/
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- "*"

concurrency:
group: tests-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
run-unit-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
surrealdb-version: ["v2.1.0", "v2.1.1", "v2.1.2", "v2.1.3", "v2.1.4"] # v2.0.0 has different UPSERT behaviour
name: Python ${{ matrix.python-version }} - SurrealDB ${{ matrix.surrealdb-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install surrealdb
run: curl -sSf https://install.surrealdb.com | sh -s -- --version ${{ matrix.surrealdb-version }}

- name: Start surrealdb
run: surreal start --allow-all -u root -p root --log trace &

- name: Wait for startup
run: sleep 5

- name: Install dependencies
run: pip install -r requirements.txt

- name: Run unit tests (HTTP)
run: python -m unittest discover -s tests
env:
PYTHONPATH: ./src
SURREALDB_URL: http://localhost:8000

- name: Run unit tests (WebSocket)
run: python -m unittest discover -s tests
env:
PYTHONPATH: ./src
SURREALDB_URL: ws://localhost:8000



39 changes: 0 additions & 39 deletions .github/workflows/unit_tests.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/surrealdb/connections/async_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ async def upsert(
self.check_response_for_result(response, "upsert")
return response["result"]

def close(self):
self.socket.close()
async def close(self):
await self.socket.close()

async def __aenter__(self) -> "AsyncWsSurrealConnection":
"""
Expand Down
28 changes: 11 additions & 17 deletions tests/unit_tests/connections/invalidate/test_async_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ async def asyncSetUp(self):
_ = await self.connection.signin(self.vars_params)
_ = await self.connection.use(namespace=self.namespace, database=self.database_name)

async def running_through_docker(self):
_ = await self.connection.invalidate()
with self.assertRaises(Exception) as context:
_ = await self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)

async def running_through_binary(self):
async def test_invalidate(self):
outcome = await self.connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))
outcome = await self.main_connection.query("SELECT * FROM user;")
Expand All @@ -47,14 +38,17 @@ async def running_through_binary(self):
outcome = await self.main_connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))

await self.main_connection.query("DELETE user;")

async def test_invalidate(self):
if os.environ.get("DOCKER_RUN") == "TRUE":
await self.running_through_docker()
else:
await self.running_through_binary()
'''
# Exceptions are raised only when SurrealDB doesn't allow guest mode
with self.assertRaises(Exception) as context:
_ = await self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)
'''

await self.main_connection.query("DELETE user;")

if __name__ == "__main__":
main()
30 changes: 13 additions & 17 deletions tests/unit_tests/connections/invalidate/test_async_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ async def asyncSetUp(self):
_ = await self.connection.signin(self.vars_params)
_ = await self.connection.use(namespace=self.namespace, database=self.database_name)

async def running_through_docker(self):
_ = await self.connection.invalidate()
with self.assertRaises(Exception) as context:
_ = await self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)

async def running_through_binary(self):
async def test_invalidate(self):
outcome = await self.connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))
outcome = await self.main_connection.query("SELECT * FROM user;")
Expand All @@ -47,14 +38,19 @@ async def running_through_binary(self):
outcome = await self.main_connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))

await self.main_connection.query("DELETE user;")

async def test_invalidate(self):
if os.environ.get("DOCKER_RUN") == "TRUE":
await self.running_through_docker()
else:
await self.running_through_binary()
'''
# Exceptions are raised only when SurrealDB doesn't allow guest mode
with self.assertRaises(Exception) as context:
_ = await self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)
'''

await self.main_connection.query("DELETE user;")
await self.main_connection.close()
await self.connection.close()

if __name__ == "__main__":
main()
28 changes: 11 additions & 17 deletions tests/unit_tests/connections/invalidate/test_blocking_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ def setUp(self):
_ = self.connection.signin(self.vars_params)
_ = self.connection.use(namespace=self.namespace, database=self.database_name)

def running_through_docker(self):
_ = self.connection.invalidate()
with self.assertRaises(Exception) as context:
_ = self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)

def running_through_binary(self):
def test_invalidate(self):
outcome = self.connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))
outcome = self.main_connection.query("SELECT * FROM user;")
Expand All @@ -47,14 +38,17 @@ def running_through_binary(self):
outcome = self.main_connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))

self.main_connection.query("DELETE user;")

def test_invalidate(self):
if os.environ.get("DOCKER_RUN") == "TRUE":
self.running_through_docker()
else:
self.running_through_binary()
'''
# Exceptions are raised only when SurrealDB doesn't allow guest mode
with self.assertRaises(Exception) as context:
_ = self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)
'''

self.main_connection.query("DELETE user;")

if __name__ == "__main__":
main()
20 changes: 6 additions & 14 deletions tests/unit_tests/connections/invalidate/test_blocking_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self):
_ = self.connection.signin(self.vars_params)
_ = self.connection.use(namespace=self.namespace, database=self.database_name)

def running_through_binary(self):
def test_invalidate(self):
outcome = self.connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))
outcome = self.main_connection.query("SELECT * FROM user;")
Expand All @@ -38,27 +38,19 @@ def running_through_binary(self):
outcome = self.main_connection.query("SELECT * FROM user;")
self.assertEqual(1, len(outcome))

self.main_connection.query("DELETE user;")
self.main_connection.close()
self.connection.close()

def running_through_docker(self):
_ = self.connection.invalidate()
'''
# Exceptions are raised only when SurrealDB doesn't allow guest mode
with self.assertRaises(Exception) as context:
_ = self.connection.query("CREATE user:jaime SET name = 'Jaime';")
self.assertEqual(
"IAM error: Not enough permissions" in str(context.exception),
True
)
'''

self.main_connection.query("DELETE user;")
self.main_connection.close()
self.connection.close()

def test_invalidate(self):
if os.environ.get("DOCKER_RUN") == "TRUE":
self.running_through_docker()
else:
self.running_through_binary()


if __name__ == "__main__":
main()

0 comments on commit 7adba41

Please sign in to comment.