forked from Khan/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_keys.py
More file actions
51 lines (42 loc) · 1.65 KB
/
test_api_keys.py
File metadata and controls
51 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from .base_test import BaseTest, MockSendGridAPIClientRequest
import os
try:
import unittest2 as unittest
except ImportError:
import unittest
try:
from StringIO import StringIO
except ImportError: # Python 3
from io import StringIO
import sendgrid
from sendgrid.client import SendGridAPIClient
from sendgrid.version import __version__
SG_KEY = os.getenv('SG_KEY') or 'SENDGRID_APIKEY'
class TestAPIKeys(unittest.TestCase):
def setUp(self):
SendGridAPIClient = MockSendGridAPIClientRequest
self.client = SendGridAPIClient(SG_KEY)
def test_apikeys_init(self):
self.apikeys = self.client.apikeys
self.assertEqual(self.apikeys.name, None)
self.assertEqual(self.apikeys.base_endpoint, "/v3/api_keys")
self.assertEqual(self.apikeys.endpoint, "/v3/api_keys")
self.assertEqual(self.apikeys.client, self.client)
def test_apikeys_post(self):
name = "My Amazing API Key of Wonder [PATCH Test]"
status, msg = self.client.apikeys.post(name)
self.assertEqual(status, 201)
self.assertEqual(msg['name'], name)
def test_apikeys_patch(self):
name = "My NEW Amazing API Key of Wonder [PATCH TEST]"
status, msg = self.client.apikeys.patch(SG_KEY, name)
self.assertEqual(status, 200)
self.assertEqual(msg['name'], name)
def test_apikeys_delete(self):
status, msg = self.client.apikeys.delete(SG_KEY)
self.assertEqual(status, 204)
def test_apikeys_get(self):
status, msg = self.client.apikeys.get()
self.assertEqual(status, 200)
if __name__ == '__main__':
unittest.main()