当前位置: 首页>>代码示例>>Python>>正文


Python utils.create_request函数代码示例

本文整理汇总了Python中zaqar.tests.unit.transport.websocket.utils.create_request函数的典型用法代码示例。如果您正苦于以下问题:Python create_request函数的具体用法?Python create_request怎么用?Python create_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bad_client_id

    def test_bad_client_id(self, text_id):
        action = consts.MESSAGE_POST
        body = {
            "queue_name": "kinder",
            "messages": [{"ttl": 60,
                          "body": ""}]
        }
        headers = {
            'Client-ID': text_id,
            'X-Project-ID': self.project_id
        }

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        req = test_utils.create_request(action, body, headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(400, resp['headers']['status'])

        action = consts.MESSAGE_GET
        body = {
            "queue_name": "kinder",
            "limit": 3,
            "echo": True
        }

        req = test_utils.create_request(action, body, headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(400, resp['headers']['status'])
开发者ID:openstack,项目名称:zaqar,代码行数:34,代码来源:test_messages.py

示例2: test_non_ascii_name

    def test_non_ascii_name(self):
        test_params = ((u'/queues/non-ascii-n\u0153me', 'utf-8'),
                       (u'/queues/non-ascii-n\xc4me', 'iso8859-1'))

        headers = {
            'Client-ID': uuidutils.generate_uuid(),
            'X-Project-ID': 'test-project' * 30
        }
        action = consts.QUEUE_CREATE
        body = {"queue_name": test_params[0]}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp.decode())
            self.assertEqual(400, resp['headers']['status'])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)

        body = {"queue_name": test_params[1]}
        req = test_utils.create_request(action, body, headers)

        self.protocol.onMessage(req, False)
开发者ID:openstack,项目名称:zaqar,代码行数:28,代码来源:test_queue_lifecycle.py

示例3: test_project_id_restriction

    def test_project_id_restriction(self):
        headers = {
            'Client-ID': uuidutils.generate_uuid(),
            'X-Project-ID': 'test-project' * 30
        }
        action = consts.QUEUE_CREATE
        body = {"queue_name": 'poptart'}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp.decode())
            self.assertEqual(400, resp['headers']['status'])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)

        headers['X-Project-ID'] = 'test-project'
        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp.decode())
            self.assertIn(resp['headers']['status'], [201, 204])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)
开发者ID:openstack,项目名称:zaqar,代码行数:30,代码来源:test_queue_lifecycle.py

示例4: test_post_optional_ttl

    def test_post_optional_ttl(self):
        messages = [{'body': 239},
                    {'body': {'key': 'value'}, 'ttl': 200}]

        action = consts.MESSAGE_POST
        body = {"queue_name": "kitkat",
                "messages": messages}
        req = test_utils.create_request(action, body, self.headers)

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(201, resp['headers']['status'])
        msg_id = resp['body']['message_ids'][0]

        action = consts.MESSAGE_GET
        body = {"queue_name": "kitkat", "message_id": msg_id}

        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(200, resp['headers']['status'])
        self.assertEqual(self.default_message_ttl,
                         resp['body']['messages']['ttl'])
开发者ID:openstack,项目名称:zaqar,代码行数:29,代码来源:test_messages.py

示例5: test_project_id_restriction

    def test_project_id_restriction(self):
        headers = {
            'Client-ID': str(uuid.uuid4()),
            'X-Project-ID': 'test-project' * 30
        }
        action = "queue_create"
        body = {"queue_name": 'poptart'}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp)
            self.assertEqual(resp['headers']['status'], 400)

        send_mock.side_effect = validator
        self.protocol.onMessage(req, False)

        headers['X-Project-ID'] = 'test-project'
        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp)
            self.assertEqual(resp['headers']['status'], 201)

        send_mock.side_effect = validator
        self.protocol.onMessage(req, False)
开发者ID:wenchma,项目名称:zaqar,代码行数:30,代码来源:test_queue_lifecycle.py

示例6: test_bulk_delete

    def test_bulk_delete(self):
        resp = self._post_messages("nerds", repeat=5)
        msg_ids = resp['body']['message_ids']

        action = "message_delete_many"
        body = {"queue_name": "nerds",
                "message_ids": msg_ids}

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0])
        self.assertEqual(resp['headers']['status'], 204)

        action = "message_get"
        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0])
        self.assertEqual(resp['headers']['status'], 400)

        # Safe to delete non-existing ones
        action = "message_delete_many"
        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0])
        self.assertEqual(resp['headers']['status'], 204)

        # Even after the queue is gone
        action = "queue_delete"
        body = {"queue_name": "nerds"}
        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0])
        self.assertEqual(resp['headers']['status'], 204)

        action = "message_delete_many"
        body = {"queue_name": "nerds",
                "message_ids": msg_ids}
        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0])
        self.assertEqual(resp['headers']['status'], 204)
