Skip to content

Commit 38adab2

Browse files
First version of mocked tests complete
1 parent 8fdebd4 commit 38adab2

2 files changed

Lines changed: 18 additions & 38 deletions

File tree

sendgrid/resources/apikeys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class APIKeys(object):
22
"""The API Keys feature allows customers to be able to generate an API Key credential
33
which can be used for authentication with the SendGrid v3 Web API or the Mail API Endpoint"""
44

5-
def __init__(self, client , **opts):
5+
def __init__(self, client, **opts):
66
"""
77
Constructs SendGrid APIKeys object.
88

test/test_apikeys.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ def _build_request(self, url=None, json_header=False, method='GET', data=None):
3939
req.add_header('Authorization', 'Bearer ' + self.apikey)
4040
if json_header:
4141
req.add_header('Content-Type', 'application/json')
42-
# print "url= " + req._Request__original
43-
# print "headers= " + str(req.headers)
44-
# print "data= " + json.dumps(data)
45-
response = 200
46-
body = {"mock": "success"}
42+
body = data
43+
if method == 'POST':
44+
response = 201
45+
if method == 'PATCH':
46+
response = 200
47+
if method == 'DELETE':
48+
response = 204
49+
if method == 'GET':
50+
response = 200
4751
return response, body
4852

4953
class TestSendGridAPIClient(unittest.TestCase):
@@ -75,48 +79,24 @@ def test_apikeys_init(self):
7579
self.assertEqual(self.apikeys.client, self.client)
7680

7781
def test_apikeys_post(self):
78-
name = "My Amazing API Key of Wonder [PATCH Test]"
79-
status, msg = self.client.apikeys.post(name)
80-
# self.assertEqual(status, 201)
81-
# msg = json.loads(msg)
82-
# api_key_id = msg['api_key_id']
83-
# self.assertEqual(msg['name'], name)
84-
# print status
85-
# print msg
86-
87-
"""
88-
def test_apikey_post_patch_delete_test(self):
8982
name = "My Amazing API Key of Wonder [PATCH Test]"
9083
status, msg = self.client.apikeys.post(name)
9184
self.assertEqual(status, 201)
92-
msg = json.loads(msg)
93-
api_key_id = msg['api_key_id']
9485
self.assertEqual(msg['name'], name)
95-
print status
96-
print msg
97-
86+
87+
def test_apikeys_patch(self):
9888
name = "My NEW Amazing API Key of Wonder [PATCH TEST]"
99-
status, msg = self.client.apikeys.patch(api_key_id, name)
89+
status, msg = self.client.apikeys.patch(SG_KEY, name)
10090
self.assertEqual(status, 200)
101-
print status
102-
print msg
103-
104-
status, msg = self.client.apikeys.get()
105-
print status
106-
print msg
107-
108-
status, msg = self.client.apikeys.delete(api_key_id)
91+
self.assertEqual(msg['name'], name)
92+
93+
def test_apikeys_delete(self):
94+
status, msg = self.client.apikeys.delete(SG_KEY)
10995
self.assertEqual(status, 204)
110-
print status
111-
112-
status, msg = self.client.apikeys.get()
113-
print status
114-
print msg
11596

116-
def test_apikey_get(self):
97+
def test_apikeys_get(self):
11798
status, msg = self.client.apikeys.get()
11899
self.assertEqual(status, 200)
119-
"""
120100

121101
if __name__ == '__main__':
122102
unittest.main()

0 commit comments

Comments
 (0)