Skip to content

Commit

Permalink
Merge pull request #1014 from acamacho82/Issue-1008
Browse files Browse the repository at this point in the history
Adding user delete command and unittests
  • Loading branch information
allmightyspiff committed Aug 2, 2018
2 parents 0190093 + de21d24 commit b065939
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
('user:edit-permissions', 'SoftLayer.CLI.user.edit_permissions:cli'),
('user:edit-details', 'SoftLayer.CLI.user.edit_details:cli'),
('user:create', 'SoftLayer.CLI.user.create:cli'),
('user:delete', 'SoftLayer.CLI.user.delete:cli'),

('vlan', 'SoftLayer.CLI.vlan'),
('vlan:detail', 'SoftLayer.CLI.vlan.detail:cli'),
Expand Down
32 changes: 32 additions & 0 deletions SoftLayer/CLI/user/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Delete user."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import helpers


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Sets a user's status to CANCEL_PENDING, which will immediately disable the account,
and will eventually be fully removed from the account by an automated internal process.
Example: slcli user delete userId
"""

mgr = SoftLayer.UserManager(env.client)

user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username')

user_template = {'userStatusId': 1021}

result = mgr.edit_user(user_id, user_template)
if result:
click.secho("%s deleted successfully" % identifier, fg='green')
else:
click.secho("Failed to delete %s" % identifier, fg='red')
19 changes: 19 additions & 0 deletions tests/CLI/modules/user_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,22 @@ def test_edit_details_bad_json(self):
result = self.run_command(['user', 'edit-details', '1234', '-t', '{firstName:"Supermand"}'])
self.assertIn("Argument Error", result.exception.message)
self.assertEqual(result.exit_code, 2)

"""User delete tests"""
@mock.patch('SoftLayer.CLI.user.delete.click')
def test_delete(self, click):
result = self.run_command(['user', 'delete', '12345'])
click.secho.assert_called_with('12345 deleted successfully', fg='green')
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_User_Customer', 'editObject',
args=({'userStatusId': 1021},), identifier=12345)

@mock.patch('SoftLayer.CLI.user.delete.click')
def test_delete_failure(self, click):
mock = self.set_mock('SoftLayer_User_Customer', 'editObject')
mock.return_value = False
result = self.run_command(['user', 'delete', '12345'])
click.secho.assert_called_with('Failed to delete 12345', fg='red')
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_User_Customer', 'editObject',
args=({'userStatusId': 1021},), identifier=12345)

0 comments on commit b065939

Please sign in to comment.