Skip to content

Commit

Permalink
Merge pull request #2795 from HHS/OPS-2784/nighttime-tests-timezone-i…
Browse files Browse the repository at this point in the history
…ssue

fix: Created a fixture that converts local time to UTC
  • Loading branch information
Santi-3rd authored Sep 17, 2024
2 parents 54799b8 + c4b0ad4 commit f527583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions backend/ops_api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import subprocess
from collections.abc import Generator
from datetime import datetime, timezone

import pytest
from flask import Flask
Expand Down Expand Up @@ -175,3 +176,8 @@ def test_can(loaded_db) -> CAN | None:
def test_bli(loaded_db) -> BudgetLineItem | None:
"""Get a test BudgetLineItem."""
return loaded_db.get(BudgetLineItem, 15000)


@pytest.fixture
def utc_today():
return datetime.now(timezone.utc).strftime("%Y-%m-%dT")
16 changes: 8 additions & 8 deletions backend/ops_api/tests/ops/agreement/test_agreement_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_agreement_history(auth_client, loaded_db, test_can):
assert len(data[5]["changes"]) == 11


def test_agreement_history_log_items(auth_client, app, test_can):
def test_agreement_history_log_items(auth_client, app, test_can, utc_today):
session = app.db_session

# create agreement (using API)
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):
assert log_item["event_type"] == "NEW"
assert log_item["scope"] == "OBJECT"
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)

# update Agreement
data = {
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):
"old": "TEST: Agreement history with change requests",
}
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)

# create BLI
bli = BudgetLineItem(
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):
assert log_item["event_type"] == "NEW"
assert log_item["scope"] == "OBJECT"
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)

# update BLI
bli.can_id = 501
Expand All @@ -244,7 +244,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):
assert log_item["event_type"] == "UPDATED"
assert log_item["scope"] == "PROPERTY"
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)
assert log_item["property_key"] in ["amount", "can_id", "date_needed"]
if log_item["property_key"] == "amount":
assert log_item["change"] == {"new": 222.22, "old": 111.11}
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):
assert log_item["property_key"] == "status"
assert log_item["event_type"] == "UPDATED"
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)
assert log_item["change"] == {"new": "PLANNED", "old": "DRAFT"}

session.delete(bli)
Expand All @@ -283,7 +283,7 @@ def test_agreement_history_log_items(auth_client, app, test_can):


@pytest.mark.usefixtures("app_ctx")
def test_agreement_history_log_items_with_change_requests(auth_client, loaded_db, test_can, test_project):
def test_agreement_history_log_items_with_change_requests(auth_client, loaded_db, test_can, test_project, utc_today):
# create agreement (using API)
data = {
"agreement_type": "CONTRACT",
Expand Down Expand Up @@ -353,7 +353,7 @@ def test_agreement_history_log_items_with_change_requests(auth_client, loaded_db
assert log_item["event_type"] == "IN_REVIEW"
assert log_item["scope"] == "PROPERTY"
assert log_item["created_on"] is not None
assert log_item["created_on"].startswith(datetime.datetime.today().strftime("%Y-%m-%dT"))
assert log_item["created_on"].startswith(utc_today)
assert log_item["property_key"] in ["amount", "can_id", "date_needed"]
if log_item["property_key"] == "amount":
assert log_item["change"] == {"new": 333.33, "old": 111.11}
Expand Down

0 comments on commit f527583

Please sign in to comment.