Skip to content

Commit 86435f8

Browse files
committed
fix: event loop fixed
1 parent c93ea35 commit 86435f8

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def suppress_sqlalchemy_logs():
2121
yield
2222
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
2323

24-
@pytest_asyncio.fixture(scope="session", loop_scope="session")
24+
@pytest_asyncio.fixture(scope="module", loop_scope="session")
2525
async def database_setup():
2626
# reset the database again, just in case
2727
print("Resetting DB...")
@@ -32,7 +32,7 @@ async def database_setup():
3232
yield sessionmanager
3333
await sessionmanager.close()
3434

35-
@pytest_asyncio.fixture(scope="function", loop_scope="session")
35+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
3636
async def client() -> AsyncGenerator[Any, None]:
3737
# base_url is just a random placeholder url
3838
# ASGITransport is just telling the async client to pass all requests to app
@@ -45,12 +45,13 @@ async def db_session(database_setup):
4545
async with database_setup.session() as session:
4646
yield session
4747

48-
@pytest_asyncio.fixture(scope="function", loop_scope="session")
49-
async def admin_session(database_setup):
48+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
49+
async def admin_client(database_setup, client):
5050
session_id = "temp_id_" + load_test_db.SYSADMIN_COMPUTING_ID
51+
client.cookies = { "session_id": session_id }
5152
async with database_setup.session() as session:
5253
await create_user_session(session, session_id, load_test_db.SYSADMIN_COMPUTING_ID)
53-
yield
54+
yield client
5455
await remove_user_session(session, session_id)
5556

5657

tests/integration/test_officers.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio # NOTE: don't comment this out; it's required
21
import json
32
from datetime import date, timedelta
43

@@ -16,7 +15,6 @@
1615

1716
async def test__read_execs(db_session):
1817
# test that reads from the database succeeded as expected
19-
print(type(db_session))
2018
assert (await get_active_officer_terms(db_session, "blarg")) == []
2119
assert (await get_active_officer_terms(db_session, "abc22")) != []
2220

@@ -55,8 +53,7 @@ async def test__read_execs(db_session):
5553
# pass
5654

5755
async def test__get_officers(client):
58-
# private data shoudn't be leaked
59-
print(f"[DEBUG] Loop ID in {__name__}: {id(asyncio.get_running_loop())}")
56+
# private data shouldn't be leaked
6057
response = await client.get("/officers/current")
6158
assert response.status_code == 200
6259
assert response.json() != {}
@@ -172,20 +169,15 @@ async def test__patch_officer_terms(client: AsyncClient):
172169
response = await client.delete("officers/term/1")
173170
assert response.status_code == 401
174171

175-
@pytest.mark.skip
176-
async def test__endpoints_admin(client, database_setup, admin_session):
177-
# login as website admin
178-
session_id = "temp_id_" + load_test_db.SYSADMIN_COMPUTING_ID
179-
180-
client.cookies = { "session_id": session_id }
181-
172+
async def test__get_current_officers_admin(admin_client):
182173
# test that more info is given if logged in & with access to it
183-
response = await client.get("/officers/current")
174+
response = await admin_client.get("/officers/current")
184175
assert response.status_code == 200
185176
curr_officers = response.json()
186177
assert len(curr_officers) == 3
187178
assert curr_officers["executive at large"]["computing_id"] is not None
188179

180+
async def test__get_all_officers_admin(client):
189181
response = await client.get("/officers/all?include_future_terms=true")
190182
assert response.status_code == 200
191183
assert len(response.json()) == 9

0 commit comments

Comments
 (0)