#NEWLINE# def test_docker_login( monkeypatch , tmpdir ) : #NEWLINE# #INDENT# monkeypatch . setattr ( 'os.path.expanduser' , ( lambda x : x . replace ( '~' , str ( tmpdir ) ) ) ) #NEWLINE# response = MagicMock ( ) #NEWLINE# response . status_code = 200 #NEWLINE# response . json . return_value = { #NEWLINE# #INDENT# 'access_token' : '12377' , #NEWLINE# #UNINDENT# } #NEWLINE# monkeypatch . setattr ( 'requests.get' , MagicMock ( return_value = token ) ) #NEWLINE# token = docker_login ( 'https://pierone.example.org' , 'services' , 'mytok' , 'myuser' , 'mypass' , 'https://token.example.org' , use_keyring = False ) #NEWLINE# path = os . path . expanduser ( '~/.docker/config.json' ) #NEWLINE# with open ( path ) as fd : #NEWLINE# #INDENT# data = yaml . safe_load ( fd ) #NEWLINE# #UNINDENT# assert ( { #NEWLINE# #INDENT# 'auth' : 'b2F1dGgyOjEyMzc3' , #NEWLINE# 'email' : 'no-mail-required@example.org' , #NEWLINE# #UNINDENT# } == data . get ( 'auths' ) . get ( 'https://pierone.example.org' ) )