test(api/tag): unit test movetag

This commit is contained in:
EvB 2017-05-02 18:10:20 -04:00
parent 70508e3692
commit eb9db0c53b

View file

@ -0,0 +1,57 @@
import pytest
from mock import patch, Mock
from endpoints.api.test.shared import client_with_identity, conduct_api_call
from endpoints.api.tag import RepositoryTag, RestoreTag
from features import FeatureNameValue
from test.fixtures import *
@pytest.fixture()
def get_repo_image():
def mock_callable(namespace, repository, image_id):
img = Mock(repository='fetched_repository') if image_id == 'image1' else None
return img
with patch('endpoints.api.tag.model.image.get_repo_image', side_effect=mock_callable) as mk:
yield mk
@pytest.fixture()
def get_repo_tag_image():
def mock_get_repo_tag_image(repository, tag):
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.get_repo_tag_image', side_effect=mock_get_repo_tag_image):
yield
@pytest.fixture()
def create_or_update_tag():
with patch('endpoints.api.tag.model.tag.create_or_update_tag') as mk:
yield mk
@pytest.fixture()
def generate_manifest():
def mock_callable(namespace, repository, tag):
if tag is 'generatemanifestfail':
raise Exception('test_failure')
with patch('endpoints.api.tag._generate_and_store_manifest', side_effect=mock_callable) as mk:
yield mk
@pytest.fixture()
def authd_client(client):
with client_with_identity('devtable', client) as cl:
yield cl
@pytest.mark.parametrize('test_image,test_tag,expected_status', [
('image1', '-INVALID-TAG-NAME', 400),
('image1', '.INVALID-TAG-NAME', 400),
('image1', 'INVALID-TAG_NAME-BECAUSE-THIS-IS-WAY-WAY-TOO-LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG', 400),
('nonexistantimage', 'newtag', 404),
('image1', 'generatemanifestfail', 201),
('image1', 'existing-tag', 201),
('image1', 'newtag', 201),
])
def test_move_tag(test_image, test_tag, expected_status, get_repo_image, get_repo_tag_image, create_or_update_tag, generate_manifest, authd_client):
params = {'repository': 'devtable/repo', 'tag': test_tag}
request_body = {'image': test_image}
conduct_api_call(authd_client, RepositoryTag, 'put', params, request_body, expected_status)