Skip to content

Commit

Permalink
tests: fix unit and e2e tests after the upgrade
Browse files Browse the repository at this point in the history
Fix root and token endpoint unit tests.
Fix node creation test.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia committed Oct 24, 2024
1 parent 0bd1ba6 commit 5e82246
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

db_client = AsyncIOMotorClient(DB_URL)
db = db_client[DB_NAME]
node_model_fields = set(Node.__fields__.keys())
regression_model_fields = set(Regression.__fields__.keys())
node_model_fields = set(Node.model_fields.keys())
regression_model_fields = set(Regression.model_fields.keys())
paginated_response_keys = {
'items',
'total',
Expand All @@ -42,7 +42,8 @@ async def db_create(collection, obj):
"""Database create method"""
delattr(obj, 'id')
col = db[collection]
res = await col.insert_one(obj.dict(by_alias=True))
# res = await col.insert_one(obj.dict(by_alias=True))
res = await col.insert_one(obj.model_dump(by_alias=True))
obj.id = res.inserted_id
return obj

Expand Down
1 change: 1 addition & 0 deletions tests/e2e_tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def test_node_pipeline(test_async_client):

# Create a node
node = {
"kind": "checkout",
"name": "checkout",
"path": ["checkout"],
"data": {
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ async def mock_beanie_get_user_by_id(mocker):
return async_mock


@pytest.fixture
async def mock_beanie_user_update(mocker):
"""Mocks async call to external method to update user"""
async_mock = AsyncMock()
mocker.patch('fastapi_users_db_beanie.BeanieUserDatabase.update',
side_effect=async_mock)
return async_mock


@pytest.fixture
def mock_auth_current_user(mocker):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_node_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent,
"describe": "v5.16-rc4-31-g2a987e65025e",
}

revision_obj = Revision.parse_obj(revision_data)
revision_obj = Revision.model_validate(revision_data)
node_obj = Node(
id="61bda8f2eb1a63d2b7152418",
kind="checkout",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_root_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def test_root_endpoint(test_client):
HTTP Response Code 200 OK
JSON with 'message' key
"""
response = test_client.get("/latest")
response = test_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "KernelCI API"}
5 changes: 4 additions & 1 deletion tests/unit_tests/test_token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@


@pytest.mark.asyncio
async def test_token_endpoint(test_async_client, mock_user_find):
async def test_token_endpoint(test_async_client, mock_user_find,
mock_beanie_user_update):
"""
Test Case : Test KernelCI API /user/login endpoint
Expected Result :
Expand All @@ -34,6 +35,8 @@ async def test_token_endpoint(test_async_client, mock_user_find):
is_verified=True
)
mock_user_find.return_value = user
mock_beanie_user_update.return_value = user

response = await test_async_client.post(
"user/login",
headers={
Expand Down

0 comments on commit 5e82246

Please sign in to comment.