Skip to content

Commit

Permalink
#225: Fix tests involving timezone data
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed May 5, 2021
1 parent 26b7bd6 commit 9b2dc7d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion datagateway_api/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime

from dateutil.tz import tzlocal


class Constants:
PYTHON_ICAT_DISTNCT_CONDITION = "!= null"
TEST_MOD_CREATE_DATETIME = datetime(2000, 1, 1)
TEST_MOD_CREATE_DATETIME = datetime(2000, 1, 1, tzinfo=tzlocal())
11 changes: 6 additions & 5 deletions test/icat/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timezone
from datetime import datetime
import uuid

from dateutil.tz import tzlocal
from flask import Flask
from icat.client import Client
from icat.exception import ICATNoObjectError
Expand Down Expand Up @@ -49,10 +50,10 @@ def create_investigation_test_data(client, num_entities=1):
f"Test data for the Python ICAT Backend on DataGateway API {i}"
)
investigation.startDate = datetime(
year=2020, month=1, day=4, hour=1, minute=1, second=1, tzinfo=timezone.utc,
year=2020, month=1, day=4, hour=1, minute=1, second=1, tzinfo=tzlocal(),
)
investigation.endDate = datetime(
year=2020, month=1, day=8, hour=1, minute=1, second=1, tzinfo=timezone.utc,
year=2020, month=1, day=8, hour=1, minute=1, second=1, tzinfo=tzlocal(),
)
# UUID visit ID means uniquesness constraint should always be met
investigation.visitId = str(uuid.uuid1())
Expand Down Expand Up @@ -112,10 +113,10 @@ def isis_specific_endpoint_data(icat_client):
facility_cycle = icat_client.new("facilityCycle")
facility_cycle.name = "Test cycle for DataGateway API testing"
facility_cycle.startDate = datetime(
year=2020, month=1, day=1, hour=1, minute=1, second=1, tzinfo=timezone.utc,
year=2020, month=1, day=1, hour=1, minute=1, second=1, tzinfo=tzlocal(),
)
facility_cycle.endDate = datetime(
year=2020, month=2, day=1, hour=1, minute=1, second=1, tzinfo=timezone.utc,
year=2020, month=2, day=1, hour=1, minute=1, second=1, tzinfo=tzlocal(),
)
facility_cycle.facility = icat_client.get("Facility", 1)
facility_cycle.create()
Expand Down
5 changes: 3 additions & 2 deletions test/icat/test_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timezone
from datetime import datetime

from dateutil.tz import tzlocal
from icat.entity import Entity
import pytest

Expand Down Expand Up @@ -364,7 +365,7 @@ def test_valid_get_distinct_attributes(self, icat_client):
hour=1,
minute=1,
second=1,
tzinfo=timezone.utc,
tzinfo=tzlocal(),
),
),
{"startDate": "2020-01-04 01:01:01+00:00"},
Expand Down
9 changes: 6 additions & 3 deletions test/icat/test_session_handling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from datetime import datetime

from dateutil.tz import tzlocal
from icat.client import Client
import pytest

from datagateway_api.common.config import APIConfigOptions, config
from datagateway_api.common.date_handler import DateHandler
from datagateway_api.common.icat.filters import PythonICATWhereFilter


Expand All @@ -15,10 +17,11 @@ def test_get_valid_session_details(
"/sessions", headers=valid_icat_credentials_header,
)

session_expiry_datetime = datetime.strptime(
session_details.json["expireDateTime"], "%Y-%m-%d %H:%M:%S",
session_expiry_datetime = DateHandler.str_to_datetime_object(
session_details.json["expireDateTime"],
)
current_datetime = datetime.now()

current_datetime = datetime.now(tzlocal())
time_diff = abs(session_expiry_datetime - current_datetime)
time_diff_minutes = time_diff.seconds / 60

Expand Down

0 comments on commit 9b2dc7d

Please sign in to comment.