Skip to content

Commit

Permalink
test: cors tests are now properly async
Browse files Browse the repository at this point in the history
  • Loading branch information
alexogeny committed Aug 18, 2024
1 parent 0fffc9f commit 58b2253
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 0 additions & 4 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@ def test_singleton_behavior(self):
def test_no_such_file(self):
with self.assertRaises(FileNotFoundError):
Config("non_existent_file.ini")


if __name__ == "__main__":
unittest.main()
16 changes: 7 additions & 9 deletions tests/config/test_cors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import unittest
from typing import Any, Dict
from unittest.mock import AsyncMock, mock_open, patch
Expand All @@ -8,7 +7,7 @@
from zara.server.server import SimpleASGIApp


class TestCORS(unittest.TestCase):
class TestCORS(unittest.IsolatedAsyncioTestCase):
def setUp(self):
config_content = """
[server]
Expand Down Expand Up @@ -37,7 +36,7 @@ async def hello_world(request: Dict[str, Any]) -> Dict[str, Any]:

self.app.add_router(self.router)

def test_cors_headers(self):
async def test_cors_headers(self):
send_mock = AsyncMock()

async def run_app_with_scope(scope):
Expand All @@ -51,7 +50,7 @@ async def run_app_with_scope(scope):
"query_string": b"",
}

asyncio.run(run_app_with_scope(scope))
await run_app_with_scope(scope)
send_mock.assert_any_await(
{
"type": "http.response.start",
Expand All @@ -72,7 +71,7 @@ async def run_app_with_scope(scope):
}
)

def test_cors_no_origin(self):
async def test_cors_no_origin(self):
send_mock = AsyncMock()

async def run_app_with_scope(scope):
Expand All @@ -86,8 +85,7 @@ async def run_app_with_scope(scope):
"query_string": b"",
}

asyncio.run(run_app_with_scope(scope))

await run_app_with_scope(scope)
send_mock.assert_any_await(
{
"type": "http.response.start",
Expand All @@ -102,7 +100,7 @@ async def run_app_with_scope(scope):
}
)

def test_cors_not_allowed_origin(self):
async def test_cors_not_allowed_origin(self):
send_mock = AsyncMock()

async def run_app_with_scope(scope):
Expand All @@ -116,7 +114,7 @@ async def run_app_with_scope(scope):
"query_string": b"",
}

asyncio.run(run_app_with_scope(scope))
await run_app_with_scope(scope)

send_mock.assert_any_await(
{
Expand Down

0 comments on commit 58b2253

Please sign in to comment.