Skip to content

Commit a54f7d3

Browse files
author
Ofego Edafe
committed
MAPI-81 ready for review
1 parent d07c3d1 commit a54f7d3

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

message_media_messages/configuration.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
class Configuration(object):
14-
1514
"""A class used for configuring the SDK by a user.
1615
1716
This class need not be instantiated and all properties and methods
@@ -36,8 +35,10 @@ class Configuration(object):
3635

3736
# The username to use with HMAC authentication
3837
# TODO: Set an appropriate value
39-
hmac_auth_user_name = os.environ.get('AUTHUSERNAME')
38+
hmac_auth_user_name = 'FxJMSlsivOoHAjDbWcO7'
39+
#os.environ.get('AUTH_USERNAME')
4040

4141
# The password to use with HMAC authentication
4242
# TODO: Set an appropriate value
43-
hmac_auth_password = os.environ.get('AUTHPASSWORD')
43+
hmac_auth_password = 'HbR3jfA1b0J3AHVmPajTWuGGaDIsk4'
44+
#os.environ.get('PASSWORD')

tests/auth_manager_test.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from datetime import datetime
1212
from time import mktime
1313
from wsgiref.handlers import format_date_time
14+
15+
from tests.test_configuration import TestConfiguration
1416
from tests.test_util import TestUtility
1517
from message_media_messages.http.auth.auth_manager import AuthManager
1618
from message_media_messages.configuration import Configuration
@@ -27,7 +29,7 @@ class AuthManagerTests(unittest.TestCase):
2729
body.messages = []
2830
body.messages.append(Message())
2931
body.messages[0].content = 'My tests message'
30-
body.messages[0].destination_number = '{}'
32+
body.messages[0].destination_number = '{}'.format(TestConfiguration.request_dest_number)
3133
body.messages[0].format = FormatEnum.SMS
3234

3335
_url_path = '/v1/messages'
@@ -51,7 +53,7 @@ class AuthManagerTests(unittest.TestCase):
5153
content_signature = "x-Content-MD5: {}\n".format(content_hash)
5254
get_content_signature = ""
5355

54-
def test_post_request_authorization_header_values_are_appropriate(self):
56+
def test_post_request_hmac_authorization_header_values_are_appropriate(self):
5557
date_header, expected_algorithm, expected_username, http, query_url, request_header = self.header_setup()
5658
body = APIHelper.json_serialize(self.body)
5759
content_signature = self.content_signature
@@ -71,7 +73,7 @@ def test_post_request_authorization_header_values_are_appropriate(self):
7173
self.assert_cases(algorithm, expected_algorithm, expected_header, expected_signature, expected_username,
7274
header, signature, username)
7375

74-
def test_md5_content_hash_equivalent_to_body(self):
76+
def test_post_request_content_md5_is_equivalent_to_md5_hash_of_request_body(self):
7577
http = urllib3.PoolManager()
7678
body = APIHelper.json_serialize(self.body)
7779
md5 = self.content_hash
@@ -89,7 +91,7 @@ def test_md5_content_hash_equivalent_to_body(self):
8991
requestMD5 = _request.getheader('x-Content-MD5')
9092
assert md5 == requestMD5
9193

92-
def test_get_request_authorization_header_values_are_appropriate(self):
94+
def test_get_request_hmac_authorization_header_values_are_appropriate(self):
9395
date_header, expected_algorithm, expected_username, http, query_url, request_header = self.header_setup()
9496
content_signature = ""
9597
expected_header = ' headers="date request-line"'
@@ -112,7 +114,7 @@ def header_setup(self):
112114
date_header = self.date_header
113115
request_header = self._headers
114116
query_url = self._query_url
115-
expected_username = 'hmac username="{}"'
117+
expected_username = 'hmac username="{}"'.format(Configuration.hmac_auth_user_name)
116118
expected_algorithm = ' algorithm="hmac-sha1"'
117119
return date_header, expected_algorithm, expected_username, http, query_url, request_header
118120

tests/messages_controller_test.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
"""
88

99
import unittest
10+
1011
from message_media_messages.exceptions.api_exception import APIException
12+
from tests.test_configuration import TestConfiguration
1113
from tests.test_util import TestUtility
1214
from message_media_messages.message_media_messages_client import MessageMediaMessagesClient
1315

1416

15-
class MessagesControllerTest(unittest.TestCase):
17+
class MessageControllerTest(unittest.TestCase):
1618

17-
# Testing successful message to MM endpoint
18-
def test_successful_message_to_endpoint(self):
19+
# Testing successful post request to endpoint
20+
def test_successful_post_request_with_hmac_auth_to_endpoint(self):
1921
use_hmac_authentication = True
2022
body = TestUtility.create_body()
2123

@@ -26,28 +28,28 @@ def test_successful_message_to_endpoint(self):
2628
self.assertIsNotNone(result)
2729

2830
# Testing unsupported request raises exception
29-
def test_unsuccessful_request_raises_exception(self):
30-
auth_user_name = '{}'
31-
auth_password = '{}'
31+
def test_unsuccessful_request_with_hmac_auth_raises_exception(self):
32+
hmac_auth_user_name = 'wrong'
33+
hmac_auth_password = 'value'
3234
use_hmac_authentication = True
3335
body = TestUtility.create_body()
3436

35-
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
37+
client = MessageMediaMessagesClient(hmac_auth_user_name, hmac_auth_password, use_hmac_authentication)
3638
messages_controller = client.messages
3739

3840
with self.assertRaises(APIException) as context_manager:
3941
messages_controller.send_messages(body)
4042
raised_exception = context_manager.exception
4143
self.assertIsNotNone(raised_exception)
4244

43-
# Testing get message endpoint
44-
def test_successful_get_message_to_endpoint(self):
45-
actual_id = '{}'
45+
# Testing successful get request endpoint
46+
def test_successful_get_request_with_hmac_auth_to_endpoint(self):
47+
expected_id = '{}'.format(TestConfiguration.request_message_id)
4648
use_hmac_authentication = True
4749

4850
client = MessageMediaMessagesClient(use_hmac_authentication)
4951
messages_controller = client.messages
5052

51-
result = messages_controller.get_message_status(actual_id)
52-
expected_id = result.message_id
53-
assert expected_id == actual_id
53+
result = messages_controller.get_message_status(expected_id)
54+
actual_id = result.message_id
55+
assert actual_id == expected_id

tests/test_configuration.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
message_media_messages
5+
6+
This file was automatically generated for MessageMedia by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
import os
9+
10+
11+
class TestConfiguration(object):
12+
"""A class used for configuring the SDK Test cases by a user.
13+
14+
This class need not be instantiated and all properties and methods
15+
are accessible without instance creation.
16+
17+
"""
18+
19+
# Set the id for a request
20+
request_message_id = os.environ.get('message_id')
21+
22+
# The base Uri for API calls
23+
request_dest_number = os.environ.get('dest_number')

tests/test_util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from message_media_messages.models.format_enum import FormatEnum
1414
from message_media_messages.models.message import Message
1515
from message_media_messages.models.send_messages_request import SendMessagesRequest
16+
from tests.test_configuration import TestConfiguration
1617

1718

1819
class TestUtility(object):
@@ -37,7 +38,7 @@ def create_body():
3738
body.messages = []
3839
body.messages.append(Message())
3940
body.messages[0].content = 'My tests message'
40-
body.messages[0].destination_number = '{}'
41+
body.messages[0].destination_number = '{}'.format(TestConfiguration.request_dest_number)
4142
body.messages[0].format = FormatEnum.SMS
4243

4344
return body

0 commit comments

Comments
 (0)