本文整理汇总了Python中atomic_reactor.core.DockerTasker.login方法的典型用法代码示例。如果您正苦于以下问题:Python DockerTasker.login方法的具体用法?Python DockerTasker.login怎么用?Python DockerTasker.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic_reactor.core.DockerTasker
的用法示例。
在下文中一共展示了DockerTasker.login方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_login
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import login [as 别名]
def test_login(tmpdir, dockerconfig_contents, should_raise):
if MOCK:
mock_docker()
fake_api = flexmock(docker.APIClient, login=lambda username, registry,
dockercfg_path: {'Status': 'Login Succeeded'})
tmpdir_path = str(tmpdir.realpath())
file_name = '.dockercfg'
dockercfg_path = os.path.join(tmpdir_path, file_name)
with open(dockercfg_path, "w+") as dockerconfig:
dockerconfig.write(json.dumps(dockerconfig_contents))
dockerconfig.flush()
t = DockerTasker()
if should_raise:
if 'auth' in dockerconfig_contents[LOCALHOST_REGISTRY]:
with pytest.raises(ValueError) as exc:
t.login(LOCALHOST_REGISTRY, tmpdir_path)
assert "Failed to parse 'auth'" in str(exc)
else:
with pytest.raises(RuntimeError) as exc:
t.login(LOCALHOST_REGISTRY, tmpdir_path)
assert "Failed to extract a username" in str(exc)
else:
if MOCK:
(fake_api
.should_receive('login')
.with_args(username='user', registry=LOCALHOST_REGISTRY, dockercfg_path=dockercfg_path)
.once().and_return({'Status': 'Login Succeeded'}))
t.login(LOCALHOST_REGISTRY, tmpdir_path)