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


Python Mock.url方法代码示例

本文整理汇总了Python中mock.Mock.url方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.url方法的具体用法?Python Mock.url怎么用?Python Mock.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


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

示例1: get_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
def get_mock():
    ysc = youtube_status_code
    yu = youtube_url
    yc = youtube_cookies
    yt = youtube_text
    yh = youtube_headers
    yosc = youtube_oembed_status_code
    you = youtube_oembed_url
    yoh = youtube_oembed_headers
    yot = youtube_oembed_text

    mock_obj_1 = Mock()
    mock_obj_1.status_code = ysc
    mock_obj_1.url = yu
    mock_obj_1.headers = yh
    mock_obj_1.cookies = yc
    mock_obj_1.text = yt
    mock_obj_1.json = lambda: json.loads(mock_obj_1.text)

    mock_obj_2 = Mock()
    mock_obj_2.status_code = 200
    mock_obj_2.url = you
    mock_obj_2.headers = yoh
    mock_obj_2.text = yot
    mock_obj_2.json = lambda: json.loads(mock_obj_2.text)

    return [mock_obj_1, mock_obj_1, mock_obj_2]
开发者ID:greyside,项目名称:django-mesh,代码行数:29,代码来源:youtube_data.py

示例2: create_mock_api

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
 def create_mock_api(cls):
   """Builds up a mock API object, with a mock SchedulerProxy"""
   mock_scheduler = Mock()
   mock_scheduler.url = "http://something_or_other"
   mock_scheduler_client = Mock()
   mock_scheduler_client.scheduler.return_value = mock_scheduler
   mock_scheduler_client.url = "http://something_or_other"
   mock_api = Mock(spec=HookedAuroraClientAPI)
   mock_api.scheduler_proxy = mock_scheduler_client
   return (mock_api, mock_scheduler_client)
开发者ID:kevints,项目名称:aurora,代码行数:12,代码来源:util.py

示例3: make_install_req

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def make_install_req(ver=None):
        req = Mock()
        req.project_name = test_project_name
        if ver:
            req.url = url_template % str(ver)
            req.specs = [('==', ver)]
        else:
            req.url = url_template.replace('@','') % ''
            req.specs = []

        install_requirement = InstallRequirement(req, None, editable = True, url = req.url)

        return install_requirement
开发者ID:ecolitan,项目名称:snakebasket,代码行数:15,代码来源:test_sb_versions.py

示例4: test_so

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_so(self):
        from cmds.so import so
        import urllib2
        socket = Mock()

        self.assertEqual(so(socket, {'arguments': '!so'}),
            'Usage: !so <search term>')
        self.assertEqual(so(socket, {'arguments': '!so  '}),
            'Usage: !so <search term>')

        with patch('stackexchange.Site') as s:
            api = Mock()
            api.search.side_effect = urllib2.HTTPError(code=42, fp=file,
                    url='http://foo', msg='FooError', hdrs='headers')

            s.return_value = api

            self.assertEqual(so(socket, {'arguments': '!so foo'}),
                "The server couldn't fulfill the request!" + \
                        "\r\nReason: FooError\r\nCode: 42")

            api.search.side_effect = None
            api.search.return_value = []
            self.assertEqual(so(socket, {'arguments': '!so foo'}), 'Not found: foo')

            result = Mock()
            result.title = 'foo_title'
            result.url = 'foo_url'
            api.search.return_value = [result]
            self.assertEqual(so(socket, {'arguments': '!so foo'}),
                'foo_title\r\nfoo_url')
开发者ID:Chiggins,项目名称:IRC-Bot,代码行数:33,代码来源:cmds_tests.py

示例5: setup_mock_api

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
 def setup_mock_api(cls):
   """Builds up a mock API object, with a mock SchedulerProxy"""
   mock_api = Mock(spec=HookedAuroraClientAPI)
   mock_scheduler = Mock()
   mock_scheduler.url = "http://something_or_other"
   mock_api.scheduler = mock_scheduler
   return (mock_api, mock_scheduler)
开发者ID:mgargenta,项目名称:incubator-aurora,代码行数:9,代码来源:test_create.py

