-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_clientfromfile.py
More file actions
92 lines (76 loc) · 2.62 KB
/
test_clientfromfile.py
File metadata and controls
92 lines (76 loc) · 2.62 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
import os.path
import ox3apiclient
import unittest
class ClientFromFileTestCase(unittest.TestCase):
def test_returns_client(self):
file_path = os.path.join(os.path.dirname(__file__), 'ox3rctest')
ox = ox3apiclient.client_from_file(file_path=file_path)
self.assertTrue(isinstance(ox, ox3apiclient.Client))
def test_loads_default_env(self):
file_path = os.path.join(os.path.dirname(__file__), 'ox3rctest')
ox = ox3apiclient.client_from_file(file_path=file_path)
test_values = [
'domain',
'consumer_secret',
'consumer_key']
loaded_values = [
ox.domain,
ox.consumer_key,
ox.consumer_secret]
test_values.sort()
loaded_values.sort()
self.assertEqual(loaded_values, test_values)
def test_loads_alternate_env(self):
file_path = os.path.join(os.path.dirname(__file__), 'ox3rctest')
ox = ox3apiclient.client_from_file(file_path=file_path, env='dev')
test_values = [
'domain_dev',
'consumer_secret_dev',
'consumer_key_dev']
loaded_values = [
ox.domain,
ox.consumer_key,
ox.consumer_secret]
test_values.sort()
loaded_values.sort()
self.assertEqual(loaded_values, test_values)
def test_missing_required_option_raises_error(self):
file_path = os.path.join(os.path.dirname(__file__), 'ox3rctest')
self.assertRaises(
Exception,
ox3apiclient.client_from_file,
file_path,
'missing-required-option')
def test_loads_optional_options(self):
file_path = os.path.join(os.path.dirname(__file__), 'ox3rctest')
ox = ox3apiclient.client_from_file(
file_path=file_path,
env='optional-options')
test_values = [
'domain',
'consumer_secret',
'consumer_key',
'callback_url',
'scheme',
'request_token_url',
'access_token_url',
'authorization_url',
'api_path',
'email',
'password']
loaded_values = [
ox.domain,
ox.consumer_key,
ox.consumer_secret,
ox.callback_url,
ox.scheme,
ox.request_token_url,
ox.access_token_url,
ox.authorization_url,
ox.api_path,
ox._email,
ox._password]
test_values.sort()
loaded_values.sort()
self.assertEqual(loaded_values, test_values)