mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-07-02 17:00:26 +08:00
Ensuring calls default to the values found by the Settings object in indicoio.config
This commit is contained in:
+39
-2
@@ -8,24 +8,36 @@ from indicoio.config import Settings
|
||||
|
||||
|
||||
class TestConfigureEnv(unittest.TestCase):
|
||||
"""
|
||||
Ensure that environment variables are handled by the `Settings` parser
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
os.environ = {}
|
||||
|
||||
def test_set_cloud_from_env_var(self):
|
||||
"""
|
||||
Ensure cloud hostname is read in from environment variables
|
||||
"""
|
||||
cloud = "invalid/cloud"
|
||||
os.environ["INDICO_CLOUD"] = cloud
|
||||
assert config.settings.cloud() == cloud
|
||||
assert config.SETTINGS.cloud() == cloud
|
||||
|
||||
def test_set_auth_from_env_var(self):
|
||||
"""
|
||||
Ensure cloud authentication credentials are read in from environment variables
|
||||
"""
|
||||
username = "test"
|
||||
password = "password"
|
||||
os.environ["INDICO_USERNAME"] = username
|
||||
os.environ["INDICO_PASSWORD"] = password
|
||||
assert config.settings.auth() == (username, password)
|
||||
assert config.SETTINGS.auth() == (username, password)
|
||||
|
||||
|
||||
class TestConfigurationFile(unittest.TestCase):
|
||||
"""
|
||||
Ensure that the `Settings` parser reads in configuration files properly
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.username = "test"
|
||||
@@ -45,13 +57,22 @@ class TestConfigurationFile(unittest.TestCase):
|
||||
os.environ = {}
|
||||
|
||||
def test_set_cloud_from_config_file(self):
|
||||
"""
|
||||
Ensure cloud hostname is read in from file
|
||||
"""
|
||||
assert self.settings.cloud() == self.cloud
|
||||
|
||||
def test_set_auth_from_config_file(self):
|
||||
"""
|
||||
Ensure cloud authentication credentials are read in from file
|
||||
"""
|
||||
assert self.settings.auth() == (self.username, self.password)
|
||||
|
||||
|
||||
class TestPrecedence(unittest.TestCase):
|
||||
"""
|
||||
Ensure that environment variables take precedence to config files
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.file_username = "file-username"
|
||||
@@ -79,13 +100,23 @@ class TestPrecedence(unittest.TestCase):
|
||||
self.settings = Settings(files=[config_file])
|
||||
|
||||
def test_set_cloud_from_config_file(self):
|
||||
"""
|
||||
Ensure cloud hosts set in environment variables are used over those in config files
|
||||
"""
|
||||
assert self.settings.cloud() == self.env_cloud
|
||||
|
||||
def test_set_auth_from_config_file(self):
|
||||
"""
|
||||
Ensure cloud authentication credentials set in environment variables
|
||||
are used over those in config files
|
||||
"""
|
||||
assert self.settings.auth() == (self.env_username, self.env_password)
|
||||
|
||||
|
||||
class TestConfigFilePrecedence(unittest.TestCase):
|
||||
"""
|
||||
Ensure that files passed in to a `Settings` object are assigned proper priority
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.high_priority_username = "high-priority-username"
|
||||
@@ -132,7 +163,13 @@ class TestConfigFilePrecedence(unittest.TestCase):
|
||||
])
|
||||
|
||||
def test_cloud_config_file_priority(self):
|
||||
"""
|
||||
Ensure the cloud subdomain priority is handled properly
|
||||
"""
|
||||
assert self.settings.cloud() == self.high_priority_cloud
|
||||
|
||||
def test_auth_config_file_priority(self):
|
||||
"""
|
||||
Ensure the cloud auth priority is handled properly
|
||||
"""
|
||||
assert self.settings.auth() == (self.high_priority_username, self.high_priority_password)
|
||||
|
||||
@@ -16,7 +16,7 @@ DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
class BatchAPIRun(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.auth = config.auth
|
||||
self.auth = config.AUTH
|
||||
|
||||
if not all(self.auth):
|
||||
raise SkipTest
|
||||
|
||||
Reference in New Issue
Block a user