Skip to content

Commit 53cf4b3

Browse files
authored
feature/205-profile-update (#246)
1 parent d71a2f5 commit 53cf4b3

File tree

4 files changed

+68
-19
lines changed

4 files changed

+68
-19
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11+
## Unreleased
12+
13+
### Changed
14+
15+
- Command options for `profile update`:
16+
- `-n` `--name` is not required, and if omitted with use default profile.
17+
- `-s` `--server` and `-u` `--username` are not required and can be updated independently now.
18+
- Example: `code42 profile update -s 1.2.3.4:1234`
19+
1120
## 1.3.0 - 2021-02-11
1221

1322
### Fixed

src/code42cli/cmds/profile.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,32 @@ def profile_name_arg(required=False):
2222
return click.argument("profile_name", required=required)
2323

2424

25-
name_option = click.option(
26-
"-n",
27-
"--name",
28-
required=True,
29-
help="The name of the Code42 CLI profile to use when executing this command.",
30-
)
31-
server_option = click.option(
32-
"-s", "--server", required=True, help="The URL you use to sign into Code42.",
33-
)
25+
def name_option(required=False):
26+
return click.option(
27+
"-n",
28+
"--name",
29+
required=required,
30+
help="The name of the Code42 CLI profile to use when executing this command.",
31+
)
32+
33+
34+
def server_option(required=False):
35+
return click.option(
36+
"-s",
37+
"--server",
38+
required=required,
39+
help="The URL you use to sign into Code42.",
40+
)
41+
42+
43+
def username_option(required=False):
44+
return click.option(
45+
"-u",
46+
"--username",
47+
required=required,
48+
help="The username of the Code42 API user.",
49+
)
3450

35-
username_option = click.option(
36-
"-u", "--username", required=True, help="The username of the Code42 API user.",
37-
)
3851

3952
password_option = click.option(
4053
"--password",
@@ -66,9 +79,9 @@ def show(profile_name):
6679

6780

6881
@profile.command()
69-
@name_option
70-
@server_option
71-
@username_option
82+
@name_option(required=True)
83+
@server_option(required=True)
84+
@username_option(required=True)
7285
@password_option
7386
@yes_option(hidden=True)
7487
@disable_ssl_option
@@ -83,9 +96,9 @@ def create(name, server, username, password, disable_ssl_errors):
8396

8497

8598
@profile.command()
86-
@name_option
87-
@server_option
88-
@username_option
99+
@name_option()
100+
@server_option()
101+
@username_option()
89102
@password_option
90103
@disable_ssl_option
91104
def update(name, server, username, password, disable_ssl_errors):

src/code42cli/profile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def switch_default_profile(profile_name):
102102
def create_profile(name, server, username, ignore_ssl_errors):
103103
if profile_exists(name):
104104
raise Code42CLIError("A profile named '{}' already exists.".format(name))
105-
106105
config_accessor.create_profile(name, server, username, ignore_ssl_errors)
107106

108107

tests/cmds/test_profile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ def test_update_profile_updates_existing_profile(
254254
)
255255

256256

257+
def test_update_profile_updates_default_profile(
258+
runner, mock_cliprofile_namespace, user_agreement, valid_connection, profile
259+
):
260+
name = "foo"
261+
profile.name = name
262+
mock_cliprofile_namespace.get_profile.return_value = profile
263+
runner.invoke(
264+
cli, ["profile", "update", "-s", "bar", "-u", "baz", "--disable-ssl-errors"],
265+
)
266+
mock_cliprofile_namespace.update_profile.assert_called_once_with(
267+
name, "bar", "baz", True
268+
)
269+
270+
271+
def test_update_profile_updates_name_alone(
272+
runner, mock_cliprofile_namespace, user_agreement, valid_connection, profile
273+
):
274+
name = "foo"
275+
profile.name = name
276+
mock_cliprofile_namespace.get_profile.return_value = profile
277+
runner.invoke(
278+
cli, ["profile", "update", "-u", "baz", "--disable-ssl-errors"],
279+
)
280+
mock_cliprofile_namespace.update_profile.assert_called_once_with(
281+
name, None, "baz", True
282+
)
283+
284+
257285
def test_update_profile_if_user_does_not_agree_does_not_save_password(
258286
runner, mock_cliprofile_namespace, user_disagreement, invalid_connection, profile
259287
):

0 commit comments

Comments
 (0)