Skip to content

Commit

Permalink
Edit name of extract_tape_quota to get_tape_quota
Browse files Browse the repository at this point in the history
  • Loading branch information
nf679 committed Oct 21, 2024
1 parent 2db7bbf commit f1e5513
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion nlds/authenticators/base_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ def get_service_information(self, oauth_token: str, service_name: str):
"""Get the information about the given service."""
return NotImplementedError

def extract_tape_quota(self, oauth_token: str, service_name: str):
def get_tape_quota(self, oauth_token: str, service_name: str):
"""Process the service inforrmation to return the tape quota value."""
return NotImplementedError
2 changes: 1 addition & 1 deletion nlds/authenticators/jasmin_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def get_service_information(self, oauth_token: str, service_name: str):
raise RuntimeError(f"Error getting data for {service_name}")


def extract_tape_quota(self, oauth_token: str, service_name: str):
def get_tape_quota(self, oauth_token: str, service_name: str):
"""Get the service information then process it to extract the quota for the service."""
try:
result = self.get_service_information(self, oauth_token, service_name)
Expand Down
2 changes: 1 addition & 1 deletion nlds_processors/catalog/catalog_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ def _catalog_quota(self, body: Dict, properties: Header) -> None:
user, group, token = message_vars

try:
group_quota = Authenticator.extract_tape_quota(oauth_token=token, service_name=group)
group_quota = Authenticator.get_tape_quota(oauth_token=token, service_name=group)
except CatalogError as e:
# failed to get the holdings - send a return message saying so
self.log(e.message, self.RK_LOG_ERROR)
Expand Down
58 changes: 29 additions & 29 deletions tests/nlds/test_jasmin_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ def mock_get(*args, **kwargs):
JasminAuthenticator.get_projects_services("dummy_oauth_token", "test_service")


class TestExtractTapeQuota:
class TestGetTapeQuota:
"""Get the tape quota from the list of projects services."""

def test_extract_tape_quota_success(monkeypatch):
"""Test a successful instance of extract_tape_quota"""
def test_get_tape_quota_success(monkeypatch):
"""Test a successful instance of get_tape_quota"""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to gvie the response for
Expand All @@ -433,12 +433,12 @@ def mock_get_projects_services(*args, **kwargs):

monkeypatch.setattr("jasmin_authenticator.JasminAuthenticator.get_projects_services", mock_get_projects_services)

# extract_tape_quota should return the quota value of 100
result = JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
# get_tape_quota should return the quota value of 100
result = JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")
assert result == 100

def test_extract_tape_quota_no_requirements(monkeypatch, quotas):
"""Test an unsuccessful instance of extract_tape_quota due to no requirements."""
def test_get_tape_quota_no_requirements(monkeypatch, quotas):
"""Test an unsuccessful instance of get_tape_quota due to no requirements."""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to give the response for
Expand All @@ -449,10 +449,10 @@ def mock_get_projects_services(*args, **kwargs):

# A ValueError should be raised saying there's no requirements found.
with pytest.raises(ValueError, match="Cannot find any requirements for test_service"):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_no_tape_resource(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to no tape resources."""
def test_get_tape_quota_no_tape_resource(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to no tape resources."""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to give the response for
Expand All @@ -472,10 +472,10 @@ def mock_get_projects_services(*args, **kwargs):
with pytest.raises(
ValueError, match="No tape resources could be found for test_service"
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_services_runtime_error(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to a runtime error when
def test_get_tape_quota_services_runtime_error(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to a runtime error when
getting services from the projects portal."""

def mock_get_projects_services(*args, **kwargs):
Expand All @@ -489,10 +489,10 @@ def mock_get_projects_services(*args, **kwargs):
RuntimeError,
match="Error getting information for test_service: Runtime error occurred",
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_services_value_error(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to a value error
def test_get_tape_quota_services_value_error(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to a value error
getting services from the projects portal."""

def mock_get_projects_services(*args, **kwargs):
Expand All @@ -506,10 +506,10 @@ def mock_get_projects_services(*args, **kwargs):
ValueError,
match="Error getting information for test_service: Value error occurred",
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_no_gws(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to the given service
def test_get_tape_quota_no_gws(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to the given service
not being a GWS."""

def mock_get_projects_services(*args, **kwargs):
Expand All @@ -526,10 +526,10 @@ def mock_get_projects_services(*args, **kwargs):
ValueError,
match="Cannot find a Group Workspace with the name test_service. Check the category.",
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_quota_zero_quota(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to the quota being zero."""
def get_quota_zero_quota(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to the quota being zero."""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to give a quota of 0."""
Expand All @@ -552,10 +552,10 @@ def mock_get_projects_services(*args, **kwargs):
with pytest.raises(
ValueError, match="Issue getting tape quota for test_service. Quota is zero."
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_no_quota(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to there being no quota field."""
def test_get_tape_quota_no_quota(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to there being no quota field."""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to give no 'amount field."""
Expand All @@ -578,10 +578,10 @@ def mock_get_projects_services(*args, **kwargs):
KeyError,
match="Issue getting tape quota for test_service. No 'value' field exists.",
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

def test_extract_tape_quota_no_provisioned_resources(monkeypatch):
"""Test an unsuccessful instance of extract_tape_quota due to there being no provisioned resources."""
def test_get_tape_quota_no_provisioned_resources(monkeypatch):
"""Test an unsuccessful instance of get_tape_quota due to there being no provisioned resources."""

def mock_get_projects_services(*args, **kwargs):
"""Mock the response from get_projects_services to give no provisioned resources (status 50)."""
Expand All @@ -604,4 +604,4 @@ def mock_get_projects_services(*args, **kwargs):
ValueError,
match="No provisioned requirements found for test_service. Check the status of your requested resources.",
):
JasminAuthenticator.extract_tape_quota("dummy_oauth_token", "test_service")
JasminAuthenticator.get_tape_quota("dummy_oauth_token", "test_service")

0 comments on commit f1e5513

Please sign in to comment.