Post-review fixes

This commit is contained in:
Kirill Zhukov 2023-01-19 22:13:04 +01:00
parent b2a3e5ac70
commit 23ba530ada

View File

@ -1,6 +1,7 @@
"""
albs.py contains ALBS class
"""
from urllib.parse import urljoin
from typing import Union, Dict
import requests
@ -12,8 +13,6 @@ class ALBS:
"""
def __init__(self, url: str, token: str, timeout: int):
if url.endswith('/'):
url = url[:-1]
self.url = url
self.token = token
self.timeout = timeout
@ -27,13 +26,12 @@ class ALBS:
endpoint = '/api/v1/platforms/'
headers = {'accept': 'application/json',
'Authorization': f'Bearer {self.token}'}
response = requests.get(url=self.url+endpoint,
response = requests.get(url=urljoin(self.url, endpoint),
headers=headers,
timeout=self.timeout)
response.raise_for_status()
res = {}
for platform in response.json():
res[platform['name']] = platform['id']
res = {platform['name']: platform['id']
for platform in response.json()}
return res
def get_errata_status(self, errata_id: str, platform_name: str) -> Union[str, None]:
@ -60,7 +58,7 @@ class ALBS:
params = {'id': errata_id, 'platformId': platform_id}
headers = {'accept': 'application/json',
'Authorization': f'Bearer {self.token}'}
response = requests.get(url=self.url+endpoint,
response = requests.get(url=urljoin(self.url, endpoint),
params=params, headers=headers,
timeout=self.timeout)
response.raise_for_status()
@ -68,5 +66,5 @@ class ALBS:
# errata_id was not found
if response_json['total_records'] == 0:
return None
return
return response_json['records'][0]['release_status']