开发者ID:wenchma,项目名称:zaqar,代码行数:52,代码来源:test_messages.py

示例7: test_bulk_delete

    def test_bulk_delete(self):
        resp = self._post_messages("nerds", repeat=5)
        msg_ids = resp['body']['message_ids']

        action = consts.MESSAGE_DELETE_MANY
        body = {"queue_name": "nerds",
                "message_ids": msg_ids}

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(204, resp['headers']['status'])

        action = consts.MESSAGE_GET
        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(400, resp['headers']['status'])

        # Safe to delete non-existing ones
        action = consts.MESSAGE_DELETE_MANY
        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(204, resp['headers']['status'])

        # Even after the queue is gone
        action = consts.QUEUE_DELETE
        body = {"queue_name": "nerds"}
        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(204, resp['headers']['status'])

        action = consts.MESSAGE_DELETE_MANY
        body = {"queue_name": "nerds",
                "message_ids": msg_ids}
        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(204, resp['headers']['status'])
开发者ID:openstack,项目名称:zaqar,代码行数:52,代码来源:test_messages.py

示例8: test_no_metadata

    def test_no_metadata(self):
        headers = {
            'Client-ID': str(uuid.uuid4()),
            'X-Project-ID': 'test-project'
        }
        action = consts.QUEUE_CREATE
        body = {"queue_name": "fizbat"}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp)
            self.assertEqual(201, resp['headers']['status'])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)

        def validator(resp, isBinary):
            resp = json.loads(resp)
            self.assertEqual(204, resp['headers']['status'])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)
开发者ID:ollie314,项目名称:zaqar,代码行数:27,代码来源:test_queue_lifecycle.py

示例9: test_way_too_much_metadata

    def test_way_too_much_metadata(self):
        headers = {
            'Client-ID': uuidutils.generate_uuid(),
            'X-Project-ID': 'test-project'
        }
        action = consts.QUEUE_CREATE
        body = {"queue_name": "peppermint",
                "metadata": {"messages": {"ttl": 600},
                             "padding": "x"}
                }

        max_size = self.transport_cfg.max_queue_metadata
        body["metadata"]["padding"] = "x" * max_size * 5

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp.decode())
            self.assertEqual(400, resp['headers']['status'])

        sender.side_effect = validator
        self.protocol.onMessage(req, False)
开发者ID:openstack,项目名称:zaqar,代码行数:26,代码来源:test_queue_lifecycle.py

示例10: test_subscription_list

    def test_subscription_list(self):
        sub = self.boot.storage.subscription_controller.create(
            'kitkat', '', 600, {}, project=self.project_id)
        self.addCleanup(
            self.boot.storage.subscription_controller.delete, 'kitkat', sub,
            project=self.project_id)
        action = 'subscription_list'
        body = {'queue_name': 'kitkat'}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        response = {
            'body': {
                'subscriptions': [{
                    'subscriber': '',
                    'source': 'kitkat',
                    'options': {},
                    'id': str(sub),
                    'ttl': 600}]},
            'headers': {'status': 200},
            'request': {'action': 'subscription_list',
                        'body': {'queue_name': 'kitkat'},
                        'api': 'v2', 'headers': self.headers}}

        self.assertEqual(1, sender.call_count)
        self.assertEqual(response, json.loads(sender.call_args[0][0]))
开发者ID:wangxiyuan1,项目名称:zaqar,代码行数:31,代码来源:test_subscriptions.py

示例11: test_subscription_delete

    def test_subscription_delete(self):
        sub = self.boot.storage.subscription_controller.create(
            'kitkat', '', 600, {}, project=self.project_id)
        self.addCleanup(
            self.boot.storage.subscription_controller.delete, 'kitkat', sub,
            project=self.project_id)
        action = 'subscription_delete'
        body = {'queue_name': 'kitkat', 'subscription_id': str(sub)}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)
        data = list(
            next(
                self.boot.storage.subscription_controller.list(
                    'kitkat', self.project_id)))
        self.assertEqual([], data)

        response = {
            'body': 'Subscription %s removed.' % str(sub),
            'headers': {'status': 204},
            'request': {'action': 'subscription_delete',
                        'body': {'queue_name': 'kitkat',
                                 'subscription_id': str(sub)},
                        'api': 'v2', 'headers': self.headers}}
        self.assertEqual(1, sender.call_count)
        self.assertEqual(response, json.loads(sender.call_args[0][0]))
开发者ID:wangxiyuan1,项目名称:zaqar,代码行数:30,代码来源:test_subscriptions.py

