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


Python responses.HEAD属性代码示例

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


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

示例1: test_cached_path_extract_remote_tar

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_cached_path_extract_remote_tar(self):
        url = "http://fake.datastore.com/utf-8.tar.gz"
        byt = open(self.tar_file, "rb").read()

        responses.add(
            responses.GET,
            url,
            body=byt,
            status=200,
            content_type="application/tar+gzip",
            stream=True,
            headers={"Content-Length": str(len(byt))},
        )
        responses.add(
            responses.HEAD, url, status=200, headers={"ETag": "fake-etag"},
        )

        extracted = cached_path(url, cache_dir=self.TEST_DIR, extract_archive=True)
        assert extracted.endswith("-extracted")
        self.check_extracted(extracted) 
开发者ID:allenai,项目名称:allennlp,代码行数:22,代码来源:file_utils_test.py

示例2: test_cached_path_extract_remote_zip

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_cached_path_extract_remote_zip(self):
        url = "http://fake.datastore.com/utf-8.zip"
        byt = open(self.zip_file, "rb").read()

        responses.add(
            responses.GET,
            url,
            body=byt,
            status=200,
            content_type="application/zip",
            stream=True,
            headers={"Content-Length": str(len(byt))},
        )
        responses.add(
            responses.HEAD, url, status=200, headers={"ETag": "fake-etag"},
        )

        extracted = cached_path(url, cache_dir=self.TEST_DIR, extract_archive=True)
        assert extracted.endswith("-extracted")
        self.check_extracted(extracted) 
开发者ID:allenai,项目名称:allennlp,代码行数:22,代码来源:file_utils_test.py

示例3: mock_component_taskcluster_artifact

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def mock_component_taskcluster_artifact() -> None:
    responses.add(
        responses.HEAD,
        "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.source.source-bugzilla-info/artifacts/public/components.json",
        status=200,
        headers={"ETag": "100"},
    )

    responses.add(
        responses.GET,
        "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.source.source-bugzilla-info/artifacts/public/components.json",
        status=200,
        json={},
    )

    repository.download_component_mapping() 
开发者ID:mozilla,项目名称:bugbug,代码行数:18,代码来源:conftest.py

示例4: test_download_missing

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_download_missing(tmp_path, mock_zst):
    url = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.zst"
    url_version = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.version"

    db_path = tmp_path / "prova.json"
    db.register(db_path, url, 1)

    responses.add(
        responses.HEAD,
        url,
        status=404,
        headers={"ETag": "123", "Accept-Encoding": "zstd"},
    )

    responses.add(
        responses.GET, url, status=404, body=requests.exceptions.HTTPError("HTTP error")
    )

    responses.add(responses.GET, url_version, status=404)

    assert not db.download(db_path)
    assert not os.path.exists(db_path)

    with pytest.raises(Exception, match="Last-Modified is not available"):
        db.last_modified(db_path) 
开发者ID:mozilla,项目名称:bugbug,代码行数:27,代码来源:test_db.py

示例5: test_trainer

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_trainer():
    # Pretend the DB was already downloaded and no new DB is available.

    url = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_bugs.latest/artifacts/public/bugs.json"

    responses.add(
        responses.GET,
        f"{url}.version",
        status=200,
        body=str(db.DATABASES[bugzilla.BUGS_DB]["version"]),
    )

    responses.add(
        responses.HEAD, f"{url}.zst", status=200, headers={"ETag": "etag"},
    )

    trainer.Trainer().go(trainer.parse_args(["defect"])) 
开发者ID:mozilla,项目名称:bugbug,代码行数:19,代码来源:test_trainer.py

示例6: test_download_check_missing

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_download_check_missing():
    url = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug/prova.txt"

    responses.add(
        responses.HEAD,
        url,
        status=404,
        headers={"ETag": "123", "Last-Modified": "2019-04-16",},
    )

    responses.add(
        responses.GET, url, status=404, body=requests.exceptions.HTTPError("HTTP error")
    )

    with pytest.raises(requests.exceptions.HTTPError, match="HTTP error"):
        utils.download_check_etag(url)

    assert not os.path.exists("prova.txt") 
开发者ID:mozilla,项目名称:bugbug,代码行数:20,代码来源:test_utils.py

示例7: test_lazy_git

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_lazy_git():
    lazy_git = LazyGit(git_url=DOCKERFILE_GIT)
    with lazy_git:
        assert lazy_git.git_path is not None
        assert lazy_git.commit_id is not None
        assert len(lazy_git.commit_id) == 40  # current git hashes are this long

        previous_commit_id = lazy_git.commit_id
        lazy_git.reset('HEAD~2')  # Go back two commits
        assert lazy_git.commit_id is not None
        assert lazy_git.commit_id != previous_commit_id
        assert len(lazy_git.commit_id) == 40  # current git hashes are this long 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:14,代码来源:test_util.py

