def post_get_test_audit_template(**kw):
    goal = db_utils.get_test_goal()
    strategy = db_utils.get_test_strategy(goal_id=goal['id'])
    kw['goal'] = kw.get('goal', goal['uuid'])
    kw['strategy'] = kw.get('strategy', strategy['uuid'])
    kw['scope'] = kw.get('scope', [])
    audit_template = api_utils.audit_template_post_data(**kw)
    return audit_template
示例#2
0
    def test_create_audit_template_generate_uuid(self):
        audit_template_dict = api_utils.audit_template_post_data()
        del audit_template_dict['uuid']

        response = self.post_json('/audit_templates', audit_template_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(audit_template_dict['goal'], response.json['goal'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
    def test_create_audit_template_generate_uuid(self):
        audit_template_dict = api_utils.audit_template_post_data()
        del audit_template_dict['uuid']

        response = self.post_json('/audit_templates', audit_template_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(audit_template_dict['goal'], response.json['goal'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#4
0
def post_get_test_audit_template(**kw):
    audit_template = api_utils.audit_template_post_data(**kw)
    goal = db_utils.get_test_goal()
    strategy = db_utils.get_test_strategy(goal_id=goal['id'])
    del audit_template['uuid']
    del audit_template['goal_id']
    del audit_template['strategy_id']
    audit_template['goal'] = kw.get('goal', goal['uuid'])
    audit_template['strategy'] = kw.get('strategy', strategy['uuid'])
    return audit_template
def post_get_test_audit_template(**kw):
    audit_template = api_utils.audit_template_post_data(**kw)
    goal = db_utils.get_test_goal()
    strategy = db_utils.get_test_strategy(goal_id=goal['id'])
    del audit_template['uuid']
    del audit_template['goal_id']
    del audit_template['strategy_id']
    audit_template['goal'] = kw.get('goal', goal['uuid'])
    audit_template['strategy'] = kw.get('strategy', strategy['uuid'])
    return audit_template
示例#6
0
 def test_create_audit_template_with_invalid_goal(self):
     with mock.patch.object(
         self.dbapi,
         'create_audit_template',
         wraps=self.dbapi.create_audit_template
     ) as cn_mock:
         audit_template_dict = api_utils.audit_template_post_data(
             goal='INVALID_GOAL')
         response = self.post_json('/audit_templates',
                                   audit_template_dict, expect_errors=True)
     self.assertEqual(400, response.status_int)
     assert not cn_mock.called
 def test_create_audit_template_with_invalid_goal(self):
     with mock.patch.object(
             self.dbapi,
             'create_audit_template',
             wraps=self.dbapi.create_audit_template) as cn_mock:
         audit_template_dict = api_utils.audit_template_post_data(
             goal='INVALID_GOAL')
         response = self.post_json('/audit_templates',
                                   audit_template_dict,
                                   expect_errors=True)
     self.assertEqual(400, response.status_int)
     assert not cn_mock.called
 def test_create_audit_template_doesnt_contain_id(self):
     with mock.patch.object(
             self.dbapi,
             'create_audit_template',
             wraps=self.dbapi.create_audit_template) as cn_mock:
         audit_template_dict = api_utils.audit_template_post_data(
             goal='DUMMY')
         response = self.post_json('/audit_templates', audit_template_dict)
         self.assertEqual(audit_template_dict['goal'],
                          response.json['goal'])
         cn_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cn_mock.call_args[0][0])
示例#9
0
 def test_create_audit_template_doesnt_contain_id(self):
     with mock.patch.object(
         self.dbapi,
         'create_audit_template',
         wraps=self.dbapi.create_audit_template
     ) as cn_mock:
         audit_template_dict = api_utils.audit_template_post_data(
             goal='DUMMY')
         response = self.post_json('/audit_templates', audit_template_dict)
         self.assertEqual(audit_template_dict['goal'],
                          response.json['goal'])
         cn_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cn_mock.call_args[0][0])
示例#10
0
    def test_create_audit_template(self, mock_utcnow):
        audit_template_dict = api_utils.audit_template_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/audit_templates', audit_template_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = \
            '/v1/audit_templates/%s' % audit_template_dict['uuid']
        self.assertEqual(urlparse.urlparse(response.location).path,
                         expected_location)
        self.assertEqual(audit_template_dict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        self.assertNotIn('deleted_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
示例#11
0
    def test_create_audit_template(self, mock_utcnow):
        audit_template_dict = api_utils.audit_template_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/audit_templates', audit_template_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = \
            '/v1/audit_templates/%s' % audit_template_dict['uuid']
        self.assertEqual(
            urlparse.urlparse(response.location).path, expected_location)
        self.assertEqual(audit_template_dict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        self.assertNotIn('deleted_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
示例#12
0
 def test_audit_template_init(self):
     audit_template_dict = api_utils.audit_template_post_data()
     del audit_template_dict['name']
     audit_template = api_audit_template.AuditTemplate(
         **audit_template_dict)
     self.assertEqual(wtypes.Unset, audit_template.name)
示例#13
0
 def test_audit_template_init(self):
     audit_template_dict = api_utils.audit_template_post_data()
     del audit_template_dict['name']
     audit_template = api_audit_template.AuditTemplate(
         **audit_template_dict)
     self.assertEqual(wtypes.Unset, audit_template.name)