diff options
author | kali <kali@leap.se> | 2012-08-28 06:08:58 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-08-28 06:08:58 +0900 |
commit | c469e396bde67db15e486a320b254de0fa6f69df (patch) | |
tree | df725247cc48e40a109022fad32b1fc8797d576a /src/leap/eip/tests/test_checks.py | |
parent | 568d52ccf33e6d7683f36f5fe2e3c32b47892216 (diff) |
checki complete eip_config tests.
completed first version of EIPChecks
Diffstat (limited to 'src/leap/eip/tests/test_checks.py')
-rw-r--r-- | src/leap/eip/tests/test_checks.py | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py index 8c022907..83561833 100644 --- a/src/leap/eip/tests/test_checks.py +++ b/src/leap/eip/tests/test_checks.py @@ -11,7 +11,8 @@ from mock import patch, Mock import requests from leap.base import config as baseconfig -from leap.base.constants import DEFAULT_PROVIDER_DEFINITION +from leap.base.constants import (DEFAULT_PROVIDER_DEFINITION, + DEFINITION_EXPECTED_PATH) from leap.eip import checks as eipchecks from leap.eip import constants as eipconstants from leap.eip import exceptions as eipexceptions @@ -57,8 +58,8 @@ class EIPCheckTest(BaseLeapTest): "not called") self.assertTrue(mc.check_complete_eip_config.called, "not called") - self.assertTrue(mc.ping_gateway.called, - "not called") + #self.assertTrue(mc.ping_gateway.called, + #"not called") # test individual check methods @@ -107,10 +108,38 @@ class EIPCheckTest(BaseLeapTest): sampleconfig = eipconstants.EIP_SAMPLE_JSON checker.fetch_definition(config=sampleconfig) - # XXX TODO check for ConnectionError, HTTPError, InvalidUrl - # (and proper EIPExceptions are raised). + fn = os.path.join(baseconfig.get_default_provider_path(), + DEFINITION_EXPECTED_PATH) + with open(fn, 'r') as fp: + deserialized = json.load(fp) + self.assertEqual(DEFAULT_PROVIDER_DEFINITION, deserialized) + + # XXX TODO check for ConnectionError, HTTPError, InvalidUrl + # (and proper EIPExceptions are raised). + # Look at base.test_config. - # Look at base.test_config. + def test_fetch_eip_config(self): + with patch.object(requests, "get") as mocked_get: + mocked_get.return_value.status_code = 200 + mocked_get.return_value.json = eipconstants.EIP_SAMPLE_SERVICE + checker = eipchecks.EIPChecker(fetcher=requests) + sampleconfig = eipconstants.EIP_SAMPLE_JSON + checker.fetch_definition(config=sampleconfig) + + def test_check_complete_eip_config(self): + checker = eipchecks.EIPChecker() + with self.assertRaises(eipexceptions.EIPConfigurationError): + sampleconfig = copy.copy(eipconstants.EIP_SAMPLE_JSON) + sampleconfig['provider'] = None + checker.check_complete_eip_config(config=sampleconfig) + with self.assertRaises(eipexceptions.EIPConfigurationError): + sampleconfig = copy.copy(eipconstants.EIP_SAMPLE_JSON) + del sampleconfig['provider'] + checker.check_complete_eip_config(config=sampleconfig) + + # normal case + sampleconfig = copy.copy(eipconstants.EIP_SAMPLE_JSON) + checker.check_complete_eip_config(config=sampleconfig) if __name__ == "__main__": unittest.main() |