Exemple #1
0
 def test_create_action_already_exists(self):
     uuid = w_utils.generate_uuid()
     utils.create_test_action(id=1, uuid=uuid)
     self.assertRaises(exception.ActionAlreadyExists,
                       utils.create_test_action,
                       id=2,
                       uuid=uuid)
Exemple #2
0
 def test_destroy_action_by_uuid(self):
     uuid = w_utils.generate_uuid()
     utils.create_test_action(uuid=uuid)
     self.assertIsNotNone(self.dbapi.get_action_by_uuid(self.context, uuid))
     self.dbapi.destroy_action(uuid)
     self.assertRaises(exception.ActionNotFound,
                       self.dbapi.get_action_by_uuid, self.context, uuid)
Exemple #3
0
    def test_get_action_list_with_filter_by_uuid(self):
        action = utils.create_test_action()
        res = self.dbapi.get_action_list(self.context,
                                         filters={'uuid': action["uuid"]})

        self.assertEqual(len(res), 1)
        self.assertEqual(action['uuid'], res[0].uuid)
Exemple #4
0
 def test_get_action_list(self):
     uuids = []
     for _ in range(1, 6):
         action = utils.create_test_action(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(action['uuid']))
     res = self.dbapi.get_action_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Exemple #5
0
 def test_get_action_list(self):
     uuids = []
     for i in range(1, 6):
         action = utils.create_test_action(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(action['uuid']))
     res = self.dbapi.get_action_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Exemple #6
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)
        self.audit = utils.create_test_audit(
            audit_template_id=self.audit_template.id, id=1, uuid=None)
        self.action_plan = utils.create_test_action_plan(
            audit_id=self.audit.id, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.action1 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.action2 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.action3 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=3, uuid=None)
Exemple #7
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)
        self.audit = utils.create_test_audit(
            audit_template_id=self.audit_template.id, id=1, uuid=None)
        self.action_plan = utils.create_test_action_plan(
            audit_id=self.audit.id, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.action1 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.action2 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.action3 = utils.create_test_action(
                action_plan_id=self.action_plan.id, id=3, uuid=None)
Exemple #8
0
 def test_get_action_list(self):
     uuids = []
     for _ in range(1, 4):
         action = utils.create_test_action(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(action['uuid']))
     actions = self.dbapi.get_action_list(self.context)
     action_uuids = [a.uuid for a in actions]
     self.assertEqual(3, len(action_uuids))
     self.assertEqual(sorted(uuids), sorted(action_uuids))
     for action in actions:
         self.assertIsNone(action.action_plan)
Exemple #9
0
    def test_get_action_list_eager(self):
        _action_plan = utils.get_test_action_plan()
        action_plan = self.dbapi.create_action_plan(_action_plan)

        uuids = []
        for i in range(1, 4):
            action = utils.create_test_action(id=i,
                                              uuid=w_utils.generate_uuid(),
                                              action_plan_id=action_plan.id)
            uuids.append(six.text_type(action['uuid']))
        actions = self.dbapi.get_action_list(self.context, eager=True)
        action_map = {a.uuid: a for a in actions}
        self.assertEqual(sorted(uuids), sorted(action_map.keys()))
        eager_action = action_map[action.uuid]
        self.assertEqual(action_plan.as_dict(),
                         eager_action.action_plan.as_dict())
Exemple #10
0
 def test_destroy_action_plan_that_referenced_by_actions(self):
     action_plan = self._create_test_action_plan()
     action = utils.create_test_action(action_plan_id=action_plan['id'])
     self.assertEqual(action_plan['id'], action.action_plan_id)
     self.assertRaises(exception.ActionPlanReferenced,
                       self.dbapi.destroy_action_plan, action_plan['id'])
Exemple #11
0
 def test_destroy_action_plan_that_referenced_by_actions(self):
     action_plan = self._create_test_action_plan()
     action = utils.create_test_action(action_plan_id=action_plan['id'])
     self.assertEqual(action_plan['id'], action.action_plan_id)
     self.assertRaises(exception.ActionPlanReferenced,
                       self.dbapi.destroy_action_plan, action_plan['id'])
Exemple #12
0
 def test_destroy_action(self):
     action = utils.create_test_action()
     self.dbapi.destroy_action(action['id'])
     self.assertRaises(exception.ActionNotFound,
                       self.dbapi.get_action_by_id, self.context,
                       action['id'])
Exemple #13
0
 def test_update_action_uuid(self):
     action = utils.create_test_action()
     self.assertRaises(exception.Invalid, self.dbapi.update_action,
                       action['id'], {'uuid': 'hello'})
Exemple #14
0
 def test_update_action(self):
     action = utils.create_test_action()
     res = self.dbapi.update_action(
         action['id'], {'state': objects.action_plan.State.CANCELLED})
     self.assertEqual(objects.action_plan.State.CANCELLED, res.state)
Exemple #15
0
 def test_get_action_by_uuid(self):
     action = utils.create_test_action()
     action = self.dbapi.get_action_by_uuid(self.context, action['uuid'])
     self.assertEqual(action['id'], action.id)
Exemple #16
0
    def test_get_action_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = utils.create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            parents=None,
            state=objects.action_plan.State.RECOMMENDED)

        action1 = utils.create_test_action(
            id=1,
            action_plan_id=action_plan['id'],
            description='description action 1',
            uuid=w_utils.generate_uuid(),
            parents=None,
            state=objects.action_plan.State.PENDING)
        action2 = utils.create_test_action(
            id=2,
            action_plan_id=2,
            description='description action 2',
            uuid=w_utils.generate_uuid(),
            parents=[action1['uuid']],
            state=objects.action_plan.State.PENDING)
        action3 = utils.create_test_action(
            id=3,
            action_plan_id=action_plan['id'],
            description='description action 3',
            uuid=w_utils.generate_uuid(),
            parents=[action2['uuid']],
            state=objects.action_plan.State.ONGOING)
        action4 = utils.create_test_action(
            id=4,
            action_plan_id=action_plan['id'],
            description='description action 4',
            uuid=w_utils.generate_uuid(),
            parents=None,
            state=objects.action_plan.State.ONGOING)

        self.dbapi.soft_delete_action(action4['uuid'])

        res = self.dbapi.get_action_list(
            self.context, filters={'state': objects.action_plan.State.ONGOING})
        self.assertEqual([action3['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'bad-state'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'action_plan_id': 2})
        self.assertEqual([action2['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(
            self.context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(sorted([action1['id'], action3['id']]),
                         sorted([r.id for r in res]))

        temp_context = self.context
        temp_context.show_deleted = True
        res = self.dbapi.get_action_list(
            temp_context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(sorted([action1['id'], action3['id'], action4['id']]),
                         sorted([r.id for r in res]))

        res = self.dbapi.get_action_list(self.context,
                                         filters={'audit_uuid': audit.uuid})
        for action in res:
            self.assertEqual(action_plan['id'], action.action_plan_id)