Exemplo n.º 1
0
    def test_crud_partial(self):
        # Create the DB record.
        obj = ActionExecutionHistoryAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
        ActionExecutionHistory.add_or_update(ActionExecutionHistoryAPI.to_model(obj))
        model = ActionExecutionHistory.get_by_id(obj.id)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(model.trigger, {})
        self.assertDictEqual(model.trigger_type, {})
        self.assertDictEqual(model.trigger_instance, {})
        self.assertDictEqual(model.rule, {})
        self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
        self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
        doc = copy.deepcopy(self.fake_history_subtasks[0]['execution'])
        doc['start_timestamp'] = isotime.parse(doc['start_timestamp'])
        doc['end_timestamp'] = isotime.parse(doc['end_timestamp'])
        self.assertDictEqual(model.execution, doc)
        self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
        self.assertListEqual(model.children, [])

        # Update the DB record.
        children = [str(bson.ObjectId()), str(bson.ObjectId())]
        model.children = children
        ActionExecutionHistory.add_or_update(model)
        model = ActionExecutionHistory.get_by_id(obj.id)
        self.assertListEqual(model.children, children)

        # Delete the DB record.
        ActionExecutionHistory.delete(model)
        self.assertRaises(ValueError, ActionExecutionHistory.get_by_id, obj.id)
Exemplo n.º 2
0
    def setUpClass(cls):
        super(TestActionExecutionHistory, cls).setUpClass()

        cls.dt_base = isotime.add_utc_tz(
            datetime.datetime(2014, 12, 25, 0, 0, 0))
        cls.num_records = 100
        cls.refs = {}

        cls.fake_types = [{
            'trigger':
            copy.deepcopy(fixture.ARTIFACTS['trigger']),
            'trigger_type':
            copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
            'trigger_instance':
            copy.deepcopy(fixture.ARTIFACTS['trigger_instance']),
            'rule':
            copy.deepcopy(fixture.ARTIFACTS['rule']),
            'action':
            copy.deepcopy(fixture.ARTIFACTS['actions']['chain']),
            'runner':
            copy.deepcopy(fixture.ARTIFACTS['runners']['action-chain']),
            'execution':
            copy.deepcopy(fixture.ARTIFACTS['executions']['workflow']),
            'children': []
        }, {
            'action':
            copy.deepcopy(fixture.ARTIFACTS['actions']['local']),
            'runner':
            copy.deepcopy(fixture.ARTIFACTS['runners']['run-local']),
            'execution':
            copy.deepcopy(fixture.ARTIFACTS['executions']['task1'])
        }]

        def assign_parent(child):
            candidates = [
                v for k, v in cls.refs.iteritems()
                if v.action['name'] == 'chain'
            ]
            if candidates:
                parent = random.choice(candidates)
                child['parent'] = str(parent.id)
                parent.children.append(child['id'])
                cls.refs[str(
                    parent.id)] = ActionExecutionHistory.add_or_update(parent)

        for i in range(cls.num_records):
            obj_id = str(bson.ObjectId())
            timestamp = cls.dt_base + datetime.timedelta(seconds=i)
            fake_type = random.choice(cls.fake_types)
            data = copy.deepcopy(fake_type)
            data['id'] = obj_id
            data['execution']['start_timestamp'] = isotime.format(timestamp,
                                                                  offset=False)
            if fake_type['action']['name'] == 'local' and random.choice(
                [True, False]):
                assign_parent(data)
            wb_obj = ActionExecutionHistoryAPI(**data)
            db_obj = ActionExecutionHistoryAPI.to_model(wb_obj)
            cls.refs[obj_id] = ActionExecutionHistory.add_or_update(db_obj)
