Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
create test for #4 (~/.dockercfg writing)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Jun 5, 2015
1 parent cc04892 commit 6b4c280
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import json
import os
from mock import MagicMock
import yaml
from pierone.api import docker_login


def test_docker_login(monkeypatch):
def test_docker_login(monkeypatch, tmpdir):
monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
response = MagicMock()
response.json.return_value = {'access_token': '12377'}
monkeypatch.setattr('requests.get', MagicMock(return_value=response))
Expand All @@ -16,3 +18,27 @@ def test_docker_login(monkeypatch):
assert {'auth': 'b2F1dGgyOjEyMzc3', 'email': 'no-mail-required@example.org'} == data.get('https://pierone.example.org')


def test_keep_dockercfg_entries(monkeypatch, tmpdir):
monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
response = MagicMock()
response.json.return_value = {'access_token': '12377'}
monkeypatch.setattr('requests.get', MagicMock(return_value=response))
path = os.path.expanduser('~/.dockercfg')

key = 'https://old.example.org'
existing_data = {
key: {
'auth': 'abc123',
'email': 'jdoe@example.org'
}
}
with open(path, 'w') as fd:
json.dump(existing_data, fd)

token = docker_login('https://pierone.example.org', 'services', 'mytok',
'myuser', 'mypass', 'https://token.example.org', use_keyring=False)
with open(path) as fd:
data = yaml.safe_load(fd)
assert {'auth': 'b2F1dGgyOjEyMzc3', 'email': 'no-mail-required@example.org'} == data.get('https://pierone.example.org')
assert existing_data.get(key) == data.get(key)

0 comments on commit 6b4c280

Please sign in to comment.