def test__store_as_config_map_bad_exception(self, config_parser, create_cfg_map_object, patch_cfg_map, load_k8s_config, base_operator_init): data = 'data' patch_cfg_map.side_effect = kubernetes.client.rest.ApiException( status=409) operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') try: operator._store_as_config_map(data) except kubernetes.client.rest.ApiException as err: assert patch_cfg_map.side_effect == err patch_cfg_map.assert_called_once_with( config_parser.return_value, config_parser.return_value, create_cfg_map_object.return_value, pretty=deployment_status_operator.CONFIG_MAP_DETAILS['pretty'] ) create_cfg_map_object.assert_called_once_with( config_parser.return_value, config_parser.return_value, data)
def test_execute_concurrency_fail(self, config_parse_args, xcom_puller, base_operator_init): operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') try: operator.execute(self.context) except airflow.AirflowException as err: assert str(err) == "Concurrency check did not pass, so the " \ "deployment status will not be updated" assert config_parse_args.called assert xcom_puller.called
def test__get_version_doc(self, config_parser, get_unique_doc, get_client, base_operator_init): operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') result = operator._get_version_doc(self.revision_id) assert result == get_unique_doc.return_value assert get_client.called get_unique_doc.assert_called_once_with( revision_id=self.revision_id, schema=config_parser.return_value, name=config_parser.return_value)
def test__get_version_doc_does_not_exist(self, config_parser, get_unique_doc, get_client, base_operator_init): get_unique_doc.side_effect = errors.DocumentNotFoundError() operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') result = operator._get_version_doc(self.revision_id) assert result == {} assert get_client.called get_unique_doc.assert_called_once_with( revision_id=self.revision_id, schema=config_parser.return_value, name=config_parser.return_value)
def test__get_status_and_revision(self, get_deployment_status, base_operator_init): operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') action = {'committed_rev_id': self.revision_id} operator.xcom_puller = mock.MagicMock() operator.xcom_puller.get_action_info = mock.MagicMock() operator.xcom_puller.get_action_info.return_value = action status_and_revision = operator._get_status_and_revision() get_deployment_status.assert_called_once_with( action, force_completed=operator.force_completed) assert status_and_revision == (get_deployment_status.return_value, self.revision_id)
def test_execute(self, store_as_config_map, get_status_and_revision, get_version_doc, config_parse_args, xcom_puller, base_operator_init): get_status_and_revision.return_value = (self.status, self.revision_id) get_version_doc.return_value = self.version operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') operator.execute(self.context) assert config_parse_args.called assert xcom_puller.called assert get_status_and_revision.called get_version_doc.assert_called_once_with(self.revision_id) store_as_config_map.assert_called_once_with(self.config_map_data)
def test__store_as_config_map_map_already_exists(self, config_parser, create_cfg_map_object, create_cfg_map, patch_cfg_map, load_k8s_config, get_deployment_status, base_operator_init): data = 'data' operator = deployment_status_operator.DeploymentStatusOperator( shipyard_conf='conf', main_dag_name='name') operator._store_as_config_map(data) patch_cfg_map.assert_called_once_with( config_parser.return_value, config_parser.return_value, create_cfg_map_object.return_value, pretty=deployment_status_operator.CONFIG_MAP_DETAILS['pretty'] ) create_cfg_map_object.assert_called_once_with( config_parser.return_value, config_parser.return_value, data) assert not create_cfg_map.called