示例8: __init__

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def __init__(self, registry):
        self.hostname = registry_hostname(registry)
        self.repos = {}
        self._add_pattern(responses.GET, r'/v2/(.*)/manifests/([^/]+)',
                          self._get_manifest)
        self._add_pattern(responses.HEAD, r'/v2/(.*)/manifests/([^/]+)',
                          self._get_manifest)
        self._add_pattern(responses.PUT, r'/v2/(.*)/manifests/([^/]+)',
                          self._put_manifest)
        self._add_pattern(responses.GET, r'/v2/(.*)/blobs/([^/]+)',
                          self._get_blob)
        self._add_pattern(responses.HEAD, r'/v2/(.*)/blobs/([^/]+)',
                          self._get_blob)
        self._add_pattern(responses.POST, r'/v2/(.*)/blobs/uploads/\?mount=([^&]+)&from=(.+)',
                          self._mount_blob) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:17,代码来源:test_group_manifests.py

示例9: _add_pattern

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def _add_pattern(self, method, pattern, callback):
        pat = re.compile(r'^https://' + self.hostname + pattern + '$')

        def do_it(req):
            status, headers, body = callback(req, *(pat.match(req.url).groups()))
            if method == responses.HEAD:
                return status, headers, ''
            else:
                return status, headers, body

        responses.add_callback(method, pat, do_it, match_querystring=True) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:13,代码来源:test_group_manifests.py

示例10: set_up_glove

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def set_up_glove(url: str, byt: bytes, change_etag_every: int = 1000):
    # Mock response for the datastore url that returns glove vectors
    responses.add(
        responses.GET,
        url,
        body=byt,
        status=200,
        content_type="application/gzip",
        stream=True,
        headers={"Content-Length": str(len(byt))},
    )

    etags_left = change_etag_every
    etag = "0"

    def head_callback(_):
        """
        Writing this as a callback allows different responses to different HEAD requests.
        In our case, we're going to change the ETag header every `change_etag_every`
        requests, which will allow us to simulate having a new version of the file.
        """
        nonlocal etags_left, etag
        headers = {"ETag": etag}
        # countdown and change ETag
        etags_left -= 1
        if etags_left <= 0:
            etags_left = change_etag_every
            etag = str(int(etag) + 1)
        return (200, headers, "")

    responses.add_callback(responses.HEAD, url, callback=head_callback) 
开发者ID:allenai,项目名称:allennlp,代码行数:33,代码来源:file_utils_test.py

示例11: test_is_not_active_404

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_is_not_active_404(pydrill_instance):
    """
    :type pydrill_instance: pydrill.client.PyDrill
    """
    responses.add(**{
        'method': responses.HEAD,
        'url': 'http://localhost:8047/',
        'content_type': 'application/json',
        'status': 404,
    })
    assert pydrill_instance.is_active() is False 
开发者ID:PythonicNinja,项目名称:pydrill,代码行数:13,代码来源:test_pydrill_setup.py

示例12: test_is_not_active_500

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_is_not_active_500(pydrill_instance, pydrill_url):
    """
    :type pydrill_instance: pydrill.client.PyDrill
    """
    responses.add(**{
        'method': responses.HEAD,
        'url': pydrill_url,
        'content_type': 'application/json',
        'status': 500,
    })
    assert pydrill_instance.is_active() is False 
开发者ID:PythonicNinja,项目名称:pydrill,代码行数:13,代码来源:test_pydrill_setup.py

示例13: test_is_not_active_201

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_is_not_active_201(pydrill_instance, pydrill_url):
    """
    :type pydrill_instance: pydrill.client.PyDrill
    """
    responses.add(**{
        'method': responses.HEAD,
        'url': pydrill_url,
        'content_type': 'application/json',
        'status': 201,
    })
    assert pydrill_instance.is_active() is False 
开发者ID:PythonicNinja,项目名称:pydrill,代码行数:13,代码来源:test_pydrill_setup.py

示例14: test_is_not_active_timeout

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def test_is_not_active_timeout(pydrill_instance):
    """
    :type pydrill_instance: pydrill.client.PyDrill
    """
    try:
        pydrill_instance.perform_request('HEAD', '/', params={'request_timeout': 0.00001})
    except TransportError as e:
        assert e.status_code == e.args[0]
        assert e.error == e.args[1]
        assert e.info == e.args[2]
        assert str(e)
    else:
        assert False

# TODO: create more tests checking other params. 
开发者ID:PythonicNinja,项目名称:pydrill,代码行数:17,代码来源:test_pydrill_setup.py

示例15: set_up_glove

# 需要导入模块: import responses [as 别名]
# 或者: from responses import HEAD [as 别名]
def set_up_glove(url     , byt       , change_etag_every      = 1000):
    # Mock response for the datastore url that returns glove vectors
    responses.add(
            responses.GET,
            url,
            body=byt,
            status=200,
            content_type=u'application/gzip',
            stream=True,
            headers={u'Content-Length': unicode(len(byt))}
    )

    etags_left = change_etag_every
    etag = u"0"
    def head_callback(_):
        u"""
        Writing this as a callback allows different responses to different HEAD requests.
        In our case, we're going to change the ETag header every `change_etag_every`
        requests, which will allow us to simulate having a new version of the file.
        """
        nonlocal etags_left, etag
        headers = {u"ETag": etag}
        # countdown and change ETag
        etags_left -= 1
        if etags_left <= 0:
            etags_left = change_etag_every
            etag = unicode(int(etag) + 1)
        return (200, headers, u"")

    responses.add_callback(
            responses.HEAD,
            url,
            callback=head_callback
    ) 
开发者ID:plasticityai,项目名称:magnitude,代码行数:36,代码来源:file_utils_test.py


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