@@ -34,6 +34,18 @@ def mock_verify(mocker):
3434 return mocker .patch ("code42cli.cmds.profile.validate_connection" )
3535
3636
37+ @pytest .fixture
38+ def valid_connection (mock_verify ):
39+ mock_verify .return_value = True
40+ return mock_verify
41+
42+
43+ @pytest .fixture
44+ def invalid_connection (mock_verify ):
45+ mock_verify .return_value = False
46+ return mock_verify
47+
48+
3749def test_show_profile_outputs_profile_info (capsys , mock_cliprofile_namespace , profile ):
3850 profile .name = "testname"
3951 profile .authority_url = "example.com"
@@ -58,18 +70,6 @@ def test_show_profile_when_password_set_outputs_password_note(
5870 assert "A password is set" not in capture .out
5971
6072
61- def test_create_profile_if_profile_exists_exits (capsys , mock_cliprofile_namespace ):
62- mock_cliprofile_namespace .profile_exists .return_value = True
63- success = True
64- try :
65- profilecmd .create_profile ("foo" , "bar" , "baz" , True )
66- except SystemExit :
67- success = True
68- capture = capsys .readouterr ()
69- assert "already exists" in capture .out
70- assert success
71-
72-
7373def test_create_profile_if_user_sets_password_is_created (
7474 user_agreement , mock_verify , mock_cliprofile_namespace
7575):
@@ -86,7 +86,7 @@ def test_create_profile_if_user_does_not_set_password_is_created(
8686 mock_cliprofile_namespace .create_profile .assert_called_once_with ("foo" , "bar" , "baz" , True )
8787
8888
89- def test_create_profile_if_user_does_not_set_password_does_not_save_password (
89+ def test_create_profile_if_user_does_not_agree_does_not_save_password (
9090 user_disagreement , mock_verify , mock_cliprofile_namespace
9191):
9292 mock_cliprofile_namespace .profile_exists .return_value = False
@@ -95,9 +95,8 @@ def test_create_profile_if_user_does_not_set_password_does_not_save_password(
9595
9696
9797def test_create_profile_if_credentials_invalid_password_not_saved (
98- user_agreement , mock_verify , mock_cliprofile_namespace
98+ user_agreement , invalid_connection , mock_cliprofile_namespace
9999):
100- mock_verify .return_value = False
101100 mock_cliprofile_namespace .profile_exists .return_value = False
102101 success = False
103102 try :
@@ -109,14 +108,60 @@ def test_create_profile_if_credentials_invalid_password_not_saved(
109108
110109
111110def test_create_profile_if_credentials_valid_password_saved (
112- mocker , user_agreement , mock_verify , mock_cliprofile_namespace
111+ mocker , user_agreement , valid_connection , mock_cliprofile_namespace
113112):
114- mock_verify .return_value = True
115113 mock_cliprofile_namespace .profile_exists .return_value = False
116114 profilecmd .create_profile ("foo" , "bar" , "baz" , True )
117115 mock_cliprofile_namespace .set_password .assert_called_once_with ("newpassword" , mocker .ANY )
118116
119117
118+ def test_update_profile_updates_existing_profile (
119+ mock_cliprofile_namespace , user_agreement , valid_connection , profile
120+ ):
121+ name = "foo"
122+ profile .name = name
123+ mock_cliprofile_namespace .get_profile .return_value = profile
124+
125+ profilecmd .update_profile (name , "bar" , "baz" , True )
126+ mock_cliprofile_namespace .update_profile .assert_called_once_with (name , "bar" , "baz" , True )
127+
128+
129+ def test_update_profile_if_user_does_not_agree_does_not_save_password (
130+ mock_cliprofile_namespace , user_disagreement , invalid_connection , profile
131+ ):
132+ name = "foo"
133+ profile .name = name
134+ mock_cliprofile_namespace .get_profile .return_value = profile
135+ assert not mock_cliprofile_namespace .set_password .call_count
136+
137+
138+ def test_update_profile_if_credentials_invalid_password_not_saved (
139+ user_agreement , invalid_connection , mock_cliprofile_namespace , profile
140+ ):
141+ name = "foo"
142+ profile .name = name
143+ mock_cliprofile_namespace .get_profile .return_value = profile
144+
145+ success = False
146+ try :
147+ profilecmd .create_profile ("foo" , "bar" , "baz" , True )
148+ except SystemExit :
149+ success = True
150+ assert not mock_cliprofile_namespace .set_password .call_count
151+ assert success
152+
153+
154+ def test_update_profile_if_user_agrees_and_valid_connection_sets_password (
155+ mocker , user_agreement , valid_connection , mock_cliprofile_namespace , profile
156+ ):
157+ name = "foo"
158+ profile .name = name
159+ mock_cliprofile_namespace .get_profile .return_value = profile
160+
161+ profilecmd .update_profile (name , "bar" , "baz" , True )
162+ mock_cliprofile_namespace .set_password .assert_called_once_with ("newpassword" , mocker .ANY )
163+
164+
120165def test_prompt_for_password_reset_if_credentials_valid_password_saved (
121166 mocker , user_agreement , mock_verify , mock_cliprofile_namespace
122167):
0 commit comments