style(data+endpoints): ran yapf

### Description of Changes

ran yapf for the branch

[TESTING->locally using docker compose]

Issue: https://coreosdev.atlassian.net/browse/QUAY-632

## Reviewer Checklist

- [ ] It works!
- [ ] Comments provide sufficient explanations for the next contributor
- [ ] Tests cover changes and corner cases
- [ ] Follows Quay syntax patterns and format
This commit is contained in:
Charlton Austin 2017-07-10 09:46:02 -04:00
parent fc4b3642d3
commit 897a091692
7 changed files with 135 additions and 87 deletions

View file

@ -168,7 +168,8 @@ def test_get_repo_tag_image_with_repo_and_repo_tag(get_monkeypatch):
get_repository_mock(get_monkeypatch, mock_image)
get_repo_tag_image_mock(get_monkeypatch, mock_image)
image = pre_oci_model.get_repo_tag_image(Repository('namespace_name', 'repository_name'), 'tag_name')
image = pre_oci_model.get_repo_tag_image(
Repository('namespace_name', 'repository_name'), 'tag_name')
assert image is not None
assert image.docker_image_id == 'some docker image id'
@ -177,7 +178,8 @@ def test_get_repo_tag_image_with_repo_and_repo_tag(get_monkeypatch):
def test_get_repo_tag_image_without_repo(get_monkeypatch):
get_repository_mock(get_monkeypatch, None)
image = pre_oci_model.get_repo_tag_image(Repository('namespace_name', 'repository_name'), 'tag_name')
image = pre_oci_model.get_repo_tag_image(
Repository('namespace_name', 'repository_name'), 'tag_name')
assert image is None
@ -192,7 +194,8 @@ def test_get_repo_tag_image_without_repo_tag_image(get_monkeypatch):
get_monkeypatch.setattr(model.tag, 'get_repo_tag_image', raise_exception)
image = pre_oci_model.get_repo_tag_image(Repository('namespace_name', 'repository_name'), 'tag_name')
image = pre_oci_model.get_repo_tag_image(
Repository('namespace_name', 'repository_name'), 'tag_name')
assert image is None
@ -201,7 +204,8 @@ def test_create_or_update_tag(get_monkeypatch):
mock = Mock()
get_monkeypatch.setattr(model.tag, 'create_or_update_tag', mock)
pre_oci_model.create_or_update_tag('namespace_name', 'repository_name', 'tag_name', 'docker_image_id')
pre_oci_model.create_or_update_tag('namespace_name', 'repository_name', 'tag_name',
'docker_image_id')
assert mock.call_count == 1
assert mock.call_args == call('namespace_name', 'repository_name', 'tag_name', 'docker_image_id')
@ -249,14 +253,30 @@ def test_get_parent_images(get_monkeypatch):
def fake_list():
return []
image_one = AttrDict(
{'docker_image_id': 'docker_image_id', 'created': 'created_one', 'comment': 'comment_one', 'command': 'command_one',
'storage': AttrDict({'image_size': 'image_size_one', 'uploading': 'uploading_one'}), 'ancestors': 'one/two/three',
'ancestor_id_list': fake_list})
image_two = AttrDict(
{'docker_image_id': 'docker_image_id_two', 'created': 'created', 'comment': 'comment', 'command': 'command',
'storage': AttrDict({'image_size': 'image_size', 'uploading': 'uploading'}), 'ancestors': 'four/five/six',
'ancestor_id_list': fake_list})
image_one = AttrDict({
'docker_image_id': 'docker_image_id',
'created': 'created_one',
'comment': 'comment_one',
'command': 'command_one',
'storage': AttrDict({
'image_size': 'image_size_one',
'uploading': 'uploading_one'
}),
'ancestors': 'one/two/three',
'ancestor_id_list': fake_list
})
image_two = AttrDict({
'docker_image_id': 'docker_image_id_two',
'created': 'created',
'comment': 'comment',
'command': 'command',
'storage': AttrDict({
'image_size': 'image_size',
'uploading': 'uploading'
}),
'ancestors': 'four/five/six',
'ancestor_id_list': fake_list
})
get_parent_images_mock = Mock(return_value=[image_one, image_two])
get_monkeypatch.setattr(model.image, 'get_parent_images', get_parent_images_mock)
@ -303,7 +323,8 @@ def test_tag_to_manifest(get_monkeypatch):
get_monkeypatch.setattr(model.tag, 'restore_tag_to_manifest', restore_tag_mock)
get_monkeypatch.setattr(model.repository, 'get_repository', get_repository_mock)
pre_oci_model.restore_tag_to_manifest(Repository('namespace', 'repository'), 'tag_name', 'manifest_digest')
pre_oci_model.restore_tag_to_manifest(
Repository('namespace', 'repository'), 'tag_name', 'manifest_digest')
get_repository_mock.assert_called_once_with('namespace', 'repository')
restore_tag_mock.assert_called_once_with(repo_mock, 'tag_name', 'manifest_digest')
@ -314,7 +335,6 @@ def test__tag_to_image(get_monkeypatch):
restore_tag_mock = Mock(return_value=None)
get_repository_mock = Mock(return_value=repo_mock)
get_monkeypatch.setattr(model.tag, 'restore_tag_to_image', restore_tag_mock)
get_monkeypatch.setattr(model.repository, 'get_repository', get_repository_mock)