示例6: get_signed_grade_mock_request_with_correct_signature

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def get_signed_grade_mock_request_with_correct_signature(self):
        """
        Generate a proper LTI request object
        """
        mock_request = Mock()
        mock_request.headers = {
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': (
                u'OAuth realm="https://testurl/", oauth_body_hash="wwzA3s8gScKD1VpJ7jMt9b%2BMj9Q%3D",'
                'oauth_nonce="18821463", oauth_timestamp="1409321145", '
                'oauth_consumer_key="__consumer_key__", oauth_signature_method="HMAC-SHA1", '
                'oauth_version="1.0", oauth_signature="fHsE1hhIz76/msUoMR3Lyb7Aou4%3D"'
            )
        }
        mock_request.url = u'https://testurl'
        mock_request.http_method = u'POST'
        mock_request.method = mock_request.http_method

        mock_request.body = (
            '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
            '<imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">'
            '<imsx_POXHeader><imsx_POXRequestHeaderInfo><imsx_version>V1.0</imsx_version>'
            '<imsx_messageIdentifier>edX_fix</imsx_messageIdentifier></imsx_POXRequestHeaderInfo>'
            '</imsx_POXHeader><imsx_POXBody><replaceResultRequest><resultRecord><sourcedGUID>'
            '<sourcedId>MITxLTI/MITxLTI/201x:localhost%3A8000-i4x-MITxLTI-MITxLTI-lti-3751833a214a4f66a0d18f63234207f2:363979ef768ca171b50f9d1bfb322131</sourcedId>'  # pylint: disable=line-too-long
            '</sourcedGUID><result><resultScore><language>en</language><textString>0.32</textString></resultScore>'
            '</result></resultRecord></replaceResultRequest></imsx_POXBody></imsx_POXEnvelopeRequest>'
        )

        return mock_request
开发者ID:dehamzah,项目名称:edx-platform,代码行数:33,代码来源:test_lti_unit.py

示例7: test_unbind

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_unbind(self, mock_gofer_agent):
        context = Mock()
        context.agent_id = "123"
        context.secret = "test-secret"
        context.url = "http://broker.com"
        context.transport = "qpid"
        context.authenticator = Mock()
        context.details = {"task_id": "4567"}
        context.reply_queue = "pulp.task"

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_consumer = Mock()
        mock_agent.Consumer = Mock(return_value=mock_consumer)

        bindings = []
        options = {}

        Consumer.unbind(context, bindings, options)

        mock_gofer_agent.assert_called_with(
            context.agent_id,
            ctag=context.reply_queue,
            url=context.url,
            transport=context.transport,
            secret=context.secret,
            authenticator=context.authenticator,
            any=context.details,
        )

        mock_consumer.unbind.assert_called_with(bindings, options)
开发者ID:lzap,项目名称:pulp,代码行数:33,代码来源:test_agent.py

示例8: topic

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
 def topic(self):
     spec = BaseThumbfySpec(key=KEY)
     spec.crypto = Mock(spec=CryptoURL)
     field = Mock()
     field.url = IMAGE_URL
     spec.generate(field)
     return (spec, IMAGE_URL)
开发者ID:adonescunha,项目名称:thumbfy,代码行数:9,代码来源:base_thumbfy_spec_vows.py

示例9: get_signed_grade_mock_request

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def get_signed_grade_mock_request(self, namespace_lti_v1p1=True):
        """
        Example of signed request from LTI Provider.

        When `namespace_v1p0` is set to True then the default namespase from
        LTI 1.1 will be used. Otherwise fake namespace will be added to XML.
        """
        mock_request = Mock()
        mock_request.headers = {
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': u'OAuth oauth_nonce="135685044251684026041377608307", \
                oauth_timestamp="1234567890", oauth_version="1.0", \
                oauth_signature_method="HMAC-SHA1", \
                oauth_consumer_key="test_client_key", \
                oauth_signature="my_signature%3D", \
                oauth_body_hash="JEpIArlNCeV4ceXxric8gJQCnBw="'
        }
        mock_request.url = u'http://testurl'
        mock_request.http_method = u'POST'

        params = {}
        if not namespace_lti_v1p1:
            params = {
                'namespace': "http://www.fakenamespace.com/fake"
            }
        mock_request.body = self.get_request_body(params)

        return mock_request
开发者ID:dehamzah,项目名称:edx-platform,代码行数:31,代码来源:test_lti_unit.py

示例10: test_send

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_send(self, mock_gofer_agent):
        context = Mock()
        context.agent_id = "123"
        context.url = "http://broker.com"
        context.transport = "qpid"
        context.authenticator = Mock()

        task_id = "5678"
        criteria = {"match": {"task_id": task_id}}

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_admin = Mock()
        mock_agent.Admin = Mock(return_value=mock_admin)

        agent = PulpAgent()
        agent.cancel(context, task_id)

        mock_gofer_agent.assert_called_with(
            context.agent_id,
            url=context.url,
            transport=context.transport,
            authenticator=context.authenticator,
            async=True,
        )

        mock_admin.cancel.assert_called_with(criteria=criteria)
开发者ID:lzap,项目名称:pulp,代码行数:29,代码来源:test_agent.py

