def test_is_docker_image_latest_tag_with_default_image(): """ Given - The default docker image - 'demisto/python:1.3-alpine' When - The most updated docker image in docker-hub is '1.0.3' Then - If the docker image is numeric and the most update one, it is Valid - If the docker image is not numeric and labeled "latest", it is Invalid """ with mock.patch.object(DockerImageValidator, '__init__', lambda x, y, z, w: None): docker_image_validator = DockerImageValidator(None, None, None) docker_image_validator.yml_file = {} docker_image_validator.file_path = "PATH" docker_image_validator.ignored_errors = {} docker_image_validator.code_type = 'python' docker_image_validator.checked_files = set() docker_image_validator.docker_image_latest_tag = '1.0.3' docker_image_validator.docker_image_name = 'demisto/python' docker_image_validator.suppress_print = False docker_image_validator.is_latest_tag = True docker_image_validator.is_modified_file = False docker_image_validator.docker_image_tag = '1.3-alpine' docker_image_validator.is_valid = True assert docker_image_validator.is_docker_image_latest_tag() is False assert docker_image_validator.is_latest_tag is False assert docker_image_validator.is_docker_image_valid() is False
def test_is_docker_image_latest_tag_without_tag(): """ Given - A latest docker image has an empty tag When - The most updated docker image in docker-hub is '1.0.3' Then - If the docker image is numeric and the most update one, it is Valid - If the docker image is not numeric and labeled "latest", it is Invalid """ with mock.patch.object(DockerImageValidator, '__init__', lambda x, y, z, w: None): docker_image_validator = DockerImageValidator(None, None, None) docker_image_validator.yml_file = {} docker_image_validator.ignored_errors = {} docker_image_validator.file_path = "path" docker_image_validator.docker_image_latest_tag = '' docker_image_validator.docker_image_name = 'demisto/python' docker_image_validator.code_type = 'python' docker_image_validator.suppress_print = False docker_image_validator.is_latest_tag = True docker_image_validator.docker_image_tag = '1.0.2' docker_image_validator.is_valid = True assert docker_image_validator.is_docker_image_latest_tag() is False assert docker_image_validator.is_latest_tag is False assert docker_image_validator.is_docker_image_valid() is False
def test_is_docker_image_latest_tag_with_numeric_but_not_most_updated(): """ Given - A docker image with '1.0.2' as tag When - The most updated docker image in docker-hub is '1.0.3' Then - If the docker image is numeric and the most update one, it is Valid - If the docker image is not numeric and labeled "latest", it is Invalid - If the docker image is not the most updated one it is invalid """ with mock.patch.object(DockerImageValidator, '__init__', lambda x, y, z, w: None): docker_image_validator = DockerImageValidator(None, None, None) docker_image_validator.yml_file = {} docker_image_validator.ignored_errors = {} docker_image_validator.file_path = "path" docker_image_validator.docker_image_latest_tag = '1.0.3' docker_image_validator.docker_image_name = 'demisto/python' docker_image_validator.code_type = 'python' docker_image_validator.checked_files = set() docker_image_validator.is_latest_tag = True docker_image_validator.docker_image_tag = '1.0.2' docker_image_validator.is_valid = True assert docker_image_validator.is_docker_image_latest_tag() is False assert docker_image_validator.is_latest_tag is False assert docker_image_validator.is_docker_image_valid() is False