Skip to content

Commit

Permalink
remove some unneeded comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Sandel authored and Florian Sandel committed Aug 29, 2024
1 parent 8cff2bc commit 6979100
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions certbot_dns_stackit/test_stackit.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,24 @@ def setUp(self):
def test_setup_credentials_with_service_account(
self, mock_configure_credentials, mock_conf
):
# Simulate `service_account` being set
mock_conf.return_value = "service_account_value"

self.authenticator._setup_credentials()

# Assert _configure_credentials was not called
mock_configure_credentials.assert_not_called()
# Assert service_account is set correctly
self.assertEqual(self.authenticator.service_account, "service_account_value")

@patch.object(Authenticator, "conf")
@patch.object(Authenticator, "_configure_credentials")
def test_setup_credentials_without_service_account(
self, mock_configure_credentials, mock_conf
):
# Simulate `service_account` not being set
mock_conf.return_value = None
mock_creds = Mock()
mock_configure_credentials.return_value = mock_creds

self.authenticator._setup_credentials()

# Assert _configure_credentials was called with the correct arguments
mock_configure_credentials.assert_called_once_with(
"credentials",
"STACKIT credentials for the STACKIT DNS API",
Expand All @@ -256,7 +251,6 @@ def test_setup_credentials_without_service_account(
"records in the zone",
},
)
# Assert credentials are set correctly
self.assertEqual(self.authenticator.credentials, mock_creds)

@patch.object(Authenticator, "_get_stackit_client")
Expand Down Expand Up @@ -309,6 +303,7 @@ def test_load_service_file(self, mock_load_service_file):
@patch("logging.error")
def test_load_service_file_not_found(self, mock_log, mock_file):
result = self.authenticator._load_service_file("nonexistent_path")

self.assertIsNone(result)
mock_log.assert_called()

Expand All @@ -321,6 +316,7 @@ def test_generate_jwt(self, mock_jwt_encode):
"kid": "key_id",
"privateKey": "private_key",
}

self.authenticator._generate_jwt(credentials)
mock_jwt_encode.assert_called()

Expand All @@ -332,21 +328,19 @@ def test_generate_jwt_fail(self):
"kid": "key_id",
"privateKey": "not_a_valid_key",
}

with self.assertRaises(jwt.exceptions.InvalidKeyError):
token = self.authenticator._generate_jwt(credentials)
self.assertIsNone(token)

@patch("requests.post")
def test_request_access_token_success(self, mock_post):
mock_response = mock_post.return_value
mock_response.raise_for_status = (
lambda: None
) # Mock raise_for_status to do nothing
mock_response.raise_for_status = lambda: None
mock_response.json.return_value = {"access_token": "mocked_access_token"}

result = self.authenticator._request_access_token("jwt_token_example")

# Assertions
mock_post.assert_called_once_with(
"https://service-account.api.stackit.cloud/token",
data={
Expand All @@ -366,7 +360,6 @@ def test_request_access_token_failure_raises_http_error(self, mock_post):

with self.assertRaises(errors.PluginError):
self.authenticator._request_access_token("jwt_token_example")

mock_post.assert_called_once()

@patch(
Expand Down

0 comments on commit 6979100

Please sign in to comment.