Skip to content

Commit

Permalink
Remove JIRA fields ids mapping from manager and keep it only in the f…
Browse files Browse the repository at this point in the history
…rontend
  • Loading branch information
sebastian-aranda committed Nov 6, 2023
1 parent 8cecc2f commit 4d966a1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 65 deletions.
65 changes: 53 additions & 12 deletions manager/api/tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,49 @@
# this program. If not, see <http://www.gnu.org/licenses/>.


import math
import random
from unittest.mock import patch

import requests
from api.views import jira_comment, jira_ticket
from django.test import TestCase, override_settings

from manager.utils import (
OLE_JIRA_OBS_COMPONENTS_FIELDS,
OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS,
OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS,
)
OLE_JIRA_OBS_COMPONENTS_FIELDS = [
"AuxTel",
"Calibrations",
"Environmental Monitoring Systems",
"Facilities",
"IT Infrastricture",
"MainTel",
"Observer Remark",
"Other",
"Unknown",
]

OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS = [
"None",
"CSC level",
"Component Level (EUI)",
"Visualization",
"Analysis",
"Other",
"Camera Control Software",
]

OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS = [
"None",
"Mount",
"Rotator",
"Hexapod",
"M2",
"Science Cameras",
"M1M3",
"Dome",
"Utilities",
"Calibration",
"Other",
]


@override_settings(DEBUG=True)
Expand Down Expand Up @@ -67,13 +98,23 @@ def setUp(self):
}

request_narrative = {
"components": ",".join(list(OLE_JIRA_OBS_COMPONENTS_FIELDS.keys())[:2]),
"primary_software_components": list(
OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS.keys()
)[0],
"primary_hardware_components": list(
OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS.keys()
)[0],
"components": ",".join(
OLE_JIRA_OBS_COMPONENTS_FIELDS[
: math.ceil(random.random() * len(OLE_JIRA_OBS_COMPONENTS_FIELDS))
]
),
"primary_software_components": OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS[
math.ceil(
random.random()
* len(OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS)
)
],
"primary_hardware_components": OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS[
math.ceil(
random.random()
* len(OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS)
)
],
"date_begin": "2022-07-03T19:58:13.00000",
"date_end": "2022-07-04T19:25:13.00000",
"time_lost": 10,
Expand Down
66 changes: 13 additions & 53 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,6 @@
JSON_RESPONSE_LOCAL_STORAGE_NOT_ALLOWED = {"error": "Local storage not allowed."}
JSON_RESPONSE_ERROR_NOT_VALID_JSON = {"error": "Not a valid JSON response."}

# Mappings
OLE_JIRA_OBS_COMPONENTS_FIELDS = {
"AuxTel": 20710,
"Calibrations": 20714,
"Environmental Monitoring Systems": 20711,
"Facilities": 20712,
"IT Infrastricture": 20718,
"MainTel": 20709,
"Observer Remark": 20717,
"Other": 20713,
"Unknown": 19507,
}

OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS = {
"None": -1,
"CSC level": 16810,
"Component Level (EUI)": 16811,
"Visualization": 16812,
"Analysis": 16813,
"Other": 16814,
"Camera Control Software": 16815,
}

OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS = {
"None": -1,
"Mount": 16816,
"Rotator": 16817,
"Hexapod": 16818,
"M2": 16819,
"Science Cameras": 16820,
"M1M3": 16821,
"Dome": 16822,
"Utilities": 16825,
"Calibration": 16826,
"Other": 16827,
}


class LocationPermission(BasePermission):
"""Permission class to check if the user is in the location whitelist."""
Expand Down Expand Up @@ -432,24 +395,21 @@ def jira_ticket(request_data):
return Response({"ack": "Error reading request type"}, status=400)

tags_data = request_data.get("tags").split(",") if request_data.get("tags") else []
components_data = (
request_data.get("components").split(",")
if request_data.get("components")
components_ids = (
request_data.get("components_ids").split(",")
if request_data.get("components_ids")
else []
)
components_ids = [OLE_JIRA_OBS_COMPONENTS_FIELDS[c] for c in components_data]
primary_software_component_data = request_data.get(
"primary_software_components", "None"
primary_software_components_ids = (
request_data.get("primary_software_components_ids").split(",")
if request_data.get("primary_software_components_ids")
else []
)
primary_software_component_id = OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS[
primary_software_component_data
]
primary_hardware_component_data = request_data.get(
"primary_hardware_components", "None"
primary_hardware_components_ids = (
request_data.get("primary_hardware_components_ids").split(",")
if request_data.get("primary_hardware_components_ids")
else []
)
primary_hardware_component_id = OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS[
primary_hardware_component_data
]

try:
jira_payload = {
Expand All @@ -465,8 +425,8 @@ def jira_ticket(request_data):
if int(request_data.get("level", 0)) >= 100
else "off",
"customfield_16702": float(request_data.get("time_lost", 0)),
"customfield_17204": {"id": str(primary_software_component_id)},
"customfield_17205": {"id": str(primary_hardware_component_id)},
"customfield_17204": {"id": str(primary_software_components_ids[0])},
"customfield_17205": {"id": str(primary_hardware_components_ids[0])},
"issuetype": {"id": 12302},
},
"update": {
Expand Down

0 comments on commit 4d966a1

Please sign in to comment.