Skip to content

Commit 6bd61d8

Browse files
caberoscaberos
authored andcommitted
fix team code review comments
1 parent 7b826af commit 6bd61d8

File tree

7 files changed

+54
-17
lines changed

7 files changed

+54
-17
lines changed

SoftLayer/CLI/email/detail.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
"""Display details for a specified email."""
1+
"""Display details for a specified email account."""
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5+
from SoftLayer.CLI.email.list import build_statistics_table
56
from SoftLayer.CLI import environment
67
from SoftLayer.CLI import formatting
78
from SoftLayer.managers.email import EmailManager
@@ -23,11 +24,17 @@ def cli(env, identifier):
2324

2425
table.add_row(['id', result.get('id')])
2526
table.add_row(['username', result.get('username')])
27+
table.add_row(['email_address', result.get('emailAddress')])
2628
table.add_row(['create_date', result.get('createDate')])
27-
table.add_row(['categoryCode', utils.lookup(result, 'billingItem', 'categoryCode')])
29+
table.add_row(['category_code', utils.lookup(result, 'billingItem', 'categoryCode')])
2830
table.add_row(['description', utils.lookup(result, 'billingItem', 'description')])
2931
table.add_row(['type_description', utils.lookup(result, 'type', 'description')])
3032
table.add_row(['type', utils.lookup(result, 'type', 'keyName')])
3133
table.add_row(['vendor', utils.lookup(result, 'vendor', 'keyName')])
3234

35+
statistics = email_manager.get_statistics(identifier)
36+
37+
for statistic in statistics:
38+
table.add_row(['statistics', build_statistics_table(statistic)])
39+
3340
env.fout(table)

SoftLayer/CLI/email/edit.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@
1010

1111
@click.command()
1212
@click.argument('identifier')
13-
@click.option('--username', help="username account")
14-
@click.option('--email', help="Additional note for the image")
13+
@click.option('--username', help="Sets username for this account")
14+
@click.option('--email', help="Sets the contact email for this account")
1515
@click.option('--password',
1616
help="Password must be between 8 and 20 characters "
1717
"and must contain one letter and one number.")
1818
@environment.pass_env
1919
def cli(env, identifier, username, email, password):
2020
"""Edit details of an email delivery account."""
21+
email_manager = EmailManager(env.client)
22+
2123
data = {}
24+
update = False
25+
if email:
26+
if email_manager.update_email(identifier, email):
27+
update = True
28+
else:
29+
raise exceptions.CLIAbort("Failed to Edit emailAddress account")
2230
if username:
2331
data['username'] = username
24-
if email:
25-
data['emailAddress'] = email
2632
if password:
2733
data['password'] = password
34+
if len(data) != 0:
35+
if email_manager.editObject(identifier, **data):
36+
update = True
37+
else:
38+
raise exceptions.CLIAbort("Failed to Edit email account")
2839

29-
email_manager = EmailManager(env.client)
30-
31-
if not email_manager.editObject(identifier, data):
32-
raise exceptions.CLIAbort("Failed to Edit email account")
40+
if update:
41+
env.fout('Updated Successfully')

SoftLayer/CLI/email/list.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,29 @@ def cli(env):
3636
table.add_row(['email_information', table_information])
3737
table.add_row(['email_overview', overview_table])
3838
for statistic in statistics:
39-
table.add_row(['statistics', _build_statistics_table(statistic)])
39+
table.add_row(['statistics', build_statistics_table(statistic)])
4040

4141
env.fout(table)
4242

4343

4444
def _build_overview_table(email_overview):
45-
table = formatting.Table(['credit_Allowed', 'credits_Remain', 'package', 'reputation', 'requests'])
45+
table = formatting.Table(
46+
['credit_allowed', 'credits_remain', 'credits_overage', 'credits_used',
47+
'package', 'reputation', 'requests'])
4648
table.align['name'] = 'r'
4749
table.align['value'] = 'l'
4850

4951
table.add_row([email_overview.get('creditsAllowed'), email_overview.get('creditsRemain'),
52+
email_overview.get('creditsOverage'), email_overview.get('creditsUsed'),
5053
email_overview.get('package'), email_overview.get('reputation'),
5154
email_overview.get('requests')])
5255

5356
return table
5457

5558

56-
def _build_statistics_table(statistics):
57-
table = formatting.Table(['delivered', 'requests', 'bounces', 'opens', 'clicks', 'spamReports'])
59+
def build_statistics_table(statistics):
60+
"""statistics records of Email Delivery account"""
61+
table = formatting.Table(['delivered', 'requests', 'bounces', 'opens', 'clicks', 'spam_reports'])
5862
table.align['name'] = 'r'
5963
table.align['value'] = 'l'
6064

SoftLayer/fixtures/SoftLayer_Network_Message_Delivery_Email_Sendgrid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@
5656
}
5757

5858
editObject = True
59+
updateEmailAddress = True

SoftLayer/managers/email.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_instance(self, identifier):
5757
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
5858
'getObject', id=identifier, mask=_mask)
5959

60-
def editObject(self, identifier, username=None, emailAddress=None, password=None):
60+
def editObject(self, identifier, username=None, password=None):
6161
"""Edit email delivery account related details.
6262
6363
:param int identifier: The ID of the email account
@@ -68,10 +68,18 @@ def editObject(self, identifier, username=None, emailAddress=None, password=None
6868
data = {}
6969
if username:
7070
data['username'] = username
71-
if emailAddress:
72-
data['emailAddress'] = emailAddress
7371
if password:
7472
data['password'] = password
7573

7674
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
7775
'editObject', data, id=identifier)
76+
77+
def update_email(self, identifier, email):
78+
"""Edit email address delivery account .
79+
80+
:param int identifier: The ID of the email account
81+
:param string email: email of the email account.
82+
83+
"""
84+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
85+
'updateEmailAddress', email, id=identifier)

tests/CLI/modules/email_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ def test_edit(self):
2727
self.assert_no_fail(result)
2828
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
2929
'editObject')
30+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
31+
'updateEmailAddress')

tests/managers/email_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ def test_get_object(self):
2727
self.manager.get_instance(1232123)
2828
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
2929
'getObject')
30+
31+
def test_update_email_address(self):
32+
self.manager = EmailManager(self.client)
33+
self.manager.update_email(1232123, 'test@ibm.com')
34+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
35+
'updateEmailAddress')

0 commit comments

Comments
 (0)