Skip to content

add new email feature #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added SoftLayer/CLI/email/__init__.py
Empty file.
71 changes: 71 additions & 0 deletions SoftLayer/CLI/email/detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Get details for an image."""
# :license: MIT, see LICENSE for more details.

import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers.account import AccountManager
from SoftLayer.managers.email import EmailManager
from SoftLayer import utils


@click.command()
@environment.pass_env
def cli(env):
"""Display the Email Delivery account informatino """
manager = AccountManager(env.client)
email_manager = EmailManager(env.client)
result = manager.get_Network_Message_Delivery_Accounts()

table = formatting.KeyValueTable(['name', 'value'])

table_information = formatting.KeyValueTable(['id', 'username', 'hostname', 'description', 'vendor'])
table_information.align['id'] = 'r'
table_information.align['username'] = 'l'

for email in result:
table_information.add_row([email.get('id'), email.get('username'), email.get('emailAddress'),
utils.lookup(email, 'type', 'description'),
utils.lookup(email, 'vendor', 'keyName')])

overview_table = _build_overview_table(email_manager.get_AccountOverview(email.get('id')))
statistics = email_manager.get_statistics(email.get('id'),
["requests", "delivered", "opens", "clicks", "bounds"],
True, True, True, 6)

table.add_row(['email information', table_information])
table.add_row(['email overview', overview_table])
for statistic in statistics:
table.add_row(['statistics', _build_statistics_table(statistic)])

env.fout(table)


def _build_overview_table(email_overview):
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

table.add_row(['creditsAllowed', email_overview.get('creditsAllowed')])
table.add_row(['creditsRemain', email_overview.get('creditsRemain')])
table.add_row(['package', email_overview.get('package')])
table.add_row(['reputation', email_overview.get('reputation')])
table.add_row(['requests', email_overview.get('requests')])

return table


def _build_statistics_table(statistics):
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

table.add_row(['delivered', statistics.get('delivered')])
table.add_row(['requests', statistics.get('requests')])
table.add_row(['bounces', statistics.get('bounces')])
table.add_row(['opens', statistics.get('opens')])
table.add_row(['clicks', statistics.get('clicks')])
table.add_row(['spam Reports', statistics.get('spamReports')])

return table
3 changes: 3 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),

('email', 'SoftLayer.CLI.email'),
('email:detail', 'SoftLayer.CLI.email.detail:cli'),

('event-log', 'SoftLayer.CLI.event_log'),
('event-log:get', 'SoftLayer.CLI.event_log.get:cli'),
('event-log:types', 'SoftLayer.CLI.event_log.types:cli'),
Expand Down
24 changes: 24 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,3 +1076,27 @@
"username": "SL01SEV1234567_111"
}
]

getNetworkMessageDeliveryAccounts = [
{
"accountId": 147258,
"createDate": "2020-07-06T10:29:11-06:00",
"id": 1232123,
"typeId": 21,
"username": "[email protected]",
"vendorId": 1,
"type": {
"description": "Delivery of messages through e-mail",
"id": 21,
"keyName": "EMAIL",
"name": "Email"
},
"vendor": {
"id": 1,
"keyName": "SENDGRID",
"name": "SendGrid"
},
"emailAddress": "[email protected]",
"smtpAccess": "1"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
getAccountOverview = {
"creditsAllowed": 25000,
"creditsOverage": 0,
"creditsRemain": 25000,
"creditsUsed": 0,
"package": "Free Package",
"reputation": 100,
"requests": 56
}

getStatistics = [{
"blocks": 0,
"bounces": 0,
"clicks": 0,
"date": "2021-04-28",
"delivered": 0,
"invalidEmail": 0,
"opens": 0,
"repeatBounces": 0,
"repeatSpamReports": 0,
"repeatUnsubscribes": 0,
"requests": 0,
"spamReports": 0,
"uniqueClicks": 0,
"uniqueOpens": 0,
"unsubscribes": 0
}]
10 changes: 10 additions & 0 deletions SoftLayer/managers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,13 @@ def get_routers(self, mask=None, location=None):
}

return self.client['SoftLayer_Account'].getRouters(filter=object_filter, mask=mask)

def get_Network_Message_Delivery_Accounts(self):
"""Gets all Network Message delivery accounts.

:returns: Network Message delivery accounts
"""

_mask = """vendor,type"""

return self.client['SoftLayer_Account'].getNetworkMessageDeliveryAccounts(mask=_mask)
47 changes: 47 additions & 0 deletions SoftLayer/managers/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
SoftLayer.account
~~~~~~~~~~~~~~~~~~~~~~~
Account manager

:license: MIT, see License for more details.
"""

from SoftLayer import utils


# Invalid names are ignored due to long method names and short argument names
# pylint: disable=invalid-name, no-self-use


class EmailManager(utils.IdentifierMixin, object):
"""Common functions for getting information from the Account service

:param SoftLayer.API.BaseClient client: the client instance
"""

def __init__(self, client):
self.client = client

def get_AccountOverview(self, identifier):
"""Gets all the Network Message Delivery Account Overview

:returns: Network Message Delivery Account overview
"""
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
'getAccountOverview', id=identifier)

def get_statistics(self, identifier, selectedStatistics,
startDate, endDate, aggregatesOnly, days):
"""Gets statistics Network Message Delivery Account

:returns: statistics Network Message Delivery Account
"""
body = [selectedStatistics,
startDate,
endDate,
aggregatesOnly,
days
]

return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
'getStatistics', id=identifier, *body)
5 changes: 5 additions & 0 deletions docs/api/managers/email.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _email:

.. automodule:: SoftLayer.managers.email
:members:
:inherited-members:
9 changes: 9 additions & 0 deletions docs/cli/email.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _cli_email:

Email Commands
=================


.. click:: SoftLayer.CLI.email.detail:cli
:prog: email detail
:show-nested:
15 changes: 15 additions & 0 deletions tests/CLI/modules/email_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
SoftLayer.tests.CLI.modules.email_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tests for the user cli command
"""
from SoftLayer import testing


class EmailCLITests(testing.TestCase):

def test_detail(self):
result = self.run_command(['email', 'detail'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getNetworkMessageDeliveryAccounts')
26 changes: 26 additions & 0 deletions tests/managers/email_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
SoftLayer.tests.managers.email_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"""

from SoftLayer.managers.email import EmailManager
from SoftLayer import testing


class AccountManagerTests(testing.TestCase):

def test_get_AccountOverview(self):
self.manager = EmailManager(self.client)
self.manager.get_AccountOverview(1232123)
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
'getAccountOverview')

def test_get_statistics(self):
self.manager = EmailManager(self.client)
self.manager.get_statistics(1232123,
["requests", "delivered", "opens", "clicks", "bounds"],
True,
True, True, 6)
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
'getStatistics')