From f1e551309fbb9204ee0ae1af23d9de24491eb0c5 Mon Sep 17 00:00:00 2001 From: Nicola Farmer Date: Mon, 21 Oct 2024 11:48:27 +0100 Subject: [PATCH] Edit name of extract_tape_quota to get_tape_quota --- nlds/authenticators/base_authenticator.py | 2 +- nlds/authenticators/jasmin_authenticator.py | 2 +- nlds_processors/catalog/catalog_worker.py | 2 +- tests/nlds/test_jasmin_authenticator.py | 58 ++++++++++----------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/nlds/authenticators/base_authenticator.py b/nlds/authenticators/base_authenticator.py index dff4980a..6d49319e 100644 --- a/nlds/authenticators/base_authenticator.py +++ b/nlds/authenticators/base_authenticator.py @@ -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 diff --git a/nlds/authenticators/jasmin_authenticator.py b/nlds/authenticators/jasmin_authenticator.py index 3132f326..4f4f56e3 100644 --- a/nlds/authenticators/jasmin_authenticator.py +++ b/nlds/authenticators/jasmin_authenticator.py @@ -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) diff --git a/nlds_processors/catalog/catalog_worker.py b/nlds_processors/catalog/catalog_worker.py index e8370ad9..12a24dd0 100644 --- a/nlds_processors/catalog/catalog_worker.py +++ b/nlds_processors/catalog/catalog_worker.py @@ -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) diff --git a/tests/nlds/test_jasmin_authenticator.py b/tests/nlds/test_jasmin_authenticator.py index b07e9e65..0d34fe67 100644 --- a/tests/nlds/test_jasmin_authenticator.py +++ b/tests/nlds/test_jasmin_authenticator.py @@ -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 @@ -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 @@ -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 @@ -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): @@ -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): @@ -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): @@ -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.""" @@ -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.""" @@ -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).""" @@ -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")