本文整理汇总了Python中responses.add_passthru方法的典型用法代码示例。如果您正苦于以下问题:Python responses.add_passthru方法的具体用法?Python responses.add_passthru怎么用?Python responses.add_passthru使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类responses
的用法示例。
在下文中一共展示了responses.add_passthru方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_subjurisdictions_counties_web01
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def test_get_subjurisdictions_counties_web01(self):
"""A jurisdiction with sub-jurisdictions with Web01 in url should return a list of URLs"""
# Avoid hitting all the summary URLs for each subjurisdiction.
responses.add(
method=responses.GET,
url=re.compile(r"^https://results.enr.clarityelections.com/AR/(.+/[0-9]+/[0-9]+/Web01/en/summary.html|(.+/)?[0-9]+/[0-9]+/reports/summary.zip)$"),
status=200,
)
# Construct a Jurisdiction for Arkansas 2014 General Election
url = "https://results.enr.clarityelections.com/AR/53237/149294/Web01/en/summary.html"
responses.add_passthru(url)
responses.add_passthru(url.replace("summary.html", "json/electionsettings.json"))
jurisdiction = Jurisdiction(url=url, level="state")
subjurisdictions = jurisdiction.get_subjurisdictions()
# A state like AR has county sub-jurisdictions with results
expected_subjurisdiction_count = 75
self.assertEqual(len(subjurisdictions), expected_subjurisdiction_count)
# TODO: Actually check the values in subjurisdictions.
示例2: fake_hg_repo
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def fake_hg_repo(tmpdir):
tmp_path = tmpdir.strpath
dest = os.path.join(tmp_path, "repos")
local = os.path.join(dest, "local")
remote = os.path.join(dest, "remote")
for d in [local, remote]:
os.makedirs(d)
hglib.init(d)
os.environ["USER"] = "app"
hg = hglib.open(local)
responses.add_passthru("http://localhost:8000")
yield hg, local, remote
hg.close()
示例3: test_is_authenticated_token
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def test_is_authenticated_token(self, mock_config_file_with_auth):
"""test checking if the user is authenticated via a token"""
responses.add(responses.POST, 'https://gigantum.com/api/v1',
json={'data': {'synchronizeUserAccount': {'gitUserId': "123"}}},
status=200)
responses.add_passthru('https://gigantum.auth0.com/.well-known/jwks.json')
config = Configuration(mock_config_file_with_auth[0])
mgr = get_identity_manager(config)
assert type(mgr) == LocalIdentityManager
# Don't check at_hash claim due to password grant not setting it in the token
mgr.validate_at_hash_claim = False
# Invalid with no token
assert mgr.is_authenticated() is False
assert mgr.is_authenticated(None) is False
assert mgr.is_authenticated("asdfasdfa") is False
assert mgr.is_authenticated("asdfasdfa", "asdfasdffdgfgh") is False
assert mgr.is_authenticated(mock_config_file_with_auth[1]['access_token'],
mock_config_file_with_auth[1]['id_token']) is True
# Second access should load from disk and not need a token
mgr2 = get_identity_manager(config)
assert mgr2.is_authenticated() is True
assert mgr2.is_authenticated("asdfasdfa") is True # An "expired" token will essentially do this
# Double check logging out un-authenticates
mgr2.logout()
assert mgr.is_authenticated() is False
assert mgr2.is_authenticated() is False
clean_local_cache(mgr)
示例4: test_get_user_profile
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def test_get_user_profile(self, mock_config_file_with_auth_anonymous):
"""test getting a user profile from Auth0"""
responses.add(responses.POST, 'https://gigantum.com/api/v1',
json={'data': {'synchronizeUserAccount': {'gitUserId': "123"}}},
status=200)
responses.add_passthru('https://gigantum.auth0.com/.well-known/jwks.json')
config = Configuration(mock_config_file_with_auth_anonymous[0])
mgr = get_identity_manager(config)
assert type(mgr) == AnonymousIdentityManager
# Don't check at_hash claim due to password grant not setting it in the token
mgr.validate_at_hash_claim = False
# Load User
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr.get_user_profile()
# Load User
u = mgr.get_user_profile(mock_config_file_with_auth_anonymous[2]['access_token'],
mock_config_file_with_auth_anonymous[2]['id_token'])
assert type(u) == User
assert u.username == "johndoe"
assert u.email == "john.doe@gmail.com"
assert u.given_name == "John"
assert u.family_name == "Doe"
# Second access should fail since not cached
mgr2 = get_identity_manager(config)
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr2.get_user_profile()
示例5: test_get_user_profile
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def test_get_user_profile(self, mock_config_file_with_auth_browser):
"""test getting a user profile from Auth0"""
responses.add(responses.POST, 'https://gigantum.com/api/v1',
json={'data': {'synchronizeUserAccount': {'gitUserId': "123"}}},
status=200)
responses.add_passthru('https://gigantum.auth0.com/.well-known/jwks.json')
config = Configuration(mock_config_file_with_auth_browser[0])
mgr = get_identity_manager(config)
assert type(mgr) == BrowserIdentityManager
# Don't check at_hash claim due to password grant not setting it in the token
mgr.validate_at_hash_claim = False
# Load User
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr.get_user_profile()
# Load User
u = mgr.get_user_profile(mock_config_file_with_auth_browser[2]['access_token'],
mock_config_file_with_auth_browser[2]['id_token'])
assert type(u) == User
assert u.username == "johndoe"
assert u.email == "john.doe@gmail.com"
assert u.given_name == "John"
assert u.family_name == "Doe"
# Second access should fail since not cached
mgr2 = get_identity_manager(config)
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr2.get_user_profile()
示例6: docker_socket_fixture
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def docker_socket_fixture():
"""Helper method to get the docker client version"""
client = get_docker_client()
version = client.version()['ApiVersion']
if "CIRCLECI" in os.environ:
docker_host = os.environ['DOCKER_HOST']
docker_host = docker_host.replace("tcp", "https")
responses.add_passthru(
f"{docker_host}/v{version}/images/default-default-labbook1/json")
responses.add_passthru(
f"{docker_host}/v{version}/containers/default-default-labbook1/json")
responses.add_passthru(
f"{docker_host}/v{version}/images/default-default-labbook1/json")
responses.add_passthru(
f"{docker_host}/v{version}/containers/default-default-labbook1/json")
responses.add_passthru(
f"{docker_host}/v{version}/images/default-test-sample-repo-lb/json")
responses.add_passthru(
f"{docker_host}/v{version}/containers/default-test-sample-repo-lb/json")
responses.add_passthru(
'{docker_host}/v{version}/containers/default-test-sample-repo-lb/json')
else:
responses.add_passthru(
f"http+docker://localunixsocket/v{version}/images/default-default-labbook1/json")
responses.add_passthru(
f"http+docker://localunixsocket/v{version}/containers/default-default-labbook1/json")
responses.add_passthru(
f"http+docker://localunixsocket/v{version}/images/default-test-sample-repo-lb/json")
responses.add_passthru(
f"http+docker://localunixsocket/v{version}/containers/default-test-sample-repo-lb/json")
yield
示例7: register_urls
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def register_urls(self, filename='simple.csv',
content_type='application/csv'):
"""Mock some test URLs with responses.
Mocks some URLs related to a data file and a CKAN resource that
contains the data file, including the URL of the data file itself and
the resource_show, resource_update and datastore_delete URLs.
:returns: a 2-tuple containing the URL of the data file itself and the
resource_show URL for the resource that contains the data file
"""
responses.add_passthru(config['solr_url'])
# A URL that just returns a static file
responses.add(responses.GET, SOURCE_URL,
body=get_sample_file(filename),
content_type=content_type)
# A URL that mocks the response that CKAN's resource_update API would
# give after successfully updating a resource.
resource_update_url = (
'http://www.ckan.org/api/3/action/resource_update')
responses.add(responses.POST, resource_update_url,
body=json.dumps({'success': True}),
content_type='application/json')
# A URL that mock's the response that CKAN's datastore plugin's
# datastore_delete API would give after successfully deleting a
# resource from the datastore.
datastore_del_url = 'http://www.ckan.org/api/3/action/datastore_delete'
responses.add(responses.POST, datastore_del_url,
body=json.dumps({'success': True}),
content_type='application/json')
self.callback_url = 'http://www.ckan.org/api/3/action/xloader_hook'
responses.add(responses.POST, self.callback_url,
body=json.dumps({'success': True}),
content_type='application/json')
示例8: test_get_user_profile
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def test_get_user_profile(self, mock_config_file_with_auth):
"""test getting a user profile from Auth0"""
responses.add(responses.POST, 'https://gigantum.com/api/v1',
json={'data': {'synchronizeUserAccount': {'gitUserId': "123"}}},
status=200)
responses.add_passthru('https://gigantum.auth0.com/.well-known/jwks.json')
config = Configuration(mock_config_file_with_auth[0])
mgr = get_identity_manager(config)
assert type(mgr) == LocalIdentityManager
# Don't check at_hash claim due to password grant not setting it in the token
mgr.validate_at_hash_claim = False
# Load User
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr.get_user_profile()
# Load User
u = mgr.get_user_profile(mock_config_file_with_auth[1]['access_token'],
mock_config_file_with_auth[1]['id_token'])
assert type(u) == User
assert os.path.exists(os.path.join(mgr.auth_dir, 'cached_id_jwt')) is True
assert u.username == "johndoe"
assert u.email == "john.doe@gmail.com"
assert u.given_name == "John"
assert u.family_name == "Doe"
# Seccond access should load from disk and not need a token
mgr2 = get_identity_manager(config)
u2 = mgr2.get_user_profile()
assert type(u) == User
assert os.path.exists(os.path.join(mgr.auth_dir, 'cached_id_jwt')) is True
assert u2.username == "johndoe"
assert u2.email == "john.doe@gmail.com"
assert u2.given_name == "John"
assert u2.family_name == "Doe"
# Double check logging out un-authenticates
mgr2.logout()
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr.get_user_profile()
with pytest.raises(AuthenticationError):
# Should fail without a token
mgr2.get_user_profile()
clean_local_cache(mgr)
示例9: mock_repo
# 需要导入模块: import responses [as 别名]
# 或者: from responses import add_passthru [as 别名]
def mock_repo(tmpdir: py.path.local, monkeypatch: MonkeyPatch) -> Tuple[str, str]:
"""Create an empty mercurial repo"""
local_dir = tmpdir / "local"
remote_dir = tmpdir / "remote"
# Setup the worker env to use that repo dir
monkeypatch.setattr(bugbug_http, "REPO_DIR", str(local_dir))
# Create the repo
hglib.init(str(local_dir))
with hglib.open(str(local_dir)) as repo:
(local_dir / ".hg-annotate-ignore-revs").write_text("", encoding="ascii")
repo.add(str(local_dir / ".hg-annotate-ignore-revs").encode("utf-8"))
# Add several commits on a test file to create some history
test_file = local_dir / "test.txt"
for i in range(4):
test_file.write_text(f"Version {i}", encoding="utf-8")
repo.add([str(test_file).encode("utf-8")])
repo.commit(f"Base history {i}", user="bugbug")
# Copy initialized repo as remote
local_dir.copy(remote_dir)
# Configure remote on local
hgrc = local_dir / ".hg" / "hgrc"
hgrc.write_text("\n".join(["[paths]", f"default = {remote_dir}"]), "utf-8")
# Add extra commit on remote
with hglib.open(str(remote_dir)) as repo:
remote = remote_dir / "remote.txt"
remote.write_text("New remote file !", encoding="utf-8")
repo.add([str(remote).encode("utf-8")])
repo.commit("Pulled from remote", user="bugbug")
# Allow using the local code analysis server.
responses.add_passthru("http://127.0.0.1")
orig_hgclient_pull = hglib.client.hgclient.pull
def hglib_pull(hgclient, source=None, rev=None, update=False):
orig_hgclient_pull(
hgclient, source=str(remote_dir).encode("ascii"), rev=rev, update=update
)
monkeypatch.setattr(hglib.client.hgclient, "pull", hglib_pull)
return local_dir, remote_dir