|
2 | 2 | from mailjet_rest import Client |
3 | 3 | import os |
4 | 4 |
|
5 | | -API_KEY = os.environ['MJ_APIKEY_PUBLIC'] |
6 | | -API_SECRET = os.environ['MJ_APIKEY_PRIVATE'] |
7 | | - |
8 | | -mj = Client(auth=(API_KEY, API_SECRET)) |
9 | 5 |
|
10 | 6 | class TestSuite(unittest.TestCase): |
11 | 7 |
|
| 8 | + def setUp(self): |
| 9 | + self.auth = ( |
| 10 | + os.environ['MJ_APIKEY_PUBLIC'], |
| 11 | + os.environ['MJ_APIKEY_PRIVATE'] |
| 12 | + ) |
| 13 | + self.client = Client(auth=self.auth) |
| 14 | + |
12 | 15 | def test_get_no_param(self): |
13 | | - result = mj.contact.get().json() |
| 16 | + result = self.client.contact.get().json() |
14 | 17 | self.failUnless(('Data' in result and 'Count' in result)) |
15 | 18 |
|
16 | 19 | def test_get_valid_params(self): |
17 | | - result = mj.contact.get(filters={'limit': 2}).json() |
| 20 | + result = self.client.contact.get(filters={'limit': 2}).json() |
18 | 21 | self.failUnless('Count' in result) |
19 | 22 |
|
20 | 23 | def test_get_invalid_parameters(self): |
21 | 24 | # invalid parameters are ignored |
22 | | - result = mj.contact.get(filters={'invalid': 'false'}).json() |
| 25 | + result = self.client.contact.get(filters={'invalid': 'false'}).json() |
23 | 26 | self.failUnless('Count' in result) |
24 | 27 |
|
25 | 28 | def test_get_with_data(self): |
26 | 29 | # it shouldn't use data |
27 | | - result = mj. contact. get( data={ 'Email': '[email protected]'}) |
| 30 | + result = self.client. contact. get( data={ 'Email': '[email protected]'}) |
28 | 31 | self.failUnless(result.status_code == 200) |
29 | 32 |
|
30 | 33 | def test_get_with_action(self): |
31 | | - result = mj.contact_getcontactslists.get(id=5771382).json() |
| 34 | + result = self.client.contact_getcontactslists.get(id=5771382).json() |
32 | 35 | self.failUnless('Count' in result) |
33 | 36 |
|
34 | 37 | def test_get_with_id_filter(self): |
35 | | - result = mj.contact.get(filter={'id': 5771382}).json() |
| 38 | + result = self.client.contact.get(filter={'id': 5771382}).json() |
36 | 39 | self.failUnless('Count' in result) |
37 | 40 |
|
38 | 41 | def test_post_with_no_param(self): |
39 | | - result = mj.sender.create(data={}).json() |
| 42 | + result = self.client.sender.create(data={}).json() |
40 | 43 | self.failUnless('StatusCode' in result and result['StatusCode'] is not 400) |
41 | 44 |
|
| 45 | + def test_client_custom_version(self): |
| 46 | + self.client = Client( |
| 47 | + auth=self.auth, |
| 48 | + version='v3.1' |
| 49 | + ) |
| 50 | + self.assertEqual(self.client.config.version, 'v3.1') |
| 51 | + self.assertEqual( |
| 52 | + self.client.config['send'][0], |
| 53 | + 'https://api.mailjet.com/v3.1/send' |
| 54 | + ) |
| 55 | + |
42 | 56 |
|
43 | 57 | if __name__ == '__main__': |
44 | 58 | unittest.main() |
0 commit comments