Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues in existing tests #48

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone

import hypothesis
import pytest
Expand All @@ -24,14 +24,21 @@
),
)

DATETIME_TODAY_MIDNIGHT = datetime.now().replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)

datetime_today_until_now_strategy = st.datetimes(
min_value=datetime.now().replace(hour=0),
min_value=DATETIME_TODAY_MIDNIGHT,
max_value=datetime.now(),
timezones=st.just(timezone.utc),
)

datetime_before_today_strategy = st.datetimes(
max_value=datetime.now().replace(hour=0),
max_value=DATETIME_TODAY_MIDNIGHT - timedelta(microseconds=1),
min_value=datetime(1970, 1, 1, 12, 0, 0),
timezones=st.just(timezone.utc),
)
Expand Down
18 changes: 12 additions & 6 deletions tests/enlyze/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from enlyze.client import EnlyzeClient
from enlyze.constants import (
ENLYZE_BASE_URL,
MAXIMUM_NUMBER_OF_VARIABLES_PER_TIMESERIES_REQUEST,
PRODUCTION_RUNS_API_SUB_PATH,
TIMESERIES_API_SUB_PATH,
)
Expand Down Expand Up @@ -350,6 +349,7 @@ def test_get_timeseries_returns_none_on_empty_response(
)
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
def test__get_timeseries_raises_on_mixed_response(
monkeypatch,
data_strategy,
start_datetime,
end_datetime,
Expand All @@ -360,6 +360,14 @@ def test__get_timeseries_raises_on_mixed_response(
Tests that an `EnlyzeError` is raised if the timeseries API returns
data for some of the variables but not all of them.
"""

# patch to lower value to improve test performance
max_vars_per_request = 10
monkeypatch.setattr(
"enlyze.client.MAXIMUM_NUMBER_OF_VARIABLES_PER_TIMESERIES_REQUEST",
max_vars_per_request,
)

client = make_client()
variables = data_strategy.draw(
st.lists(
Expand All @@ -368,8 +376,8 @@ def test__get_timeseries_raises_on_mixed_response(
data_type=st.just("INTEGER"),
machine=st.just(machine),
),
min_size=MAXIMUM_NUMBER_OF_VARIABLES_PER_TIMESERIES_REQUEST + 1,
max_size=MAXIMUM_NUMBER_OF_VARIABLES_PER_TIMESERIES_REQUEST + 5,
min_size=max_vars_per_request + 1,
max_size=max_vars_per_request + 5,
)
)

Expand All @@ -382,9 +390,7 @@ def test__get_timeseries_raises_on_mixed_response(
"time",
*[
str(variable.uuid)
for variable in variables[
:MAXIMUM_NUMBER_OF_VARIABLES_PER_TIMESERIES_REQUEST
]
for variable in variables[:max_vars_per_request]
],
],
records=records,
Expand Down
Loading