Skip to content

Commit e42fbe8

Browse files
Merge pull request #284 from lsst-ts/tickets/DM-46580
Fix date conversion for the get_jira_obs_report method
2 parents 05f9d23 + bb561b7 commit e42fbe8

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Version History
33
===============
44

5+
v7.1.2
6+
------
7+
8+
* Fix date conversion for the get_jira_obs_report method `<https://github.com/lsst-ts/LOVE-manager/pull/284>`_
9+
510
v7.1.1
611
------
712

manager/api/tests/test_jira.py

+59
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from manager.utils import (
3232
TIME_LOST_FIELD,
33+
get_jira_obs_report,
3334
handle_jira_payload,
3435
jira_comment,
3536
jira_ticket,
@@ -488,3 +489,61 @@ def test_handle_exposure_jira_payload(self):
488489
)
489490

490491
mock_jira_patcher.stop()
492+
493+
def test_get_jira_obs_report(self):
494+
"""Test call to get_jira_obs_report
495+
function with all needed parameters"""
496+
mock_jira_patcher = patch("requests.get")
497+
mock_jira_client = mock_jira_patcher.start()
498+
response = requests.Response()
499+
response.status_code = 200
500+
response.json = lambda: {
501+
"issues": [
502+
{
503+
"key": "LOVE-XX",
504+
"fields": {
505+
"summary": "Issue title",
506+
TIME_LOST_FIELD: 13.6,
507+
"creator": {"displayName": "user"},
508+
"created": "2022-07-03T19:58:13.00000",
509+
},
510+
}
511+
]
512+
}
513+
mock_jira_client.return_value = response
514+
515+
request_data = {
516+
"day_obs": 20240902,
517+
}
518+
jira_response = get_jira_obs_report(request_data)
519+
assert jira_response[0]["key"] == "LOVE-XX"
520+
assert jira_response[0]["summary"] == "Issue title"
521+
assert jira_response[0]["time_lost"] == 13.6
522+
assert jira_response[0]["reporter"] == "user"
523+
assert jira_response[0]["created"] == "2022-07-03T19:58:13"
524+
525+
mock_jira_patcher.stop()
526+
527+
def test_get_jira_obs_report_fail(self):
528+
"""Test call to get_jira_obs_report function with fail response"""
529+
mock_jira_patcher = patch("requests.get")
530+
mock_jira_client = mock_jira_patcher.start()
531+
response = requests.Response()
532+
response.status_code = 400
533+
mock_jira_client.return_value = response
534+
535+
request_data = {
536+
"day_obs": 20240902,
537+
}
538+
with pytest.raises(Exception):
539+
get_jira_obs_report(request_data)
540+
541+
mock_jira_patcher.stop()
542+
543+
def test_get_jira_obs_report_bad_date(self):
544+
"""Test call to get_jira_obs_report function with bad date"""
545+
request_data = {
546+
"day_obs": 20240931,
547+
}
548+
with pytest.raises(ValueError):
549+
get_jira_obs_report(request_data)

manager/manager/utils.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,11 @@ def get_jira_obs_report(request_data):
656656
Then get the total observation time loss from the time_lost param
657657
"""
658658

659-
initial_day_obs_string = get_obsday_iso(request_data.get("day_obs"))
660-
final_day_obs_string = get_obsday_iso(request_data.get("day_obs") + 1)
659+
intitial_day_obs_tai = get_obsday_to_tai(request_data.get("day_obs"))
660+
final_day_obs_tai = intitial_day_obs_tai + timedelta(days=1)
661+
662+
initial_day_obs_string = intitial_day_obs_tai.strftime("%Y-%m-%d")
663+
final_day_obs_string = final_day_obs_tai.strftime("%Y-%m-%d")
661664

662665
# JQL query to find issues created on a specific date
663666
jql_query = (
@@ -733,6 +736,25 @@ def get_obsday_from_tai(tai):
733736
return observing_day
734737

735738

739+
def get_obsday_to_tai(obsday):
740+
"""Return the TAI timestamp from an observing day.
741+
742+
The TAI timestamp is set to 12:00 UTC of the observing day.
743+
744+
Parameters
745+
----------
746+
obsday : `int`
747+
The observing day in the format "YYYYMMDD" as an integer
748+
749+
Returns
750+
-------
751+
`datetime.datetime`
752+
The TAI timestamp
753+
"""
754+
obsday_iso = get_obsday_iso(obsday)
755+
return Time(f"{obsday_iso}T12:00:00", scale="tai").datetime
756+
757+
736758
def get_obsday_iso(obsday):
737759
"""Return the observing day in ISO format.
738760

0 commit comments

Comments
 (0)