forked from stackify/stackify-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_application.py
More file actions
95 lines (75 loc) · 3.31 KB
/
test_application.py
File metadata and controls
95 lines (75 loc) · 3.31 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
93
94
"""
Test the stackify.application module
"""
import unittest
from mock import patch
import os
from .bases import ClearEnvTest
from stackify import API_URL
from stackify.application import get_configuration
class TestConfig(ClearEnvTest):
'''
Test automatic configuration for the ApiConfiguration
'''
def test_required_kwargs(self):
'''API configuration requires appname, env and key'''
env_map = {}
with patch.dict('os.environ', env_map):
with self.assertRaises(NameError):
get_configuration()
with self.assertRaises(NameError):
get_configuration(application='1')
with self.assertRaises(NameError):
get_configuration(application='1', environment='2')
with self.assertRaises(NameError):
get_configuration(application='1', environment='2', api_url='3')
get_configuration(application='1', environment='2', api_key='3')
def test_environment_config(self):
'''API configuration can load from env vars'''
env_map = {
'STACKIFY_APPLICATION': 'test1_appname',
'STACKIFY_ENVIRONMENT': 'test1_environment',
'STACKIFY_API_KEY': 'test1_apikey',
'STACKIFY_API_URL': 'test1_apiurl',
}
with patch.dict('os.environ', env_map):
config = get_configuration()
self.assertEqual(config.application, 'test1_appname')
self.assertEqual(config.environment, 'test1_environment')
self.assertEqual(config.api_key, 'test1_apikey')
self.assertEqual(config.api_url, 'test1_apiurl')
def test_kwarg_mix(self):
'''API configuration can load from a mix of env vars and kwargs'''
env_map = {
'STACKIFY_APPLICATION': 'test2_appname',
'STACKIFY_ENVIRONMENT': 'test2_environment',
}
with patch.dict('os.environ', env_map):
config = get_configuration(api_key='test2_apikey', api_url='test2_apiurl')
self.assertEqual(config.application, 'test2_appname')
self.assertEqual(config.environment, 'test2_environment')
self.assertEqual(config.api_key, 'test2_apikey')
self.assertEqual(config.api_url, 'test2_apiurl')
def test_kwargs(self):
'''API configuration can load from kwargs'''
config = get_configuration(
application = 'test3_appname',
environment = 'test3_environment',
api_key = 'test3_apikey',
api_url = 'test3_apiurl')
self.assertEqual(config.application, 'test3_appname')
self.assertEqual(config.environment, 'test3_environment')
self.assertEqual(config.api_key, 'test3_apikey')
self.assertEqual(config.api_url, 'test3_apiurl')
def test_api_url_default(self):
'''API URL is set automatically'''
config = get_configuration(
application = 'test4_appname',
environment = 'test4_environment',
api_key = 'test4_apikey')
self.assertEqual(config.application, 'test4_appname')
self.assertEqual(config.environment, 'test4_environment')
self.assertEqual(config.api_key, 'test4_apikey')
self.assertEqual(config.api_url, API_URL)
if __name__=='__main__':
unittest.main()