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


Python MagicMock.url方法代码示例

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


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

示例1: test_get_file_name_when_content_disposition_filename_is_missing

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
def test_get_file_name_when_content_disposition_filename_is_missing():
    # Example of a feed with such files:
    # http://feeds.wnyc.org/radiolab?format=xml
    response = MagicMock()
    response.headers = {'Content-Disposition': 'attachment'}
    response.url = 'http://feeds.wnyc.org/~r/radiolab/~5/KYQG_JtkTYM/radiolab_podcast16cellmates.mp3'
    assert get_file_name(response) == 'radiolab_podcast16cellmates.mp3'
开发者ID:matachi,项目名称:riley,代码行数:9,代码来源:download_test.py

示例2: test_prefer_name_from_headers

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
def test_prefer_name_from_headers():
    response = MagicMock()
    response.headers = {}
    response.url = 'http://example.com/abc.mp3'
    assert get_file_name(response) == 'abc.mp3'
    response.headers = {'Content-Disposition': 'attachment;filename="def.mp3"'}
    assert get_file_name(response) == 'def.mp3'
开发者ID:matachi,项目名称:riley,代码行数:9,代码来源:download_test.py

示例3: init_branches

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def init_branches(self):
        branch = MagicMock()
        branch.name = "master"
        commit = MagicMock()
        commit.sha = "sha"
        commit.url = "url"
        branch.commit = commit

        return [branch]
开发者ID:luiseduardo1,项目名称:Github-API,代码行数:11,代码来源:GithubTest.py

示例4: prepareReply

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
 def prepareReply(self, method: str, url: str, status_code: int, response: Union[bytes, dict]) -> None:
     reply_mock = MagicMock()
     reply_mock.url().toString.return_value = url
     reply_mock.operation.return_value = self._OPERATIONS[method]
     reply_mock.attribute.return_value = status_code
     reply_mock.finished = FakeSignal()
     reply_mock.isFinished.return_value = False
     reply_mock.readAll.return_value = response if isinstance(response, bytes) else json.dumps(response).encode()
     self.replies[method, url] = reply_mock
     Logger.log("i", "Prepared mock {}-response to {} {}", status_code, method, url)
开发者ID:TinkerGnome,项目名称:Cura,代码行数:12,代码来源:NetworkManagerMock.py

示例5: test_should_convert_single_url_to_source_with_timeextractor

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def test_should_convert_single_url_to_source_with_timeextractor(self):
        urlsrc_to_return = MagicMock()
        urlsrc_to_return.url = self.url
        timeextractor = MagicMock(return_value=self.current_time)
        urlsrc_func = MagicMock(return_value=urlsrc_to_return)

        converter = source.SourceConverter(urlsrc_func, timeextractor=timeextractor)
        srcs = converter.to_sources(self.url)

        timeextractor.assert_called_with(urlsrc_to_return.url)
        self.assertEqual(srcs, [urlsrc_to_return])
        self.assertEqual(urlsrc_to_return.timestamp, self.current_time)
开发者ID:wxmann,项目名称:FileSaverPy,代码行数:14,代码来源:sourcetest.py

示例6: init_issues

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
 def init_issues(self):
     issue = MagicMock()
     repository = MagicMock()
     repository.url = "repository_url"
     issue.id = 3
     issue.url = "issue_url"
     issue.repository = repository
     issue.labels_url = "labels_url"
     issue.comments_url = "comments_url"
     issue.events_url = "events_url"
     issue.html_url = "html_url"
     issue.number = 5
     issue.state = "open"
     issue.title = "title"
     issue.body = "git gud or git rekt"
     issue.user = self.init_user(self)
     issue.assignee = None
     issue.milestone = None
     issue.labels = None
     issue.comments = "comments"
     issue.pull_request = None
     return [issue]
开发者ID:luiseduardo1,项目名称:Github-API,代码行数:24,代码来源:GithubTest.py

示例7: test__get_resource

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def test__get_resource(self, req_mock):
        ex_content = b'1.1.1.1\n2.2.2.2\n'
        expected = Resource(ex_content, self.url, 200)

        response_mock = MagicMock()
        response_mock.status_code = 200
        response_mock.url = self.url
        response_mock.content = ex_content

        req_mock.get.return_value = response_mock

        result = self.fetcher._get_resource(self.fetcher.url)
        self.assertEqual(result, expected)
开发者ID:flazzarini,项目名称:blocklister,代码行数:15,代码来源:test_fetcher.py

示例8: build

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
 def build(self):
     m = MagicMock()
     m.text = self._text
     m.url = self._url
     m.status_code = self._status_code
     m.headers = CaseInsensitiveDict({
         "content-type": self._content_type
     })
     m.content = self._content
     m.encoding = self._encoding
     m.elapsed = datetime.timedelta(seconds=self._seconds, microseconds=self._microseconds)
     m.json.return_value = self._json
     return m
