Ejemplo n.º 1
0
 def test_request_unsupported_version(self):
     bad_version = (main.CURRENT_API_VERSION[0],
                    main.CURRENT_API_VERSION[1] + 1)
     headers = {conf.VERSION_HEADER: main._format_version(bad_version)}
     res = self.app.get('/', headers=headers)
     self._check_version_present(res)
     self.assertEqual(406, res.status_code)
     error = _get_error(res)
     self.assertIn('%d.%d' % bad_version, error)
     self.assertIn('%d.%d' % main.MINIMUM_API_VERSION, error)
     self.assertIn('%d.%d' % main.CURRENT_API_VERSION, error)
Ejemplo n.º 2
0
 def test_request_unsupported_version(self):
     bad_version = (main.CURRENT_API_VERSION[0],
                    main.CURRENT_API_VERSION[1] + 1)
     headers = {conf.VERSION_HEADER:
                main._format_version(bad_version)}
     res = self.app.get('/', headers=headers)
     self._check_version_present(res)
     self.assertEqual(406, res.status_code)
     error = _get_error(res)
     self.assertIn('%d.%d' % bad_version, error)
     self.assertIn('%d.%d' % main.MINIMUM_API_VERSION, error)
     self.assertIn('%d.%d' % main.CURRENT_API_VERSION, error)
Ejemplo n.º 3
0
    def test_create_api_less_1_6(self, create_mock):
        data = {'uuid': self.uuid, 'conditions': 'cond', 'actions': 'act'}
        exp = data.copy()
        exp['description'] = None
        create_mock.return_value = mock.Mock(spec=rules.IntrospectionRule,
                                             **{'as_dict.return_value': exp})

        headers = {conf.VERSION_HEADER: main._format_version((1, 5))}

        res = self.app.post('/v1/rules',
                            data=json.dumps(data),
                            headers=headers)
        self.assertEqual(200, res.status_code)
        create_mock.assert_called_once_with(conditions_json='cond',
                                            actions_json='act',
                                            uuid=self.uuid,
                                            description=None)
        self.assertEqual(exp, json.loads(res.data.decode('utf-8')))
Ejemplo n.º 4
0
    def test_create_api_less_1_6(self, create_mock):
        data = {'uuid': self.uuid,
                'conditions': 'cond',
                'actions': 'act'}
        exp = data.copy()
        exp['description'] = None
        create_mock.return_value = mock.Mock(spec=rules.IntrospectionRule,
                                             **{'as_dict.return_value': exp})

        headers = {conf_opts.VERSION_HEADER:
                   main._format_version((1, 5))}

        res = self.app.post('/v1/rules', data=json.dumps(data),
                            headers=headers)
        self.assertEqual(200, res.status_code)
        create_mock.assert_called_once_with(conditions_json='cond',
                                            actions_json='act',
                                            uuid=self.uuid,
                                            description=None)
        self.assertEqual(exp, json.loads(res.data.decode('utf-8')))
Ejemplo n.º 5
0
 def test_request_correct_version(self):
     headers = {conf.VERSION_HEADER:
                main._format_version(main.CURRENT_API_VERSION)}
     self._check_version_present(self.app.get('/', headers=headers))