def test_get_config_with_production_and_tier_is_preemptible(): context = FakeAuroraCommandContext() context.set_options(create_mock_options()) with CLUSTERS.patch(AuroraClientCommandTest.TEST_CLUSTERS.values()): api = context.get_api(TEST_CLUSTER.name) api.get_tier_configs.return_value = AuroraClientCommandTest.get_mock_tier_configurations() with temporary_file() as fp: fp.write(create_test_config()) fp.flush() config = context.get_job_config(AuroraClientCommandTest.TEST_JOBKEY, fp.name) assert not config.job().taskConfig.production assert config.job().taskConfig.tier == AuroraClientCommandTest.PREEMPTIBLE_TIER.name
def test_get_api_caches_hook_enabled_apis_separately(): with CLUSTERS.patch([TEST_CLUSTER]): context = AuroraCommandContext() hooked_api = context.get_api(TEST_CLUSTER.name) unhooked_api = context.get_api(TEST_CLUSTER.name, enable_hooks=False) assert hooked_api != unhooked_api assert hooked_api in context.apis.values() assert hooked_api not in context.unhooked_apis.values() assert unhooked_api in context.unhooked_apis.values() assert unhooked_api not in context.apis.values()
def test_docker_binding_throws(self, mock_resolve): mock_resolve.side_effect = Exception('mock resolve failure') binding_helper.unregister_all() BindingHelper.register(DockerBindingHelper()) with temporary_file() as fp: fp.write(DOCKER_BINDING_CONFIG) fp.flush() with CLUSTERS.patch(TEST_CLUSTERS): cfg = AuroraConfig.load(fp.name) with pytest.raises(Exception): binding_helper.apply_all(cfg) assert mock_resolve.mock_calls == [call(TEST_CLUSTER, 'some/name', 'some.tag')]
def test_get_config_with_production_and_tier_is_preemptible(): context = FakeAuroraCommandContext() context.set_options(create_mock_options()) with CLUSTERS.patch(AuroraClientCommandTest.TEST_CLUSTERS.values()): api = context.get_api(TEST_CLUSTER.name) api.get_tier_configs.return_value = AuroraClientCommandTest.get_mock_tier_configurations( ) with temporary_file() as fp: fp.write(create_test_config()) fp.flush() config = context.get_job_config( AuroraClientCommandTest.TEST_JOBKEY, fp.name) assert not config.job().taskConfig.production assert config.job( ).taskConfig.tier == AuroraClientCommandTest.PREEMPTIBLE_TIER.name
def test_docker_binding(self, mock_resolve): image_reference = 'registry.example.com/some/repo@some:digest' mock_resolve.return_value = image_reference binding_helper.unregister_all() BindingHelper.register(DockerBindingHelper()) with temporary_file() as fp: fp.write(DOCKER_BINDING_CONFIG) fp.flush() with CLUSTERS.patch(TEST_CLUSTERS): cfg = AuroraConfig.load(fp.name) binding_helper.apply_all(cfg) assert cfg.job().taskConfig.container.docker.image == image_reference assert mock_resolve.mock_calls == [call(TEST_CLUSTER, 'some/name', 'some.tag')]
def test_docker_binding_throws(self, mock_resolve): mock_resolve.side_effect = Exception('mock resolve failure') binding_helper.unregister_all() BindingHelper.register(DockerBindingHelper()) with temporary_file() as fp: fp.write(DOCKER_BINDING_CONFIG) fp.flush() with CLUSTERS.patch(TEST_CLUSTERS): cfg = AuroraConfig.load(fp.name) with pytest.raises(Exception): binding_helper.apply_all(cfg) assert mock_resolve.mock_calls == [ call(TEST_CLUSTER, 'some/name', 'some.tag') ]
def test_docker_binding(self, mock_resolve): image_reference = 'registry.example.com/some/repo@some:digest' mock_resolve.return_value = image_reference binding_helper.unregister_all() BindingHelper.register(DockerBindingHelper()) with temporary_file() as fp: fp.write(DOCKER_BINDING_CONFIG) fp.flush() with CLUSTERS.patch(TEST_CLUSTERS): cfg = AuroraConfig.load(fp.name) binding_helper.apply_all(cfg) assert cfg.job( ).taskConfig.container.docker.image == image_reference assert mock_resolve.mock_calls == [ call(TEST_CLUSTER, 'some/name', 'some.tag') ]
def test_get_api_forwards_hooks_disabled(): with CLUSTERS.patch([TEST_CLUSTER]): api = AuroraCommandContext().get_api(TEST_CLUSTER.name, enable_hooks=False) assert isinstance(api, AuroraClientAPI) assert api._cluster == TEST_CLUSTER
def test_get_api_defaults_to_hooks_enabled(): with CLUSTERS.patch([TEST_CLUSTER]): api = AuroraCommandContext().get_api(TEST_CLUSTER.name) assert isinstance(api, HookedAuroraClientAPI) assert api._cluster == TEST_CLUSTER
def run(self, result=None): # Since CLUSTERS is a global value that evaluates code on import this is the best way to # ensure it does not pollute any tests. with CLUSTERS.patch(self.TEST_CLUSTERS._clusters.values()): super(AuroraClientCommandTest, self).run(result)
def run(self, result=None): # Since CLUSTERS is a global value that evaluates code on import this is the best way to # ensure it does not pollute any tests. with CLUSTERS.patch(self.TEST_CLUSTERS._clusters.values()): super(AuroraClientCommandTest, self).run()