def test_set_health_check_defaults(self): # Pass nothing in. self.assertEqual( _DEFAULT_HEALTH_CHECK, application_configuration._set_health_check_defaults(None)) # Pass in an empty object. self.assertEqual( _DEFAULT_HEALTH_CHECK, application_configuration._set_health_check_defaults( appinfo.HealthCheck())) # Override some. health_check = appinfo.HealthCheck(restart_threshold=7, healthy_threshold=4) defaults_set = application_configuration._set_health_check_defaults( health_check) self.assertEqual(defaults_set.enable_health_check, _DEFAULT_HEALTH_CHECK.enable_health_check) self.assertEqual(defaults_set.check_interval_sec, _DEFAULT_HEALTH_CHECK.check_interval_sec) self.assertEqual(defaults_set.timeout_sec, _DEFAULT_HEALTH_CHECK.timeout_sec) self.assertEqual(defaults_set.unhealthy_threshold, _DEFAULT_HEALTH_CHECK.unhealthy_threshold) self.assertEqual(defaults_set.healthy_threshold, 4) self.assertEqual(defaults_set.restart_threshold, 7) self.assertEqual(defaults_set.host, _DEFAULT_HEALTH_CHECK.host)
def test_vm_app_yaml_configuration_network(self): manual_scaling = appinfo.ManualScaling() vm_settings = appinfo.VmSettings() vm_settings['vm_runtime'] = 'myawesomeruntime' network = appinfo.Network() network.forwarded_ports = ['49111:49111', '5002:49112', 8000] health_check = appinfo.HealthCheck() health_check.enable_health_check = False info = appinfo.AppInfoExternal( application='app', module='module1', version='1', runtime='vm', vm_settings=vm_settings, threadsafe=False, manual_scaling=manual_scaling, health_check=health_check, network=network ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.mox.VerifyAll() self.assertEqual(os.path.realpath('/appdir'), config.application_root) self.assertEqual(os.path.realpath('/appdir/app.yaml'), config.config_path) self.assertEqual('dev~app', config.application) self.assertEqual('app', config.application_external_name) self.assertEqual('dev', config.partition) self.assertEqual('module1', config.module_name) self.assertEqual('1', config.major_version) self.assertRegexpMatches(config.version_id, r'module1:1\.\d+') self.assertEqual('vm', config.runtime) self.assertEqual(vm_settings['vm_runtime'], config.effective_runtime) self.assertItemsEqual( {49111: 49111, 5002: 49112, 8000: 8000}, config.forwarded_ports) self.assertFalse(config.threadsafe) self.assertEqual(manual_scaling, config.manual_scaling) self.assertEqual({'/appdir/app.yaml': 10}, config._mtimes) self.assertEqual(info.health_check, config.health_check)
def _set_health_check_defaults(health_check): """Sets default values for any missing attributes in HealthCheck. These defaults need to be kept up to date with the production values in health_check.cc Args: health_check: An instance of appinfo.HealthCheck or None. Returns: An instance of appinfo.HealthCheck """ if not health_check: health_check = appinfo.HealthCheck() for k, v in _HEALTH_CHECK_DEFAULTS.iteritems(): if getattr(health_check, k) is None: setattr(health_check, k, v) return health_check
"""Make the java_supported() function return True temporarily. Use as: with _java_temporarily_supported(): ...test that relies on Java being supported... """ old_java_supported = application_configuration.java_supported application_configuration.java_supported = lambda: True yield application_configuration.java_supported = old_java_supported _DEFAULT_HEALTH_CHECK = appinfo.HealthCheck( enable_health_check=True, check_interval_sec=5, timeout_sec=4, unhealthy_threshold=2, healthy_threshold=2, restart_threshold=60, host='127.0.0.1') class TestModuleConfiguration(unittest.TestCase): """Tests for application_configuration.ModuleConfiguration.""" def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock(appinfo_includes, 'ParseAndReturnIncludePaths') self.mox.StubOutWithMock(os.path, 'getmtime') application_configuration.open = self._fake_open def tearDown(self):