View file

@ -23,13 +23,15 @@ def get_repo_image():
img = Mock(repository=mock, docker_image_id=12) if image_id == 'image1' else None
return img
with patch('endpoints.api.tag_models_pre_oci.model.image.get_repo_image', side_effect=mock_callable) as mk:
with patch('endpoints.api.tag_models_pre_oci.model.image.get_repo_image',
side_effect=mock_callable) as mk:
yield mk
@pytest.fixture()
def get_repository():
with patch('endpoints.api.tag_models_pre_oci.model.image.get_repo_image', return_value='mock_repo') as mk:
with patch('endpoints.api.tag_models_pre_oci.model.image.get_repo_image',
return_value='mock_repo') as mk:
yield mk
@ -42,8 +44,9 @@ def get_repo_tag_image():
return []
if tag == 'existing-tag':
return Mock(docker_image_id='mock_docker_image_id', created=12345, comment='comment', command='command',
storage=storage_mock, ancestors=[], ancestor_id_list=fake_ancestor_id_list)
return Mock(docker_image_id='mock_docker_image_id', created=12345, comment='comment',
command='command', storage=storage_mock, ancestors=[],
ancestor_id_list=fake_ancestor_id_list)
else:
raise DataModelException('Unable to find image for tag.')
@ -100,12 +103,14 @@ def authd_client(client):
def list_repository_tag_history():
def list_repository_tag_history(namespace_name, repository_name, page, size, specific_tag):
return RepositoryTagHistory(tags=[
Tag(name='First Tag', image='image', reversion=False, lifetime_start_ts=0, lifetime_end_ts=0, manifest_list=[],
docker_image_id='first docker image id'),
Tag(name='Second Tag', image='second image', reversion=True, lifetime_start_ts=10, lifetime_end_ts=100,
manifest_list=[], docker_image_id='second docker image id')], more=False)
Tag(name='First Tag', image='image', reversion=False, lifetime_start_ts=0, lifetime_end_ts=0,
manifest_list=[], docker_image_id='first docker image id'),
Tag(name='Second Tag', image='second image', reversion=True, lifetime_start_ts=10,
lifetime_end_ts=100, manifest_list=[], docker_image_id='second docker image id')
], more=False)
with patch('endpoints.api.tag.model.list_repository_tag_history', side_effect=list_repository_tag_history):
with patch('endpoints.api.tag.model.list_repository_tag_history',
side_effect=list_repository_tag_history):
yield
@ -114,7 +119,8 @@ def find_no_repo_tag_history():
def list_repository_tag_history(namespace_name, repository_name, page, size, specific_tag):
return None
with patch('endpoints.api.tag.model.list_repository_tag_history', side_effect=list_repository_tag_history):
with patch('endpoints.api.tag.model.list_repository_tag_history',
side_effect=list_repository_tag_history):
yield
@ -140,23 +146,39 @@ def test_move_tag(test_image, test_tag, expected_status, get_repo_image, get_rep
conduct_api_call(authd_client, RepositoryTag, 'put', params, request_body, expected_status)
@pytest.mark.parametrize('namespace, repository, specific_tag, page, limit, expected_response_code, expected', [
('devtable', 'simple', None, 1, 10, 200, {'has_additional': False}),
('devtable', 'simple', None, 1, 10, 200, {'page': 1}),
('devtable', 'simple', None, 1, 10, 200, {'tags': [{'docker_image_id': 'first docker image id',
'name': 'First Tag',
'reversion': False},
{'docker_image_id': 'second docker image id',
'end_ts': 100,
'name': 'Second Tag',
'reversion': True,
'start_ts': 10}]}),
])
@pytest.mark.parametrize(
'namespace, repository, specific_tag, page, limit, expected_response_code, expected', [
('devtable', 'simple', None, 1, 10, 200, {
'has_additional': False
}),
('devtable', 'simple', None, 1, 10, 200, {
'page': 1
}),
('devtable', 'simple', None, 1, 10, 200, {
'tags': [{
'docker_image_id': 'first docker image id',
'name': 'First Tag',
'reversion': False
}, {
'docker_image_id': 'second docker image id',
'end_ts': 100,
'name': 'Second Tag',
'reversion': True,
'start_ts': 10
}]
}),
])
def test_list_repository_tags_view_is_correct(namespace, repository, specific_tag, page, limit,
list_repository_tag_history, expected_response_code, expected,
authd_client):
params = {'repository': namespace + '/' + repository, 'specificTag': specific_tag, 'page': page, 'limit': limit}
response = conduct_api_call(authd_client, ListRepositoryTags, 'get', params, expected_code=expected_response_code)
list_repository_tag_history, expected_response_code,
expected, authd_client):
params = {
'repository': namespace + '/' + repository,
'specificTag': specific_tag,
'page': page,
'limit': limit
}
response = conduct_api_call(authd_client, ListRepositoryTags, 'get', params,
expected_code=expected_response_code)
compare_list_history_tags_response(expected, response.json)
@ -183,17 +205,23 @@ def test_no_repo_tag_history(find_no_repo_tag_history, authd_client):
('specific_tag', -1, 101, 'specific_tag', 1, 100),
('specific_tag', 0, 0, 'specific_tag', 1, 1),
])
def test_repo_tag_history_param_parse(specific_tag, page, limit, expected_specific_tag, expected_page, expected_limit,
authd_client):
def test_repo_tag_history_param_parse(specific_tag, page, limit, expected_specific_tag,
expected_page, expected_limit, authd_client):
mock = MagicMock()
mock.return_value = RepositoryTagHistory(tags=[], more=False)
with patch('endpoints.api.tag.model.list_repository_tag_history', side_effect=mock):
params = {'repository': 'devtable/simple', 'specificTag': specific_tag, 'page': page, 'limit': limit}
params = {
'repository': 'devtable/simple',
'specificTag': specific_tag,
'page': page,
'limit': limit
}
conduct_api_call(authd_client, ListRepositoryTags, 'get', params)
assert mock.call_args == call(namespace_name='devtable', repository_name='simple',
page=expected_page, size=expected_limit, specific_tag=expected_specific_tag)
page=expected_page, size=expected_limit,
specific_tag=expected_specific_tag)
@pytest.mark.parametrize('test_manifest,test_tag,manifest_generated,expected_status', [