Skip to content

Commit d1b28bd

Browse files
Jeny Sadadianuclearcat
Jeny Sadadia
authored andcommitted
tests: fix unit and e2e tests after the upgrade
Fix root and token endpoint unit tests. Fix node creation test. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent acbfc79 commit d1b28bd

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

tests/e2e_tests/conftest.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
db_client = AsyncIOMotorClient(DB_URL)
2121
db = db_client[DB_NAME]
22-
node_model_fields = set(Node.__fields__.keys())
23-
regression_model_fields = set(Regression.__fields__.keys())
22+
node_model_fields = set(Node.model_fields.keys())
23+
regression_model_fields = set(Regression.model_fields.keys())
2424
paginated_response_keys = {
2525
'items',
2626
'total',
@@ -42,7 +42,8 @@ async def db_create(collection, obj):
4242
"""Database create method"""
4343
delattr(obj, 'id')
4444
col = db[collection]
45-
res = await col.insert_one(obj.dict(by_alias=True))
45+
# res = await col.insert_one(obj.dict(by_alias=True))
46+
res = await col.insert_one(obj.model_dump(by_alias=True))
4647
obj.id = res.inserted_id
4748
return obj
4849

tests/e2e_tests/test_pipeline.py

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async def test_node_pipeline(test_async_client):
4242

4343
# Create a node
4444
node = {
45+
"kind": "checkout",
4546
"name": "checkout",
4647
"path": ["checkout"],
4748
"data": {

tests/unit_tests/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ async def mock_beanie_get_user_by_id(mocker):
277277
return async_mock
278278

279279

280+
@pytest.fixture
281+
async def mock_beanie_user_update(mocker):
282+
"""Mocks async call to external method to update user"""
283+
async_mock = AsyncMock()
284+
mocker.patch('fastapi_users_db_beanie.BeanieUserDatabase.update',
285+
side_effect=async_mock)
286+
return async_mock
287+
288+
280289
@pytest.fixture
281290
def mock_auth_current_user(mocker):
282291
"""

tests/unit_tests/test_node_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent,
3333
"describe": "v5.16-rc4-31-g2a987e65025e",
3434
}
3535

36-
revision_obj = Revision.parse_obj(revision_data)
36+
revision_obj = Revision.model_validate(revision_data)
3737
node_obj = Node(
3838
id="61bda8f2eb1a63d2b7152418",
3939
kind="checkout",

tests/unit_tests/test_root_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def test_root_endpoint(test_client):
1515
HTTP Response Code 200 OK
1616
JSON with 'message' key
1717
"""
18-
response = test_client.get("/latest")
18+
response = test_client.get("/")
1919
assert response.status_code == 200
2020
assert response.json() == {"message": "KernelCI API"}

tests/unit_tests/test_token_handler.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616

1717
@pytest.mark.asyncio
18-
async def test_token_endpoint(test_async_client, mock_user_find):
18+
async def test_token_endpoint(test_async_client, mock_user_find,
19+
mock_beanie_user_update):
1920
"""
2021
Test Case : Test KernelCI API /user/login endpoint
2122
Expected Result :
@@ -34,6 +35,8 @@ async def test_token_endpoint(test_async_client, mock_user_find):
3435
is_verified=True
3536
)
3637
mock_user_find.return_value = user
38+
mock_beanie_user_update.return_value = user
39+
3740
response = await test_async_client.post(
3841
"user/login",
3942
headers={

0 commit comments

Comments
 (0)