Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldor1510 committed Aug 15, 2024
1 parent 54ce8d9 commit 8c5af33
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/esi-leap-api-version-history.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# REST API Version History

## 1.0
This is the initial (and current) version of the API.
This is the initial (and current) version of the API.
6 changes: 3 additions & 3 deletions esi_leap/api/controllers/v1/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
MINOR_MAX_VERSION = MINOR_0_INITIAL_VERSION

# String representations of the minor and maximum versions
_MIN_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_0_INITIAL_VERSION)
_MAX_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_MAX_VERSION)
_MIN_VERSION_STRING = "{}.{}".format(BASE_VERSION, MINOR_0_INITIAL_VERSION)
_MAX_VERSION_STRING = "{}.{}".format(BASE_VERSION, MINOR_MAX_VERSION)


def min_version_string():
Expand All @@ -45,4 +45,4 @@ def min_version_string():

def max_version_string():
"""Returns the maximum supported API version (as a string)."""
return _MAX_VERSION_STRING
return _MAX_VERSION_STRING
16 changes: 7 additions & 9 deletions esi_leap/api/controllers/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Borrowed from Ironic

ID_VERSION1 = 'v1'
ID_VERSION1 = "v1"


def all_versions(host_url):
Expand All @@ -36,11 +36,9 @@ def default_version(host_url):
from esi_leap.api.controllers.v1 import versions

return {
'id': ID_VERSION1,
'links': [
{"href": "{0}/{1}".format(host_url, ID_VERSION1), "rel": "self"}
],
'status': 'CURRENT',
'min_version': versions.min_version_string(),
'version': versions.max_version_string()
}
"id": ID_VERSION1,
"links": [{"href": "{0}/{1}".format(host_url, ID_VERSION1), "rel": "self"}],
"status": "CURRENT",
"min_version": versions.min_version_string(),
"version": versions.max_version_string(),
}
2 changes: 1 addition & 1 deletion esi_leap/common/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def root(host_url):
"name": "ESI Leap API",
"description": "ESI Leap is an OpenStack service for leasing baremetal nodes, designed to run on top of multi-tenant Ironic.",
"default_version": version.default_version(host_url),
"versions": version.all_versions(host_url)
"versions": version.all_versions(host_url),
}


Expand Down
30 changes: 15 additions & 15 deletions esi_leap/tests/api/controllers/v1/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@
"""

import re
from unittest import mock

from esi_leap.api.controllers.v1 import versions
from esi_leap.tests import base


class TestVersionConstants(base.TestCase):

def setUp(self):
super(TestVersionConstants, self).setUp()

# Get all of our named constants. They all begin with r'MINOR_[0-9]'
self.minor_consts = [x for x in dir(versions)
if re.search(r'^MINOR_[0-9]', x)]
self.minor_consts = [x for x in dir(versions) if re.search(r"^MINOR_[0-9]", x)]

# Sort key needs to be an integer
def minor_key(x):
return int(x.split('_', 2)[1])
return int(x.split("_", 2)[1])

self.minor_consts.sort(key=minor_key)

def test_max_ver_str(self):
# Test to make sure _MAX_VERSION_STRING corresponds with the largest
# MINOR_ constant

max_ver = '1.{}'.format(getattr(versions, self.minor_consts[-1]))
max_ver = "1.{}".format(getattr(versions, self.minor_consts[-1]))
self.assertEqual(max_ver, versions._MAX_VERSION_STRING)

def test_min_ver_str(self):
# Try to make sure someone doesn't change the _MIN_VERSION_STRING by
# accident and make sure it exists
self.assertEqual('1.0', versions._MIN_VERSION_STRING)
self.assertEqual("1.0", versions._MIN_VERSION_STRING)

def test_name_value_match(self):
# Test to make sure variable name matches the value. For example
# MINOR_99_FOO should equal 99

for var_name in self.minor_consts:
version = int(var_name.split('_', 2)[1])
version = int(var_name.split("_", 2)[1])
self.assertEqual(
version, getattr(versions, var_name),
'Constant "{}" does not equal {}'.format(var_name, version))
version,
getattr(versions, var_name),
'Constant "{}" does not equal {}'.format(var_name, version),
)

def test_duplicates(self):
# Test to make sure no duplicates values
Expand All @@ -67,13 +67,13 @@ def test_duplicates(self):
for var_name in self.minor_consts:
value = getattr(versions, var_name)
self.assertNotIn(
value, seen_values,
'The value {} has been used more than once'.format(value))
value,
seen_values,
"The value {} has been used more than once".format(value),
)
seen_values.add(value)


class TestMaxVersionString(base.TestCase):

def test_max_version_not_pinned(self):
self.assertEqual(versions._MAX_VERSION_STRING,
versions.max_version_string())
self.assertEqual(versions._MAX_VERSION_STRING, versions.max_version_string())
2 changes: 1 addition & 1 deletion esi_leap/tests/common/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_root(self):
"name": "ESI Leap API",
"description": "ESI Leap is an OpenStack service for leasing baremetal nodes, designed to run on top of multi-tenant Ironic.",
"default_version": version.default_version(host_url),
"versions": version.all_versions(host_url)
"versions": version.all_versions(host_url),
}
result = health.root(host_url)
self.assertEqual(result, expected_result)
Expand Down

0 comments on commit 8c5af33

Please sign in to comment.