Ejemplo n.º 1
0
 def test_create_audit_template_already_exists(self):
     uuid = w_utils.generate_uuid()
     utils.create_test_audit_template(id=1, uuid=uuid)
     self.assertRaises(exception.AuditTemplateAlreadyExists,
                       utils.create_test_audit_template,
                       id=2,
                       uuid=uuid)
Ejemplo n.º 2
0
 def test_destroy_audit_template_by_uuid(self):
     uuid = w_utils.generate_uuid()
     utils.create_test_audit_template(uuid=uuid)
     self.assertIsNotNone(
         self.dbapi.get_audit_template_by_uuid(self.context, uuid))
     self.dbapi.destroy_audit_template(uuid)
     self.assertRaises(exception.AuditTemplateNotFound,
                       self.dbapi.get_audit_template_by_uuid, self.context,
                       uuid)
Ejemplo n.º 3
0
    def test_get_audit_template_list_with_filters(self):
        goal = utils.create_test_goal(name='DUMMY')

        audit_template1 = utils.create_test_audit_template(
            id=1,
            uuid=w_utils.generate_uuid(),
            name='My Audit Template 1',
            description='Description of my audit template 1',
            goal_id=goal['id'])
        audit_template2 = utils.create_test_audit_template(
            id=2,
            uuid=w_utils.generate_uuid(),
            name='My Audit Template 2',
            description='Description of my audit template 2',
            goal_id=goal['id'])
        audit_template3 = utils.create_test_audit_template(
            id=3,
            uuid=w_utils.generate_uuid(),
            name='My Audit Template 3',
            description='Description of my audit template 3',
            goal_id=goal['id'])

        self.dbapi.soft_delete_audit_template(audit_template3['uuid'])

        res = self.dbapi.get_audit_template_list(
            self.context,
            filters={'name': 'My Audit Template 1'})
        self.assertEqual([audit_template1['id']], [r.id for r in res])

        res = self.dbapi.get_audit_template_list(
            self.context,
            filters={'name': 'Does not exist'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_audit_template_list(
            self.context,
            filters={'goal_name': 'DUMMY'})
        self.assertEqual(
            sorted([audit_template1['id'], audit_template2['id']]),
            sorted([r.id for r in res]))

        temp_context = self.context
        temp_context.show_deleted = True
        res = self.dbapi.get_audit_template_list(
            temp_context,
            filters={'goal_name': 'DUMMY'})
        self.assertEqual(
            sorted([audit_template1['id'], audit_template2['id'],
                    audit_template3['id']]),
            sorted([r.id for r in res]))

        res = self.dbapi.get_audit_template_list(
            self.context,
            filters={'name': 'My Audit Template 2'})
        self.assertEqual([audit_template2['id']], [r.id for r in res])
Ejemplo n.º 4
0
    def _data_setup(self):
        gen_name = lambda: "Audit Template %s" % w_utils.generate_uuid()
        self.audit_template1_name = gen_name()
        self.audit_template2_name = gen_name()
        self.audit_template3_name = gen_name()

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit_template1 = utils.create_test_audit_template(
                name=self.audit_template1_name, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit_template2 = utils.create_test_audit_template(
                name=self.audit_template2_name, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit_template3 = utils.create_test_audit_template(
                name=self.audit_template3_name, id=3, uuid=None)
Ejemplo n.º 5
0
    def _data_setup(self):
        gen_name = lambda: "Audit Template %s" % w_utils.generate_uuid()
        self.audit_template1_name = gen_name()
        self.audit_template2_name = gen_name()
        self.audit_template3_name = gen_name()

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit_template1 = utils.create_test_audit_template(
                name=self.audit_template1_name, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit_template2 = utils.create_test_audit_template(
                name=self.audit_template2_name, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit_template3 = utils.create_test_audit_template(
                name=self.audit_template3_name, id=3, uuid=None)
Ejemplo n.º 6
0
    def test_get_audit_template_list_with_filter_by_uuid(self):
        audit_template = utils.create_test_audit_template()
        res = self.dbapi.get_audit_template_list(
            self.context, filters={'uuid': audit_template["uuid"]})

        self.assertEqual(len(res), 1)
        self.assertEqual(audit_template['uuid'], res[0].uuid)
Ejemplo n.º 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)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=2,
                uuid=None,
                state=objects.audit.State.FAILED)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=3,
                uuid=None,
                state=objects.audit.State.CANCELLED)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit4 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=4,
                uuid=None,
                state=objects.audit.State.SUSPENDED)
Ejemplo n.º 8
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.efficacy_indicator1 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=1,
                uuid=None,
                name="efficacy_indicator1",
                description="Test Indicator 1")
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.efficacy_indicator2 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=2,
                uuid=None,
                name="efficacy_indicator2",
                description="Test Indicator 2")
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.efficacy_indicator3 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=3,
                uuid=None,
                name="efficacy_indicator3",
                description="Test Indicator 3")
