test(api/tag): test restore_tag

This commit is contained in:
EvB 2017-05-03 17:24:39 -04:00
parent 6e894d5f24
commit 25b9d044de

View file

@ -16,6 +16,11 @@ def get_repo_image():
with patch('endpoints.api.tag.model.image.get_repo_image', side_effect=mock_callable) as mk:
yield mk
@pytest.fixture()
def get_repository():
with patch('endpoints.api.tag.model.image.get_repo_image', return_value='mock_repo') as mk:
yield mk
@pytest.fixture()
def get_repo_tag_image():
def mock_get_repo_tag_image(repository, tag):
@ -24,6 +29,22 @@ def get_repo_tag_image():
with patch('endpoints.api.tag.model.tag.get_repo_tag_image', side_effect=mock_get_repo_tag_image):
yield
@pytest.fixture()
def restore_tag_to_manifest():
def mock_restore_tag_to_manifest(repository, tag, manifest_digest):
tag_img = Mock(docker_image_id='mock_docker_image_id') if tag == 'existing-tag' else None
return tag_img
with patch('endpoints.api.tag.model.tag.restore_tag_to_manifest', side_effect=mock_restore_tag_to_manifest):
yield
@pytest.fixture()
def restore_tag_to_image():
def mock_restore_tag_to_image(repository, tag, image_id):
tag_img = Mock(docker_image_id='mock_docker_image_id') if tag == 'existing-tag' else None
return tag_img
with patch('endpoints.api.tag.model.tag.restore_tag_to_image', side_effect=mock_restore_tag_to_image):
yield
@pytest.fixture()
def create_or_update_tag():
with patch('endpoints.api.tag.model.tag.create_or_update_tag') as mk:
@ -59,3 +80,22 @@ 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)
else:
conduct_api_call(authd_client, RepositoryTag, 'put', params, request_body, expected_status)
@pytest.mark.parametrize('test_manifest,test_tag,manifest_generated,expected_status', [
(None, 'newtag', True, 200),
(None, 'generatemanifestfail', True, None),
('manifest1', 'newtag', False, 200),
])
def test_restore_tag(test_manifest, test_tag, manifest_generated, expected_status, get_repository, restore_tag_to_manifest, restore_tag_to_image, generate_manifest, authd_client):
params = {'repository': 'devtable/repo', 'tag': test_tag}
request_body = {'image': 'image1'}
if test_manifest is not None:
request_body['manifest_digest'] = test_manifest
if expected_status is None:
with pytest.raises(Exception):
conduct_api_call(authd_client, RestoreTag, 'post', params, request_body, expected_status)
else:
conduct_api_call(authd_client, RestoreTag, 'post', params, request_body, expected_status)
if manifest_generated:
generate_manifest.assert_called_with('devtable', 'repo', test_tag)