Skip to content

Commit 843f531

Browse files
code review fixes
1 parent 1d4ca3f commit 843f531

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

SoftLayer/CLI/account/event_detail.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def cli(env, identifier, ack):
3131

3232
def basic_event_table(event):
3333
"""Formats a basic event table"""
34-
table = formatting.Table(["Id", "Status", "Type", "Start", "End"], title=event.get('subject'))
34+
table = formatting.Table(["Id", "Status", "Type", "Start", "End"],
35+
title=utils.clean_splitlines(event.get('subject')))
3536

3637
table.add_row([
3738
event.get('id'),
@@ -47,7 +48,7 @@ def basic_event_table(event):
4748
def impacted_table(event):
4849
"""Formats a basic impacted resources table"""
4950
table = formatting.Table([
50-
"Type", "Id", "hostname", "privateIp", "Label"
51+
"Type", "Id", "Hostname", "PrivateIp", "Label"
5152
])
5253
for item in event.get('impactedResources', []):
5354
table.add_row([
@@ -69,4 +70,4 @@ def update_table(event):
6970
update_number = update_number + 1
7071
text = update.get('contents')
7172
# deals with all the \r\n from the API
72-
click.secho("\n".join(text.splitlines()))
73+
click.secho(utils.clean_splitlines(text))

SoftLayer/CLI/account/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def event_table(events):
4444
event.get('id'),
4545
utils.clean_time(event.get('startDate')),
4646
utils.clean_time(event.get('endDate')),
47-
event.get('subject'),
47+
# Some subjects can have \r\n for some reason.
48+
utils.clean_splitlines(event.get('subject')),
4849
utils.lookup(event, 'statusCode', 'name'),
4950
event.get('acknowledgedFlag'),
5051
event.get('updateCount'),

SoftLayer/CLI/account/invoice_detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def cli(env, identifier, details):
2121
top_items = manager.get_billing_items(identifier)
2222

2323
title = "Invoice %s" % identifier
24-
table = formatting.Table(["Item Id", "category", "description", "Single",
24+
table = formatting.Table(["Item Id", "Category", "Description", "Single",
2525
"Monthly", "Create Date", "Location"], title=title)
2626
table.align['category'] = 'l'
2727
table.align['description'] = 'l'

SoftLayer/CLI/account/invoices.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def cli(env, limit, closed=False, get_all=False):
3030
table.align['Ending Balance'] = 'l'
3131
table.align['Invoice Amount'] = 'l'
3232
table.align['Items'] = 'l'
33+
if isinstance(invoices, dict):
34+
invoices = [invoices]
3335
for invoice in invoices:
3436
table.add_row([
3537
invoice.get('id'),

SoftLayer/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ def clean_string(string):
290290
return " ".join(string.split())
291291

292292

293+
def clean_splitlines(string):
294+
"""Returns a string where \r\n is replaced with \n"""
295+
if string is None:
296+
return ''
297+
else:
298+
return "\n".join(string.splitlines())
299+
300+
293301
def clean_time(sltime, in_format='%Y-%m-%dT%H:%M:%S%z', out_format='%Y-%m-%d %H:%M'):
294302
"""Easy way to format time strings
295303

tests/CLI/modules/account_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Tests for the user cli command
66
"""
7+
from SoftLayer.fixtures import SoftLayer_Account as SoftLayer_Account
78
from SoftLayer import testing
89

910

@@ -80,6 +81,13 @@ def test_invoices_all(self):
8081
self.assert_no_fail(result)
8182
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
8283

84+
def test_single_invoice(self):
85+
amock = self.set_mock('SoftLayer_Account', 'getInvoices')
86+
amock.return_value = SoftLayer_Account.getInvoices[0]
87+
result = self.run_command(['account', 'invoices', '--limit=1'])
88+
self.assert_no_fail(result)
89+
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=1)
90+
8391
# slcli account summary
8492
def test_account_summary(self):
8593
result = self.run_command(['account', 'summary'])

0 commit comments

Comments
 (0)