def test_response_deployments_remove_namespace_from_all_app_ids(self, fixture): deployment = MarathonDeployment.from_json(fixture[0]) self.filter.response_deployment(self.user, deployment, deployment) self.assertEqual(deployment.affected_apps, ['/foo']) current_action_apps = [action.app for action in deployment.current_actions] self.assertEqual(current_action_apps, ['/foo']) actions = [step.actions for step in deployment.steps] step_apps = [action.app for action in chain.from_iterable(actions)] self.assertEqual(step_apps, ['/foo', '/foo'])
def response_deployment(self, user, deployment: MarathonDeployment, original_deployment) -> MarathonDeployment: # Não teremos deployments que afetam apps de múltiplos namespaces, # por isos podemos olhar apenas umas das apps. original_affected_apps_id = deployment.affected_apps[0] deployment.affected_apps = [ self._remove_namespace(app_id, user.current_account.namespace) for app_id in deployment.affected_apps ] for action in deployment.current_actions: action.app = self._remove_namespace(action.app, user.current_account.namespace) for step in deployment.steps: for action in step.actions: action.app = self._remove_namespace( action.app, user.current_account.namespace) if original_affected_apps_id.startswith( f"/{user.current_account.namespace}/"): return deployment return None
def test_response_deployments_return_none_if_outside_current_namespace( self, fixture): deployment = MarathonDeployment.from_json(fixture[0]) deployment.affected_apps = ["/othernamespace/foo"] self.assertIsNone( self.filter.response_deployment(self.user, deployment, deployment))