Ejemplo n.º 9
0
 def test_audit_template_create_same_name(self):
     audit_template1 = utils.create_test_audit_template(
         uuid=w_utils.generate_uuid(), name='audit_template_name')
     self.assertEqual(audit_template1['uuid'], audit_template1.uuid)
     self.assertRaises(exception.AuditTemplateAlreadyExists,
                       utils.create_test_audit_template,
                       uuid=w_utils.generate_uuid(),
                       name='audit_template_name')
Ejemplo n.º 10
0
 def test_get_audit_template_list(self):
     uuids = []
     for i in range(1, 6):
         audit_template = utils.create_test_audit_template(
             uuid=w_utils.generate_uuid(),
             name='My Audit Template {0}'.format(i))
         uuids.append(six.text_type(audit_template['uuid']))
     res = self.dbapi.get_audit_template_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Ejemplo n.º 11
0
 def test_audit_template_create_same_name(self):
     audit_template1 = utils.create_test_audit_template(
         uuid=w_utils.generate_uuid(),
         name='audit_template_name')
     self.assertEqual(audit_template1['uuid'], audit_template1.uuid)
     self.assertRaises(
         exception.AuditTemplateAlreadyExists,
         utils.create_test_audit_template,
         uuid=w_utils.generate_uuid(),
         name='audit_template_name')
Ejemplo n.º 12
0
 def test_get_audit_template_list(self):
     uuids = []
     for i in range(1, 6):
         audit_template = utils.create_test_audit_template(
             uuid=w_utils.generate_uuid(),
             name='My Audit Template {0}'.format(i))
         uuids.append(six.text_type(audit_template['uuid']))
     res = self.dbapi.get_audit_template_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Ejemplo n.º 13
0
 def test_get_audit_template_list(self):
     uuids = []
     for i in range(1, 4):
         audit_template = utils.create_test_audit_template(
             id=i,
             uuid=w_utils.generate_uuid(),
             name='My Audit Template {0}'.format(i))
         uuids.append(six.text_type(audit_template['uuid']))
     audit_templates = self.dbapi.get_audit_template_list(self.context)
     audit_template_uuids = [at.uuid for at in audit_templates]
     self.assertEqual(sorted(uuids), sorted(audit_template_uuids))
     for audit_template in audit_templates:
         self.assertIsNone(audit_template.goal)
         self.assertIsNone(audit_template.strategy)
Ejemplo n.º 14
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)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=3, uuid=None)
Ejemplo n.º 15
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)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=3, uuid=None)
Ejemplo n.º 16
0
    def test_get_audit_template_list_eager(self):
        _goal = utils.get_test_goal()
        goal = self.dbapi.create_goal(_goal)
        _strategy = utils.get_test_strategy()
        strategy = self.dbapi.create_strategy(_strategy)

        uuids = []
        for i in range(1, 4):
            audit_template = utils.create_test_audit_template(
                id=i, uuid=w_utils.generate_uuid(),
                name='My Audit Template {0}'.format(i),
                goal_id=goal.id, strategy_id=strategy.id)
            uuids.append(six.text_type(audit_template['uuid']))
        audit_templates = self.dbapi.get_audit_template_list(
            self.context, eager=True)
        audit_template_map = {a.uuid: a for a in audit_templates}
        self.assertEqual(sorted(uuids), sorted(audit_template_map.keys()))
        eager_audit_template = audit_template_map[audit_template.uuid]
        self.assertEqual(goal.as_dict(), eager_audit_template.goal.as_dict())
        self.assertEqual(
            strategy.as_dict(), eager_audit_template.strategy.as_dict())
Ejemplo n.º 17
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.efficacy_indicator1 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=1, uuid=None,
                name="efficacy_indicator1", description="Test Indicator 1")
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.efficacy_indicator2 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=2, uuid=None,
                name="efficacy_indicator2", description="Test Indicator 2")
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.efficacy_indicator3 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=3, uuid=None,
                name="efficacy_indicator3", description="Test Indicator 3")
Ejemplo n.º 18
0
 def test_get_audit_template_by_uuid(self):
     audit_template = utils.create_test_audit_template()
     audit_template = self.dbapi.get_audit_template_by_uuid(
         self.context, audit_template['uuid'])
     self.assertEqual(audit_template['id'], audit_template.id)
Ejemplo n.º 19
0
 def test_update_audit_template(self):
     audit_template = utils.create_test_audit_template()
     res = self.dbapi.update_audit_template(audit_template['id'],
                                            {'name': 'updated-model'})
     self.assertEqual('updated-model', res.name)
Ejemplo n.º 20
0
 def test_destroy_audit_template(self):
     audit_template = utils.create_test_audit_template()
     self.dbapi.destroy_audit_template(audit_template['id'])
     self.assertRaises(exception.AuditTemplateNotFound,
                       self.dbapi.get_audit_template_by_id, self.context,
                       audit_template['id'])
Ejemplo n.º 21
0
 def test_update_audit_template_uuid(self):
     audit_template = utils.create_test_audit_template()
     self.assertRaises(exception.Invalid, self.dbapi.update_audit_template,
                       audit_template['id'], {'uuid': 'hello'})