Skip to content

Commit

Permalink
Extend narrativelog tests to verify date_begin and date_end params ar…
Browse files Browse the repository at this point in the history
…e transformed to TAI scale.
  • Loading branch information
sebastian-aranda committed Dec 20, 2024
1 parent 69b1c88 commit ccda055
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
40 changes: 37 additions & 3 deletions manager/api/tests/test_ole.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from django.urls import reverse
from rest_framework.test import APIClient

from manager.utils import DATETIME_ISO_FORMAT, get_tai_from_utc


@override_settings(DEBUG=True)
class OLETestCase(TestCase):
Expand Down Expand Up @@ -71,9 +73,9 @@ def setUp(self):
"components": "MainTel",
"primary_software_components": "None",
"primary_hardware_components": "None",
"date_begin": "2020-07-03T19:58:13.000000",
"date_end": "2022-07-04T19:25:13.000000",
"time_lost": 10,
"date_begin": "2024-01-01T00:00:00.000000",
"date_end": "2024-01-01T00:10:00.000000",
"time_lost": 1,
"level": 0,
}

Expand Down Expand Up @@ -318,8 +320,24 @@ def test_simple_narrativelog_create(self):
# Act:
url = reverse("NarrativeLogs-list")
response = self.client.post(url, self.payload_full_narrative)

# Assert:
self.assertEqual(response.status_code, 201)

# Check the date_begin and date_end arguments
# are transformed to TAI scale.
mock_ole_client_json_arg = mock_ole_client.call_args.kwargs["json"].dict()
date_begin_arg = mock_ole_client_json_arg["date_begin"]
date_end_arg = mock_ole_client_json_arg["date_end"]
payload_date_begin_formatted = get_tai_from_utc(
self.payload_full_narrative["date_begin"]
).strftime("%Y-%m-%dT%H:%M:%S.%f")
payload_date_end_formatted = get_tai_from_utc(
self.payload_full_narrative["date_end"]
).strftime("%Y-%m-%dT%H:%M:%S.%f")
assert date_begin_arg == payload_date_begin_formatted
assert date_end_arg == payload_date_end_formatted

mock_ole_client.stop()

def test_narrativelog_update(self):
Expand All @@ -339,8 +357,24 @@ def test_narrativelog_update(self):
# Act:
url = reverse("NarrativeLogs-detail", args=[1])
response = self.client.put(url, self.payload_full_narrative)

# Assert
self.assertEqual(response.status_code, 200)

# Check the date_begin and date_end arguments
# are transformed to TAI scale.
mock_ole_client_json_arg = mock_ole_client.call_args.kwargs["json"].dict()
date_begin_arg = mock_ole_client_json_arg["date_begin"]
date_end_arg = mock_ole_client_json_arg["date_end"]
payload_date_begin_formatted = get_tai_from_utc(
self.payload_full_narrative["date_begin"]
).strftime(DATETIME_ISO_FORMAT)
payload_date_end_formatted = get_tai_from_utc(
self.payload_full_narrative["date_end"]
).strftime(DATETIME_ISO_FORMAT)
assert date_begin_arg == payload_date_begin_formatted
assert date_end_arg == payload_date_end_formatted

mock_ole_client.stop()

def test_narrative_log_create_with_jira(self):
Expand Down
5 changes: 3 additions & 2 deletions manager/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
AUTH_LDAP_3_SERVER_URI,
)
from manager.utils import (
DATETIME_ISO_FORMAT,
CommandPermission,
arrange_nightreport_email,
get_jira_obs_report,
Expand Down Expand Up @@ -1316,7 +1317,7 @@ def create(self, request, *args, **kwargs):
for key in date_keys:
if key in json_data:
tai_datetime = get_tai_from_utc(json_data[key])
json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")
json_data[key] = tai_datetime.strftime(DATETIME_ISO_FORMAT)

# Split lists of values separated by comma
array_keys = {
Expand Down Expand Up @@ -1384,7 +1385,7 @@ def update(self, request, pk=None, *args, **kwargs):
for key in date_keys:
if key in json_data:
tai_datetime = get_tai_from_utc(json_data[key])
json_data[key] = tai_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")
json_data[key] = tai_datetime.strftime(DATETIME_ISO_FORMAT)

array_keys = {
"components",
Expand Down
2 changes: 2 additions & 0 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
PRIMARY_SOFTWARE_COMPONENTS_IDS = "customfield_10107"
PRIMARY_HARDWARE_COMPONENTS_IDS = "customfield_10196"

DATETIME_ISO_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"


class LocationPermission(BasePermission):
"""Permission class to check if the user is in the location whitelist."""
Expand Down

0 comments on commit ccda055

Please sign in to comment.