开发者ID:tadashi-aikawa,项目名称:gemini,代码行数:15,代码来源:test_executor.py

示例9: create_client

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def create_client(self):
        args = MagicMock()
        args.username = None
        args.url = None
        config = load_config()
        # Every test runs with a new key, so we must remove existing
        # files
        key_file = config.get('DEFAULT', 'key_file')
        if os.path.exists(key_file):
            os.remove(key_file)
        do_init(args, config)
        config = load_config()

        url = os.environ.get('RESTAPI_URL', config.get('DEFAULT', 'url'))
        key_file = config.get('DEFAULT', 'key_file')
        return SupplyChainClient(url, key_file)
开发者ID:feihujiang,项目名称:sawtooth-core,代码行数:18,代码来源:test_supplychain_integration.py

示例10: test_download_url

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
def test_download_url(tmpdir, monkeypatch):
    monkeypatch.setattr('riley.download._download', dummy_download)

    response = MagicMock()
    response.url = 'http://example.com/123.mp3'
    response.headers.get.return_value = None
    # The header 'content-length' is missing, which was the case with
    # http://www.linuxvoice.com/podcast_opus.rss
    monkeypatch.setattr(
        'riley.download.requests.get', lambda x, stream: response)

    time_struct = time.strptime('2015-11-12 01:02:03', '%Y-%m-%d %H:%M:%S')

    download(response.url, tmpdir.strpath, time_struct)

    file = tmpdir.join('123.mp3')
    assert file.read() == 'abc'
    assert os.stat(file.strpath).st_mtime == time.mktime(time_struct)
开发者ID:matachi,项目名称:riley,代码行数:20,代码来源:download_test.py

示例11: test_put

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
def test_put():
    output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
    mocked_network_manager = MagicMock()
    output_device._manager = mocked_network_manager

    # Create a fake reply (we cant use a QReply, since those are abstract C++)
    reply = MagicMock()
    reply.operation = MagicMock(return_value=QNetworkAccessManager.PostOperation)
    reply.url = MagicMock(return_value=QUrl("127.0.0.1"))
    mocked_network_manager.put = MagicMock(return_value = reply)

    mocked_callback_handler = MagicMock()
    output_device.put("whatever", "omgzomg", on_finished = mocked_callback_handler.onFinished)

    # So we now fake that the request was sucesful.
    output_device._handleOnFinished(reply)

    # We expect to get a callback regarding this.
    mocked_callback_handler.onFinished.assert_called_once_with(reply)
开发者ID:Ultimaker,项目名称:Cura,代码行数:21,代码来源:TestNetworkedPrinterOutputDevice.py

示例12: test__get_resource_gziped

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def test__get_resource_gziped(self, req_mock):
        ex_content = b'1.1.1.1\n2.2.2.2\n'
        expected = Resource(ex_content, self.gzip_url, 200)

        # To test gzip decompression lets gzip our `ex_content`
        ex_content_gziped = BytesIO()
        g = GzipFile(fileobj=ex_content_gziped, mode='w', compresslevel=5)
        g.write(ex_content)
        g.close()
        ex_content_gziped.seek(0)

        response_mock = MagicMock()
        response_mock.status_code = 200
        response_mock.url = self.gzip_url
        response_mock.content = ex_content_gziped.read()

        req_mock.get.return_value = response_mock

        result = self.fetcher._get_resource(self.gzip_url)
        self.assertEqual(result, expected)
开发者ID:flazzarini,项目名称:blocklister,代码行数:22,代码来源:test_fetcher.py

示例13: init_user

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
    def init_user(self):
        user = MagicMock()

        user.login = "login"
        user.id = 5
        user.avatar_url = " avatar_url"
        user.gravatar_id = 9
        user.url = "user_url"
        user.html_url = "html_url"
        user.followers_url = " followers_url"
        user.gists_url = "gists_url"
        user.starred_url = "starred_url"
        user.subscriptions_url = "subscriptions_url"
        user.organizations_url = "organizations_url"
        user.repos_url = "repos_url"
        user.events_url = "events_url"
        user.received_events_url = "received_events_url "
        user.type = "user"

        return user
开发者ID:luiseduardo1,项目名称:Github-API,代码行数:22,代码来源:GithubTest.py

示例14: _create_mock_slave

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
 def _create_mock_slave(self, num_executors=5):
     mock = MagicMock(spec_set=Slave(slave_url=self._FAKE_SLAVE_URL, num_executors=num_executors))
     mock.url = self._FAKE_SLAVE_URL
     mock.num_executors = num_executors
     return mock
开发者ID:mdengler,项目名称:ClusterRunner,代码行数:7,代码来源:test_build.py

示例15: create_submission

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import url [as 别名]
def create_submission(url="", title="", subreddit=""):
    submission = MagicMock()
    submission.url = url
    submission.title = title
    submission.subreddit.display_name = subreddit
    return submission
开发者ID:TylerRidenour,项目名称:redditcurl,代码行数:8,代码来源:test_base.py


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