Exemplo n.º 1
0
    def test_action_instance_cancels_current_running_clients(
            self, workflow_engine, db_session, get_action_instance,
            store_service):
        """
        @rapid-unit Workflow:Cancel Action Instance:Should cancel active client
        :param db_session:
        :type db_session:
        :param get_action_instance:
        :type get_action_instance:
        :param store_service:
        :type store_service:
        :return:
        :rtype:
        """
        db_session.return_value = [Mock()]
        mock_workflow = Mock()
        workflow_engine.return_value = mock_workflow
        get_action_instance.return_value = Mock(
            assigned_to='12345', status_id=StatusConstants.INPROGRESS)
        setattr(get_action_instance, 'id', '54321')

        mock_constants = Mock()
        action_dal = ActionDal(flask_app=Mock(),
                               queue_constants=mock_constants)

        eq_("Action Instance has been canceled.",
            action_dal.cancel_action_instance(123455)['message'])

        mock_workflow.complete_an_action.assert_called_with(
            123455, StatusConstants.CANCELED)
        mock_constants.cancel_worker.assert_called_with(
            get_action_instance().serialize())
Exemplo n.º 2
0
    def test_get_workable_work_requests_work_request_validation(
            self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance(id=1,
                                         pipeline_instance_id=1,
                                         workflow_instance_id=1)
        pipeline_parameters = PipelineParameters(parameter="foo", value="bar")
        action_instance_config = ActionInstanceConfig()
        pipeline_parameters_2 = PipelineParameters(parameter="foo2",
                                                   value="bar2")
        action_instance_config2 = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))
        session.results.append(
            (action_instance, pipeline_parameters_2, action_instance_config2))

        work_requests = action_dal.get_workable_work_requests()
        work_request = work_requests[0]
        eq_(1, len(work_requests))
        eq_(1, work_request.action_instance_id)
        eq_(1, work_request.pipeline_instance_id)
        eq_(1, work_request.workflow_instance_id)

        eq_({"foo": "bar", "foo2": "bar2"}, work_request.environment)
Exemplo n.º 3
0
    def test_get_verify_working_verify_join(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_dal.get_verify_working(10)

        eq_(PipelineInstance, session.join_args[0])
Exemplo n.º 4
0
    def test_get_verify_working_verify_results(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = Mock(id=1, pipeline_instance_id=1)
        session.results.append(action_instance)

        results = action_dal.get_verify_working(10)

        eq_([action_instance.serialize()], results)
Exemplo n.º 5
0
    def test_action_instance_returns_404_when_not_found(
            self, db_session, get_action_instance):
        """
        @rapid-unit Workflow:Cancel Action Instance:Should return a 404 if not found
        :return:
        :rtype:
        """
        db_session.return_value = [Mock()]
        get_action_instance.return_value = None

        action_dal = ActionDal(flask_app=Mock())
        with self.assertRaises(InvalidObjectException) as exception:
            action_dal.cancel_action_instance(12345)

        eq_(404, exception.exception.code)
        eq_("Action Instance not found", exception.exception.description)
Exemplo n.º 6
0
    def test_get_workable_work_requests_verify_outerjoin(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        ok_(PipelineParameters in session.outerjoin_args)
        eq_(PipelineParameters.__table__.columns['pipeline_instance_id'],
            session.outerjoin_args[1].left)
        eq_(ActionInstance.__table__.columns['pipeline_instance_id'],
            session.outerjoin_args[1].right)
Exemplo n.º 7
0
    def test_get_workable_work_requests_verify_queryables(
            self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        eq_([
            ActionInstance, PipelineParameters, ActionInstanceConfig,
            ActionInstance, PipelineParameters, ActionInstanceConfig
        ], session.query_args)
Exemplo n.º 8
0
    def test_get_verify_working_verify_filter_args(self, get_db_session, base):
        action_dal = ActionDal()

        now = datetime.datetime.utcnow()
        diff = now - datetime.timedelta(minutes=10)

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_dal.get_verify_working(10)

        eq_(6, len(session.filter_args))

        filter_1 = session.filter_args[0]
        filter_2 = session.filter_args[1]
        filter_3 = session.filter_args[2]
        filter_4 = session.filter_args[3]
        filter_5 = session.filter_args[4]
        filter_6 = session.filter_args[5]

        eq_(PipelineInstance.__table__.columns['status_id'], filter_1.left)
        eq_(StatusConstants.INPROGRESS, filter_1.right.value)

        eq_(ActionInstance.__table__.columns['status_id'], filter_2.left)
        eq_(StatusConstants.INPROGRESS, filter_2.right.value)

        eq_(ActionInstance.__table__.columns['assigned_to'], filter_3.left)
        eq_('', filter_3.right.value)

        eq_(ActionInstance.__table__.columns['start_date'], filter_4.left)
        eq_(diff.minute, filter_4.right.value.minute)
        eq_(diff.day, filter_4.right.value.day)
        eq_(diff.year, filter_4.right.value.year)
        eq_(diff.hour, filter_4.right.value.hour)

        eq_(ActionInstance.__table__.columns['end_date'], filter_5.left)
        eq_(Boolean, type(filter_5.type))

        eq_(ActionInstance.__table__.columns['manual'], filter_6.left)
        eq_(0, filter_6.right.value)
Exemplo n.º 9
0
    def test_get_workable_work_requests_verify_filters(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = Mock()
        action_instance.serialize.return_value = {}
        pipeline_parameters = Mock()
        action_configs = Mock()
        session.results.append(
            (action_instance, pipeline_parameters, action_configs))

        action_dal.get_workable_work_requests()

        eq_(8, len(session.filter_args))

        filter_1 = session.filter_args[0]
        filter_2 = session.filter_args[1]
        filter_3 = session.filter_args[2]
        filter_4 = session.filter_args[3]
        filter_5 = session.filter_args[4]
        filter_6 = session.filter_args[5]
        filter_7 = session.filter_args[6]
        filter_8 = session.filter_args[7]

        eq_(ActionInstance.__table__.columns['status_id'], filter_1.left)
        eq_(StatusConstants.READY, filter_1.right.value)

        eq_(ActionInstance.__table__.columns['manual'], filter_2.left)
        eq_(0, filter_2.right.value)

        eq_(ActionInstance.__table__.columns['pipeline_instance_id'],
            filter_3.left)
        eq_(PipelineInstance.__table__.columns['id'], filter_3.right)

        eq_(PipelineInstance.__table__.columns['status_id'], filter_4.left)
        eq_(StatusConstants.INPROGRESS, filter_4.right.value)
Exemplo n.º 10
0
    def test_get_workable_work_requests_verify_order_by(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        eq_(PipelineInstance.__table__.columns['priority'],
            session.order_by_args[0].element)
        eq_(PipelineInstance.__table__.columns['created_date'],
            session.order_by_args[1].element)
        eq_(PipelineInstance.__table__.columns['id'],
            session.order_by_args[2].element)
        eq_(ActionInstance.__table__.columns['order'],
            session.order_by_args[3].element)
        eq_(ActionInstance.__table__.columns['slice'],
            session.order_by_args[4].element)
Exemplo n.º 11
0
 def client_verify_working(self):
     action_dal = ActionDal(None, None)
     return action_dal.get_verify_working(self.flask_app.rapid_config.queue_consider_late_time)