Skip to content

Commit

Permalink
Refactor fixtures. Add preview client as possible fixture for ce and …
Browse files Browse the repository at this point in the history
…extra ce client.
  • Loading branch information
fkdosilovic committed Jan 5, 2025
1 parent 56f6953 commit 4a2e4f1
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from dotenv import load_dotenv

from judge0 import clients
from judge0 import clients, RegularPeriodRetry

load_dotenv()

Expand Down Expand Up @@ -34,55 +34,71 @@ def custom_extra_ce_client():
@pytest.fixture(scope="session")
def atd_ce_client():
api_key = os.getenv("JUDGE0_ATD_API_KEY")
client = clients.ATDJudge0CE(api_key)
return client

if api_key is None:
return None
else:
return clients.ATDJudge0CE(api_key)


@pytest.fixture(scope="session")
def atd_extra_ce_client():
api_key = os.getenv("JUDGE0_ATD_API_KEY")
client = clients.ATDJudge0ExtraCE(api_key)
return client

if api_key is None:
return None
else:
return clients.ATDJudge0ExtraCE(api_key)


@pytest.fixture(scope="session")
def rapid_ce_client():
api_key = os.getenv("JUDGE0_RAPID_API_KEY")
client = clients.RapidJudge0CE(api_key)
return client

if api_key is None:
return None
else:
return clients.RapidJudge0CE(api_key)


@pytest.fixture(scope="session")
def rapid_extra_ce_client():
api_key = os.getenv("JUDGE0_RAPID_API_KEY")
client = clients.RapidJudge0ExtraCE(api_key)
return client

if api_key is None:
return None
else:
return clients.RapidJudge0ExtraCE(api_key)


@pytest.fixture(scope="session")
def sulu_ce_client():
api_key = os.getenv("JUDGE0_SULU_API_KEY")
if api_key is None:
pytest.fail(
"Sulu API key is not available for testing. Make sure to have "
"JUDGE0_SULU_API_KEY in your environment variables."
)

client = clients.SuluJudge0CE(api_key)
return client
if api_key is None:
return None
else:
return clients.SuluJudge0CE(api_key)


@pytest.fixture(scope="session")
def sulu_extra_ce_client():
api_key = os.getenv("JUDGE0_SULU_API_KEY")

if api_key is None:
pytest.fail(
"Sulu API key is not available for testing. Make sure to have "
"JUDGE0_SULU_API_KEY in your environment variables."
)
return None
else:
return clients.SuluJudge0ExtraCE(api_key)

client = clients.SuluJudge0ExtraCE(api_key)
return client

@pytest.fixture(scope="session")
def preview_ce_client() -> clients.SuluJudge0CE:
return clients.SuluJudge0CE(retry_strategy=RegularPeriodRetry(0.5))


@pytest.fixture(scope="session")
def preview_extra_ce_client() -> clients.SuluJudge0ExtraCE:
return clients.SuluJudge0ExtraCE(retry_strategy=RegularPeriodRetry(0.5))


@pytest.fixture(scope="session")
Expand All @@ -91,6 +107,7 @@ def ce_client(
sulu_ce_client,
rapid_ce_client,
atd_ce_client,
preview_ce_client,
):
if custom_ce_client is not None:
return custom_ce_client
Expand All @@ -100,8 +117,10 @@ def ce_client(
return rapid_ce_client
if atd_ce_client is not None:
return atd_ce_client
if preview_ce_client is not None:
return preview_ce_client

pytest.fail("No CE client available for testing.")
pytest.fail("No CE client available for testing. This error should not happen!")


@pytest.fixture(scope="session")
Expand All @@ -110,6 +129,7 @@ def extra_ce_client(
sulu_extra_ce_client,
rapid_extra_ce_client,
atd_extra_ce_client,
preview_extra_ce_client,
):
if custom_extra_ce_client is not None:
return custom_extra_ce_client
Expand All @@ -119,5 +139,9 @@ def extra_ce_client(
return rapid_extra_ce_client
if atd_extra_ce_client is not None:
return atd_extra_ce_client
if preview_extra_ce_client is not None:
return preview_extra_ce_client

pytest.fail("No Extra CE client available for testing.")
pytest.fail(
"No Extra CE client available for testing. This error should not happen!"
)

0 comments on commit 4a2e4f1

Please sign in to comment.