Skip to content

Commit cd2b139

Browse files
committed
Load credentials from env or ini file, to match local testing behavior
1 parent 49e9872 commit cd2b139

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

src/datacustomcode/cli.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ def zip(path: str):
7979

8080

8181
@cli.command()
82-
@click.option("--profile", default="default")
8382
@click.option("--path", default="payload")
8483
@click.option("--name", required=True)
8584
@click.option("--version", default="0.0.1")
8685
@click.option("--description", default="Custom Data Transform Code")
87-
def deploy(profile: str, path: str, name: str, version: str, description: str):
86+
def deploy(path: str, name: str, version: str, description: str):
8887
from datacustomcode.credentials import Credentials
8988
from datacustomcode.deploy import TransformationJobMetadata, deploy_full
9089

@@ -96,11 +95,10 @@ def deploy(profile: str, path: str, name: str, version: str, description: str):
9695
description=description,
9796
)
9897
try:
99-
credentials = Credentials.from_ini(profile=profile)
100-
except KeyError:
98+
credentials = Credentials.from_available()
99+
except ValueError as e:
101100
click.secho(
102-
f"Error: Profile {profile} not found in credentials.ini. "
103-
"Run `datacustomcode configure` to create a credentialsprofile.",
101+
f"Error: {e}",
104102
fg="red",
105103
)
106104
raise click.Abort() from None

tests/test_cli.py

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from click.testing import CliRunner
66

7-
from datacustomcode.cli import init
7+
from datacustomcode.cli import init, deploy
88

99

1010
class TestInit:
@@ -47,3 +47,83 @@ def test_init_command(self, mock_file, mock_scan, mock_copy):
4747
)
4848
expected_content = json.dumps(mock_scan.return_value, indent=2)
4949
assert written_content == expected_content
50+
51+
52+
class TestDeploy:
53+
@patch("datacustomcode.deploy.deploy_full")
54+
@patch("datacustomcode.credentials.Credentials.from_available")
55+
def test_deploy_command_success(self, mock_credentials, mock_deploy_full):
56+
"""Test successful deploy command."""
57+
# Mock credentials
58+
mock_creds = mock_credentials.return_value
59+
60+
runner = CliRunner()
61+
with runner.isolated_filesystem():
62+
# Create test payload directory
63+
os.makedirs("payload", exist_ok=True)
64+
65+
result = runner.invoke(deploy, ["--name", "test-job", "--version", "1.0.0"])
66+
67+
assert result.exit_code == 0
68+
mock_credentials.assert_called_once()
69+
mock_deploy_full.assert_called_once()
70+
71+
# Check that deploy_full was called with correct arguments
72+
call_args = mock_deploy_full.call_args
73+
assert call_args[0][0] == "payload" # path
74+
assert call_args[0][1].name == "test-job" # metadata
75+
assert call_args[0][1].version == "1.0.0"
76+
assert call_args[0][1].description == "Custom Data Transform Code"
77+
assert call_args[0][2] == mock_creds # credentials
78+
79+
@patch("datacustomcode.credentials.Credentials.from_available")
80+
def test_deploy_command_credentials_error(self, mock_credentials):
81+
"""Test deploy command when credentials are not available."""
82+
# Mock credentials to raise ValueError
83+
mock_credentials.side_effect = ValueError("Credentials not found in env or ini file. Run `datacustomcode configure` to create a credentials file.")
84+
85+
runner = CliRunner()
86+
with runner.isolated_filesystem():
87+
# Create test payload directory
88+
os.makedirs("payload", exist_ok=True)
89+
90+
result = runner.invoke(deploy, ["--name", "test-job"])
91+
92+
assert result.exit_code == 1
93+
assert "Error: Credentials not found in env or ini file" in result.output
94+
95+
@patch("datacustomcode.deploy.deploy_full")
96+
@patch("datacustomcode.credentials.Credentials.from_available")
97+
def test_deploy_command_custom_path(self, mock_credentials, mock_deploy_full):
98+
"""Test deploy command with custom path."""
99+
runner = CliRunner()
100+
with runner.isolated_filesystem():
101+
# Create test directory
102+
os.makedirs("custom_path", exist_ok=True)
103+
104+
result = runner.invoke(deploy, ["--path", "custom_path", "--name", "test-job"])
105+
106+
assert result.exit_code == 0
107+
mock_deploy_full.assert_called_once()
108+
109+
# Check that deploy_full was called with custom path
110+
call_args = mock_deploy_full.call_args
111+
assert call_args[0][0] == "custom_path" # path
112+
113+
@patch("datacustomcode.deploy.deploy_full")
114+
@patch("datacustomcode.credentials.Credentials.from_available")
115+
def test_deploy_command_custom_description(self, mock_credentials, mock_deploy_full):
116+
"""Test deploy command with custom description."""
117+
runner = CliRunner()
118+
with runner.isolated_filesystem():
119+
# Create test payload directory
120+
os.makedirs("payload", exist_ok=True)
121+
122+
result = runner.invoke(deploy, ["--name", "test-job", "--description", "Custom description"])
123+
124+
assert result.exit_code == 0
125+
mock_deploy_full.assert_called_once()
126+
127+
# Check that deploy_full was called with custom description
128+
call_args = mock_deploy_full.call_args
129+
assert call_args[0][1].description == "Custom description"

0 commit comments

Comments
 (0)