本文整理汇总了Python中nectar.report.DownloadReport.headers方法的典型用法代码示例。如果您正苦于以下问题:Python DownloadReport.headers方法的具体用法?Python DownloadReport.headers怎么用?Python DownloadReport.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nectar.report.DownloadReport
的用法示例。
在下文中一共展示了DownloadReport.headers方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_single_path_failure
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_get_single_path_failure(self, mock_download_one):
report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
StringIO(''))
report.headers = {}
report.state = report.DOWNLOAD_FAILED
mock_download_one.return_value = report
self.assertRaises(IOError, self.repo._get_single_path, '/v1/repositories/pulp/crane/images')
示例2: download_one
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def download_one(request):
"""
Mock the download_one() method.
"""
self.assertEqual(request.url, 'https://registry.example.com/some/path')
self.assertEqual(type(request.destination), type(StringIO()))
report = DownloadReport(request.url, request.destination)
report.download_succeeded()
report.headers = {'some': 'cool stuff'}
report.destination.write("This is the stuff you've been waiting for.")
return report
示例3: test_get_tags
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_get_tags(self, mock_download_one):
body = json.dumps({'latest': 'abc123'})
report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/tags',
StringIO(body))
report.headers = {}
mock_download_one.return_value = report
ret = self.repo._get_single_path('/v1/repositories/pulp/crane/tags')
self.assertEqual(ret, {'latest': 'abc123'})
self.assertEqual(mock_download_one.call_count, 1)
self.assertTrue(isinstance(mock_download_one.call_args[0][0], DownloadRequest))
req = mock_download_one.call_args[0][0]
self.assertEqual(req.url, 'http://pulpproject.org/v1/repositories/pulp/crane/tags')
示例4: test_get_with_headers
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_get_with_headers(self, mock_download_one):
body = json.dumps(['abc123'])
report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
StringIO(body))
report.headers = {
self.repo.DOCKER_TOKEN_HEADER: 'token',
self.repo.DOCKER_ENDPOINT_HEADER: 'endpoint',
}
mock_download_one.return_value = report
self.repo._get_single_path('/v1/repositories/pulp/crane/images')
self.assertEqual(self.repo.token, 'token')
self.assertEqual(self.repo.endpoint, 'endpoint')
示例5: test_get_images
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_get_images(self, mock_download_one):
body = json.dumps(['abc123'])
report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
StringIO(body))
report.headers = {}
mock_download_one.return_value = report
ret = self.repo._get_single_path('/v1/repositories/pulp/crane/images')
self.assertEqual(ret, ['abc123'])
self.assertEqual(mock_download_one.call_count, 1)
self.assertTrue(isinstance(mock_download_one.call_args[0][0], DownloadRequest))
req = mock_download_one.call_args[0][0]
self.assertEqual(req.url, 'http://pulpproject.org/v1/repositories/pulp/crane/images')
# make sure this header is set, which is required by the docker API in order
# to give us an auth token
self.assertEqual(req.headers[self.repo.DOCKER_TOKEN_HEADER], 'true')
示例6: test_on_succeeded_pulp_requested
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_on_succeeded_pulp_requested(self, _insert_deferred):
entry = Mock(url='url-a')
request = Mock(uri='http://content-world.com/content/bear.rpm')
request.getHeader.side_effect = {
constants.PULP_STREAM_REQUEST_HEADER: True
}.__getitem__
report = DownloadReport('', '')
report.headers = {
'A': 1,
'B': 2,
}
# test
streamer = Streamer(Mock())
streamer._on_succeeded(entry, request, report)
# validation
self.assertFalse(_insert_deferred.called)
示例7: test_get_tags_from_endpoint
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_get_tags_from_endpoint(self, mock_download_one):
body = json.dumps({'latest': 'abc123'})
report = DownloadReport('http://some-endpoint.org/v1/repositories/pulp/crane/tags',
StringIO(body))
report.headers = {}
mock_download_one.return_value = report
self.repo.endpoint = 'some-endpoint.org'
# this lets us test that auth was added to the request
self.repo.token = 'letmein'
ret = self.repo._get_single_path('/v1/repositories/pulp/crane/tags')
self.assertEqual(ret, {'latest': 'abc123'})
self.assertEqual(mock_download_one.call_count, 1)
self.assertTrue(isinstance(mock_download_one.call_args[0][0], DownloadRequest))
req = mock_download_one.call_args[0][0]
self.assertEqual(req.url, 'http://some-endpoint.org/v1/repositories/pulp/crane/tags')
# make sure the authorization was added, which is usually required by an endpoint
self.assertTrue('Authorization' in req.headers)
示例8: test_download_headers
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import headers [as 别名]
def test_download_headers(self):
request = Mock(
uri='http://content-world.com/content/bear.rpm',
headers={})
request.setHeader.side_effect = request.headers.__setitem__
report = DownloadReport('', '')
report.headers = {
'A': 1,
'B': 2,
}
# should be ignored.
report.headers.update({k: '' for k in HOP_BY_HOP_HEADERS})
config = Mock(properties={
'streamer': {
'cache_timeout': 100
}
})
def get(s, p):
return config.properties[s][p]
config.get.side_effect = get
streamer = Mock(config=config)
# test
listener = DownloadListener(streamer, request)
listener.download_headers(report)
# validation
self.assertEqual(
request.headers,
{
'Cache-Control': 'public, s-maxage=100, max-age=100',
'A': 1,
'B': 2,
})