本文整理汇总了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'
示例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'
示例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]
示例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)
示例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)
示例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]
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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