Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed May 22, 2024
1 parent 3746f7d commit 181087e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,43 @@ def test_inject_env_variables_with_secrets_found(
# mock_open().write.assert_called_once_with('key="secret-value"\n')


@patch("server.utils.os")
@patch("server.utils.requests")
def test_inject_env_variables_with_default_secrets_found(
mock_requests, mock_os, secrets_helper_instance, mocker
):
# Mocking necessary dependencies
mock_response1 = MagicMock()
mock_response1.status_code = 200
mock_response1.json.return_value = {"data": {"data": {}}}

mock_response2 = MagicMock()
mock_response2.status_code = 200
mock_response2.json.return_value = {"data": {"data": {"key": "secret-value"}}}

mock_requests.get.side_effect = [mock_response1, mock_response2]

mock_open = MagicMock()
mock_os.path.join.return_value = "/path/to/project/.env"
with patch("builtins.open", mock_open):
# Calling the method under test
secrets_helper_instance.inject_env_variables("/path/to/project")

# Assertions
assert mock_requests.get.call_args_list == [
call(
url="http://vault:8200/v1/kv/data/project_name/branch_name",
headers={"X-Vault-Token": "hvs.randomToken"},
),
call(
url="http://vault:8200/v1/kv/data/project_name/default-dev-secrets",
headers={"X-Vault-Token": "hvs.randomToken"},
),
]

mock_open.assert_called_once_with("/path/to/project/.env", "w")


@patch("server.utils.os")
@patch("server.utils.requests")
def test_inject_env_variables_with_no_secrets(
Expand Down

0 comments on commit 181087e

Please sign in to comment.