Exemplo n.º 3
0
    def test_model_complete(self):

        # Create API object.
        obj = ActionExecutionHistoryAPI(
            **copy.deepcopy(self.fake_history_workflow))
        self.assertDictEqual(obj.trigger,
                             self.fake_history_workflow['trigger'])
        self.assertDictEqual(obj.trigger_type,
                             self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(obj.trigger_instance,
                             self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
        self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
        self.assertDictEqual(obj.execution,
                             self.fake_history_workflow['execution'])
        self.assertIsNone(getattr(obj, 'parent', None))
        self.assertListEqual(obj.children,
                             self.fake_history_workflow['children'])

        # Convert API object to DB model.
        model = ActionExecutionHistoryAPI.to_model(obj)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(model.trigger,
                             self.fake_history_workflow['trigger'])
        self.assertDictEqual(model.trigger_type,
                             self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(model.trigger_instance,
                             self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(model.action,
                             self.fake_history_workflow['action'])
        self.assertDictEqual(model.runner,
                             self.fake_history_workflow['runner'])
        doc = copy.deepcopy(self.fake_history_workflow['execution'])
        doc['start_timestamp'] = isotime.parse(doc['start_timestamp'])
        self.assertDictEqual(model.execution, doc)
        self.assertIsNone(getattr(model, 'parent', None))
        self.assertListEqual(model.children,
                             self.fake_history_workflow['children'])

        # Convert DB model to API object.
        obj = ActionExecutionHistoryAPI.from_model(model)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(obj.trigger,
                             self.fake_history_workflow['trigger'])
        self.assertDictEqual(obj.trigger_type,
                             self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(obj.trigger_instance,
                             self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
        self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
        self.assertDictEqual(obj.execution,
                             self.fake_history_workflow['execution'])
        self.assertIsNone(getattr(obj, 'parent', None))
        self.assertListEqual(obj.children,
                             self.fake_history_workflow['children'])
Exemplo n.º 4
0
    def test_crud_partial(self):
        # Create the DB record.
        obj = ActionExecutionHistoryAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
        ActionExecutionHistory.add_or_update(ActionExecutionHistoryAPI.to_model(obj))
        model = ActionExecutionHistory.get_by_id(obj.id)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(model.trigger, {})
        self.assertDictEqual(model.trigger_type, {})
        self.assertDictEqual(model.trigger_instance, {})
        self.assertDictEqual(model.rule, {})
        self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
        self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
        doc = copy.deepcopy(self.fake_history_subtasks[0]['execution'])
        doc['start_timestamp'] = isotime.parse(doc['start_timestamp'])
        self.assertDictEqual(model.execution, doc)
        self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
        self.assertListEqual(model.children, [])

        # Update the DB record.
        children = [str(bson.ObjectId()), str(bson.ObjectId())]
        model.children = children
        ActionExecutionHistory.add_or_update(model)
        model = ActionExecutionHistory.get_by_id(obj.id)
        self.assertListEqual(model.children, children)

        # Delete the DB record.
        ActionExecutionHistory.delete(model)
        self.assertRaises(ValueError, ActionExecutionHistory.get_by_id, obj.id)
Exemplo n.º 5
0
    def test_datetime_range(self):
        base = isotime.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
        for i in range(60):
            timestamp = base + datetime.timedelta(seconds=i)
            doc = copy.deepcopy(self.fake_history_subtasks[0])
            doc['id'] = str(bson.ObjectId())
            doc['execution']['start_timestamp'] = isotime.format(timestamp)
            obj = ActionExecutionHistoryAPI(**doc)
            ActionExecutionHistory.add_or_update(ActionExecutionHistoryAPI.to_model(obj))

        dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
        objs = ActionExecutionHistory.query(execution__start_timestamp=dt_range)
        self.assertEqual(len(objs), 10)

        dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
        objs = ActionExecutionHistory.query(execution__start_timestamp=dt_range)
        self.assertEqual(len(objs), 10)
Exemplo n.º 6
0
 def test_get_one(self):
     obj_id = random.choice(self.refs.keys())
     response = self.app.get('/history/executions/%s' % obj_id)
     self.assertEqual(response.status_int, 200)
     self.assertIsInstance(response.json, dict)
     record = response.json
     fake_record = ActionExecutionHistoryAPI.from_model(self.refs[obj_id])
     self.assertEqual(record['id'], obj_id)
     self.assertDictEqual(record['action'], fake_record.action)
     self.assertDictEqual(record['runner'], fake_record.runner)
     self.assertDictEqual(record['execution'], fake_record.execution)
Exemplo n.º 7
0
 def test_get_one(self):
     obj_id = random.choice(self.refs.keys())
     response = self.app.get('/v1/history/executions/%s' % obj_id)
     self.assertEqual(response.status_int, 200)
     self.assertIsInstance(response.json, dict)
     record = response.json
     fake_record = ActionExecutionHistoryAPI.from_model(self.refs[obj_id])
     self.assertEqual(record['id'], obj_id)
     self.assertDictEqual(record['action'], fake_record.action)
     self.assertDictEqual(record['runner'], fake_record.runner)
     self.assertDictEqual(record['execution'], fake_record.execution)
Exemplo n.º 8
0
    def test_model_partial(self):
        # Create API object.
        obj = ActionExecutionHistoryAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
        self.assertIsNone(getattr(obj, 'trigger', None))
        self.assertIsNone(getattr(obj, 'trigger_type', None))
        self.assertIsNone(getattr(obj, 'trigger_instance', None))
        self.assertIsNone(getattr(obj, 'rule', None))
        self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
        self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
        self.assertDictEqual(obj.execution, self.fake_history_subtasks[0]['execution'])
        self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
        self.assertIsNone(getattr(obj, 'children', None))

        # Convert API object to DB model.
        model = ActionExecutionHistoryAPI.to_model(obj)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(model.trigger, {})
        self.assertDictEqual(model.trigger_type, {})
        self.assertDictEqual(model.trigger_instance, {})
        self.assertDictEqual(model.rule, {})
        self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
        self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
        doc = copy.deepcopy(self.fake_history_subtasks[0]['execution'])
        doc['start_timestamp'] = isotime.parse(doc['start_timestamp'])
        doc['end_timestamp'] = isotime.parse(doc['end_timestamp'])
        self.assertDictEqual(model.execution, doc)
        self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
        self.assertListEqual(model.children, [])

        # Convert DB model to API object.
        obj = ActionExecutionHistoryAPI.from_model(model)
        self.assertEqual(str(model.id), obj.id)
        self.assertIsNone(getattr(obj, 'trigger', None))
        self.assertIsNone(getattr(obj, 'trigger_type', None))
        self.assertIsNone(getattr(obj, 'trigger_instance', None))
        self.assertIsNone(getattr(obj, 'rule', None))
        self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
        self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
        self.assertDictEqual(obj.execution, self.fake_history_subtasks[0]['execution'])
        self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
        self.assertIsNone(getattr(obj, 'children', None))
Exemplo n.º 9
0
    def test_model_complete(self):

        # Create API object.
        obj = ActionExecutionHistoryAPI(**copy.deepcopy(self.fake_history_workflow))
        self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
        self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
        self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
        self.assertDictEqual(obj.execution, self.fake_history_workflow['execution'])
        self.assertIsNone(getattr(obj, 'parent', None))
        self.assertListEqual(obj.children, self.fake_history_workflow['children'])

        # Convert API object to DB model.
        model = ActionExecutionHistoryAPI.to_model(obj)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(model.trigger, self.fake_history_workflow['trigger'])
        self.assertDictEqual(model.trigger_type, self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(model.trigger_instance, self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(model.action, self.fake_history_workflow['action'])
        self.assertDictEqual(model.runner, self.fake_history_workflow['runner'])
        doc = copy.deepcopy(self.fake_history_workflow['execution'])
        doc['start_timestamp'] = isotime.parse(doc['start_timestamp'])
        self.assertDictEqual(model.execution, doc)
        self.assertIsNone(getattr(model, 'parent', None))
        self.assertListEqual(model.children, self.fake_history_workflow['children'])

        # Convert DB model to API object.
        obj = ActionExecutionHistoryAPI.from_model(model)
        self.assertEqual(str(model.id), obj.id)
        self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
        self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
        self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
        self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
        self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
        self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
        self.assertDictEqual(obj.execution, self.fake_history_workflow['execution'])
        self.assertIsNone(getattr(obj, 'parent', None))
        self.assertListEqual(obj.children, self.fake_history_workflow['children'])
Exemplo n.º 10
0
    def test_datetime_range(self):
        base = isotime.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
        for i in range(60):
            timestamp = base + datetime.timedelta(seconds=i)
            doc = copy.deepcopy(self.fake_history_subtasks[0])
            doc['id'] = str(bson.ObjectId())
            doc['execution']['start_timestamp'] = isotime.format(timestamp)
            obj = ActionExecutionHistoryAPI(**doc)
            ActionExecutionHistory.add_or_update(ActionExecutionHistoryAPI.to_model(obj))

        dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
        objs = ActionExecutionHistory.query(execution__start_timestamp=dt_range)
        self.assertEqual(len(objs), 10)

        dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
        objs = ActionExecutionHistory.query(execution__start_timestamp=dt_range)
        self.assertEqual(len(objs), 10)
Exemplo n.º 11
0
    def setUpClass(cls):
        super(TestActionExecutionHistory, cls).setUpClass()

        cls.dt_base = isotime.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
        cls.num_records = 100
        cls.refs = {}

        cls.fake_types = [
            {
                'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
                'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
                'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance']),
                'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
                'action': copy.deepcopy(fixture.ARTIFACTS['actions']['chain']),
                'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['action-chain']),
                'execution': copy.deepcopy(fixture.ARTIFACTS['executions']['workflow']),
                'children': []
            },
            {
                'action': copy.deepcopy(fixture.ARTIFACTS['actions']['local']),
                'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['run-local']),
                'execution': copy.deepcopy(fixture.ARTIFACTS['executions']['task1'])
            }
        ]

        def assign_parent(child):
            candidates = [v for k, v in cls.refs.iteritems() if v.action['name'] == 'chain']
            if candidates:
                parent = random.choice(candidates)
                child['parent'] = str(parent.id)
                parent.children.append(child['id'])
                cls.refs[str(parent.id)] = ActionExecutionHistory.add_or_update(parent)

        for i in range(cls.num_records):
            obj_id = str(bson.ObjectId())
            timestamp = cls.dt_base + datetime.timedelta(seconds=i)
            fake_type = random.choice(cls.fake_types)
            data = copy.deepcopy(fake_type)
            data['id'] = obj_id
            data['execution']['start_timestamp'] = isotime.format(timestamp, offset=False)
            if fake_type['action']['name'] == 'local' and random.choice([True, False]):
                assign_parent(data)
            wb_obj = ActionExecutionHistoryAPI(**data)
            db_obj = ActionExecutionHistoryAPI.to_model(wb_obj)
            cls.refs[obj_id] = ActionExecutionHistory.add_or_update(db_obj)