Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAlbertQC committed Jul 15, 2024
1 parent f22e5b3 commit 66e5b34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 4 additions & 9 deletions quetz/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import tempfile
from typing import List, Iterator
from unittest import mock

import pytest
import sqlalchemy.orm
Expand Down Expand Up @@ -158,8 +159,9 @@ def wrapper(*args, **kwargs):
def db(
session_maker: sqlalchemy.orm.sessionmaker,
) -> Iterator[sqlalchemy.orm.Session]:
with session_maker() as db:
yield db
with mock.patch("quetz.database.get_session", session_maker):
with session_maker() as db:
yield db


@pytest.fixture
Expand Down Expand Up @@ -257,13 +259,6 @@ def app(config, db, mocker):
from quetz.deps import get_db
from quetz.main import app

# mocking is required for some functions that do not use fastapi
# dependency injection (mainly non-request functions)
def get_session_mock(*args, **kwargs):
return db

mocker.patch("quetz.database.get_session", get_session_mock)

# overriding dependency works with all requests handlers that
# depend on quetz.deps.get_db
app.dependency_overrides[get_db] = lambda: db
Expand Down
7 changes: 4 additions & 3 deletions quetz/tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uuid
from io import BytesIO
from pathlib import Path
from unittest import mock
from unittest.mock import MagicMock
from urllib.parse import urlparse

Expand Down Expand Up @@ -820,7 +821,7 @@ def test_add_and_register_mirror(auth_client, dummy_session_mock):
]
],
)
def test_wrong_package_format(client, dummy_repo, owner, job_supervisor):
def test_wrong_package_format(session_maker, client, dummy_repo, owner, job_supervisor):
response = client.get("/api/dummylogin/bartosz")
assert response.status_code == 200

Expand All @@ -837,8 +838,8 @@ def test_wrong_package_format(client, dummy_repo, owner, job_supervisor):
)

assert response.status_code == 201

job_supervisor.run_once()
with mock.patch("quetz.database.get_session", session_maker):
job_supervisor.run_once()

assert dummy_repo == [
"http://mirror3_host/channeldata.json",
Expand Down

0 comments on commit 66e5b34

Please sign in to comment.