Skip to content

Commit 5111537

Browse files
author
Matthew Fisher
committed
feat(client): add flags for automating auth:cancel
1 parent c9eb523 commit 5111537

3 files changed

Lines changed: 18 additions & 36 deletions

File tree

client/deis.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,29 @@ def auth_cancel(self, args):
745745
"""
746746
Cancels and removes the current account.
747747
748-
Usage: deis auth:cancel
748+
Usage: deis auth:cancel [options]
749+
750+
Options:
751+
--username=<username>
752+
provide a username for the account.
753+
--password=<password>
754+
provide a password for the account.
755+
--yes
756+
force "yes" when prompted.
749757
"""
750758
controller = self._settings.get('controller')
751759
if not controller:
752760
self._logger.error('Not logged in to a Deis controller')
753761
sys.exit(1)
754762
self._logger.info('Please log in again in order to cancel this account')
755-
username = self.auth_login({'<controller>': controller})
763+
args['<controller>'] = controller
764+
username = self.auth_login(args)
756765
if username:
757-
confirm = raw_input("Cancel account \"{}\" at {}? (y/N) ".format(username, controller))
758-
if confirm == 'y':
766+
confirm = args.get('--yes')
767+
if not confirm:
768+
confirm = raw_input(
769+
"Cancel account \"{}\" at {}? (y/N) ".format(username, controller))
770+
if confirm in ['y', True]:
759771
self._dispatch('delete', '/v1/auth/cancel')
760772
self._settings['controller'] = None
761773
self._settings['token'] = None

tests/auth_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var (
1212
authLoginCmd = "auth:login http://deis.{{.Domain}} --username={{.UserName}} --password={{.Password}}"
1313
authLogoutCmd = "auth:logout"
1414
authRegisterCmd = "auth:register http://deis.{{.Domain}} --username={{.UserName}} --password={{.Password}} --email={{.Email}}"
15+
authCancelCmd = "auth:cancel --username={{.UserName}} --password={{.Password}} --yes"
1516
)
1617

1718
func TestAuth(t *testing.T) {
@@ -31,7 +32,7 @@ func authSetup(t *testing.T) *utils.DeisTestConfig {
3132
}
3233

3334
func authCancel(t *testing.T, params *utils.DeisTestConfig) {
34-
utils.AuthCancel(t, params)
35+
utils.Execute(t, authCancelCmd, params, false, "Account cancelled")
3536
}
3637

3738
func authLoginTest(t *testing.T, params *utils.DeisTestConfig) {

tests/utils/itutils.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,6 @@ func CurlWithFail(t *testing.T, params *DeisTestConfig, failFlag bool, expect st
143143
}
144144
}
145145

146-
// AuthCancel tests whether `deis auth:cancel` destroys a user's account.
147-
func AuthCancel(t *testing.T, params *DeisTestConfig) {
148-
fmt.Println("deis auth:cancel")
149-
child, err := gexpect.Spawn(Deis + " auth:cancel")
150-
if err != nil {
151-
t.Fatalf("command not started\n%v", err)
152-
}
153-
fmt.Println("username:")
154-
err = child.Expect("username:")
155-
if err != nil {
156-
t.Fatalf("expect username failed\n%v", err)
157-
}
158-
child.SendLine(params.UserName)
159-
fmt.Print("password:")
160-
err = child.Expect("password:")
161-
if err != nil {
162-
t.Fatalf("expect password failed\n%v", err)
163-
}
164-
child.SendLine(params.Password)
165-
err = child.ExpectRegex("(y/N)")
166-
if err != nil {
167-
t.Fatalf("expect cancel \n%v", err)
168-
}
169-
child.SendLine("y")
170-
err = child.Expect("Account cancelled")
171-
if err != nil {
172-
t.Fatalf("command executiuon failed\n%v", err)
173-
}
174-
child.Close()
175-
}
176-
177146
// AuthPasswd tests whether `deis auth:passwd` updates a user's password.
178147
func AuthPasswd(t *testing.T, params *DeisTestConfig, password string) {
179148
fmt.Println("deis auth:passwd")

0 commit comments

Comments
 (0)