示例12: test_list_returns_503_on_nopoolfound_exception

    def test_list_returns_503_on_nopoolfound_exception(self):
        headers = {
            'Client-ID': uuidutils.generate_uuid(),
            'X-Project-ID': 'test-project'
        }
        action = consts.QUEUE_LIST
        body = {}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp.decode())
            self.assertEqual(503, resp['headers']['status'])

        sender.side_effect = validator

        queue_controller = self.boot.storage.queue_controller

        with mock.patch.object(queue_controller, 'list') as mock_queue_list:

            def queue_generator():
                raise storage_errors.NoPoolFound()

            # This generator tries to be like queue controller list generator
            # in some ways.
            def fake_generator():
                yield queue_generator()
                yield {}
            mock_queue_list.return_value = fake_generator()
            self.protocol.onMessage(req, False)
开发者ID:openstack,项目名称:zaqar,代码行数:34,代码来源:test_queue_lifecycle.py

示例13: test_subscription_create_trust

    def test_subscription_create_trust(self, create_trust):
        create_trust.return_value = 'trust_id'
        action = 'subscription_create'
        body = {'queue_name': 'kitkat', 'ttl': 600,
                'subscriber': 'trust+http://example.com'}
        self.protocol._auth_env = {}
        self.protocol._auth_env['X-USER-ID'] = 'user-id'
        self.protocol._auth_env['X-ROLES'] = 'my-roles'

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        send_mock.start()

        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)
        [subscriber] = list(
            next(
                self.boot.storage.subscription_controller.list(
                    'kitkat', self.project_id)))
        self.addCleanup(
            self.boot.storage.subscription_controller.delete, 'kitkat',
            subscriber['id'], project=self.project_id)
        self.assertEqual('trust+http://example.com',
                         subscriber['subscriber'])
        self.assertEqual({'trust_id': 'trust_id'}, subscriber['options'])

        self.assertEqual('user-id', create_trust.call_args[0][1])
        self.assertEqual(self.project_id, create_trust.call_args[0][2])
        self.assertEqual(['my-roles'], create_trust.call_args[0][3])
开发者ID:AvnishPal,项目名称:zaqar,代码行数:29,代码来源:test_subscriptions.py

示例14: test_subscription_get

    def test_subscription_get(self):
        sub = self.boot.storage.subscription_controller.create(
            'kitkat', '', 600, {}, project=self.project_id)
        self.addCleanup(
            self.boot.storage.subscription_controller.delete, 'kitkat', sub,
            project=self.project_id)
        action = 'subscription_get'
        body = {'queue_name': 'kitkat', 'subscription_id': str(sub)}

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        sender = send_mock.start()

        req = test_utils.create_request(action, body, self.headers)
        self.protocol.onMessage(req, False)

        expected_response_without_age = {
            'body': {'subscriber': '',
                     'source': 'kitkat',
                     'options': {},
                     'id': str(sub),
                     'ttl': 600},
            'headers': {'status': 200},
            'request': {'action': 'subscription_get',
                        'body': {'queue_name': 'kitkat',
                                 'subscription_id': str(sub)},
                        'api': 'v2', 'headers': self.headers}}

        self.assertEqual(1, sender.call_count)
        response = json.loads(sender.call_args[0][0])
        # Get and remove age from the actual response.
        actual_sub_age = response['body'].pop('age')
        self.assertLessEqual(0, actual_sub_age)
        self.assertEqual(expected_response_without_age, response)
开发者ID:AvnishPal,项目名称:zaqar,代码行数:34,代码来源:test_subscriptions.py

示例15: test_too_much_metadata

    def test_too_much_metadata(self):
        headers = {
            'Client-ID': str(uuid.uuid4()),
            'X-Project-ID': 'test-project'
        }
        action = "queue_create"
        body = {"queue_name": "buttertoffee",
                "metadata": {"messages": {"ttl": 600},
                             "padding": "x"}
                }

        max_size = self.transport_cfg.max_queue_metadata
        body["metadata"]["padding"] = "x" * max_size

        send_mock = mock.patch.object(self.protocol, 'sendMessage')
        self.addCleanup(send_mock.stop)
        send_mock.start()

        req = test_utils.create_request(action, body, headers)

        def validator(resp, isBinary):
            resp = json.loads(resp)
            self.assertEqual(resp['headers']['status'], 400)

        send_mock.side_effect = validator
        self.protocol.onMessage(req, False)
开发者ID:wenchma,项目名称:zaqar,代码行数:26,代码来源:test_queue_lifecycle.py


注:本文中的zaqar.tests.unit.transport.websocket.utils.create_request函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。