示例11: test_download

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_download(self, mock_repo_controller, mock_dl_request):
        # Setup
        mock_catalog = Mock()
        mock_catalog.importer_id = 'mock_id'
        mock_catalog.url = 'http://dev.null/'
        mock_catalog.data = {'k': 'v'}
        mock_request = Mock()
        mock_data = {'catalog_entry': mock_catalog, 'client_request': mock_request}
        mock_responder = Mock()
        mock_importer = Mock()
        mock_importer_config = Mock()
        mock_downloader = mock_importer.get_downloader.return_value
        mock_repo_controller.get_importer_by_id.return_value = (mock_importer,
                                                                mock_importer_config)

        # Test
        self.streamer._download(mock_catalog, mock_request, mock_responder)
        mock_repo_controller.get_importer_by_id.assert_called_once_with(mock_catalog.importer_id)
        mock_dl_request.assert_called_once_with(mock_catalog.url, mock_responder, data=mock_data)
        mock_importer.get_downloader.assert_called_once_with(
            mock_importer_config, mock_catalog.url, **mock_catalog.data)
        self.assertEqual(mock_request, mock_downloader.event_listener.request)
        self.assertEqual(self.config, mock_downloader.event_listener.streamer_config)
        mock_downloader.download_one.assert_called_once_with(mock_dl_request.return_value,
                                                             events=True)
        mock_downloader.config.finalize.assert_called_once_with()
开发者ID:maxamillion,项目名称:pulp,代码行数:28,代码来源:test_server.py

示例12: test_is_valid_local_copy

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
 def test_is_valid_local_copy(self):
     remote = Mock()
     remote.url = self.url
     repo = Mock()
     repo.remote.return_value = remote
     self.git_mock.Repo.return_value = repo
     self.assertTrue(self.git_manager.is_valid_local_copy)
开发者ID:holandes22,项目名称:rafee,代码行数:9,代码来源:test_git_manager.py

示例13: test_json_response

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
def test_json_response():
    class HTTPError(Exception):
        pass

    response = Mock()
    response.json.return_value = {'a': 1, 'b': {'c': 2, 'd': 3}}
    response.raise_for_status.side_effect = [None, HTTPError()]

    mock = Mock()
    mock.url = "http://example.com"
    mock.http_client.request.return_value = response

    json = JSONResponseProperty(method="POST")
    rv = json.provide_value(mock)

    assert rv == {
        'a': 1,
        'b': {
            'c': 2,
            'd': 3
        }
    }
    response.raise_for_status.assert_called_once_with()
    mock.http_client.request.assert_called_once_with(
        method="POST", url="http://example.com")

    with raises(HTTPError):
        json.provide_value(mock)
开发者ID:douban,项目名称:brownant,代码行数:30,代码来源:test_network.py

示例14: test_unregistered

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_unregistered(self, mock_gofer_agent):
        context = Mock()
        context.agent_id = "123"
        context.secret = "test-secret"
        context.url = "http://broker.com"
        context.transport = "qpid"
        context.authenticator = Mock()

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_consumer = Mock()
        mock_agent.Consumer = Mock(return_value=mock_consumer)

        # test capability

        Consumer.unregistered(context)

        # validation

        mock_gofer_agent.assert_called_with(
            context.agent_id,
            url=context.url,
            secret=context.secret,
            authenticator=context.authenticator,
            transport=context.transport,
            async=True,
        )

        mock_consumer.unregistered.assert_called_with()
开发者ID:lzap,项目名称:pulp,代码行数:31,代码来源:test_agent.py

示例15: test_auth_header_preserved_from_s3_redirects

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import url [as 别名]
    def test_auth_header_preserved_from_s3_redirects(self):
        request = AWSRequest()
        request.url = 'https://bucket.s3.amazonaws.com/'
        request.method = 'GET'
        request.headers['Authorization'] = 'original auth header'
        prepared_request = request.prepare()

        fake_response = Mock()
        fake_response.headers = {
            'location': 'https://bucket.s3-us-west-2.amazonaws.com'}
        fake_response.url = request.url
        fake_response.status_code = 307
        fake_response.is_permanent_redirect = False
        # This line is needed to disable the cookie handling
        # code in requests.
        fake_response.raw._original_response = None

        success_response = Mock()
        success_response.raw._original_response = None
        success_response.is_redirect = False
        success_response.status_code = 200
        session = PreserveAuthSession()
        session.send = Mock(return_value=success_response)

        list(session.resolve_redirects(
            fake_response, prepared_request, stream=False))

        redirected_request = session.send.call_args[0][0]
        # The Authorization header for the newly sent request should
        # still have our original Authorization header.
        self.assertEqual(
            redirected_request.headers['Authorization'],
            'original auth header')
开发者ID:brint,项目名称:botocore,代码行数:35,代码来源:test_endpoint.py


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