def prepare(testfile="test-image", check_repo_retval=0):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, testfile)
    workflow.source = StubSource()
    workflow.builder = StubInsideBuilder()
    workflow.tag_conf = StubTagConf().set_images([
        ImageName(repo="image-name1"),
        ImageName(namespace="prefix",
                  repo="image-name2"),
        ImageName(repo="image-name3",
                  tag="asd"),
    ])

    # Mock dockpulp and docker
    dockpulp.Pulp = flexmock(dockpulp.Pulp)
    dockpulp.Pulp.registry = 'registry.example.com'
    (flexmock(dockpulp.imgutils).should_receive('get_metadata')
     .with_args(object)
     .and_return([{'id': 'foo'}]))
    (flexmock(dockpulp.imgutils).should_receive('get_manifest')
     .with_args(object)
     .and_return([{'id': 'foo'}]))
    (flexmock(dockpulp.imgutils).should_receive('get_versions')
     .with_args(object)
     .and_return({'id': '1.6.0'}))
    (flexmock(dockpulp.imgutils).should_receive('check_repo')
     .and_return(check_repo_retval))
    (flexmock(dockpulp.Pulp)
     .should_receive('set_certs')
     .with_args(object, object))
    (flexmock(dockpulp.Pulp)
     .should_receive('login')
     .with_args(object, object))
    (flexmock(dockpulp.Pulp)
     .should_receive('getRepos')
     .with_args(list, fields=list, distributors=True)
     .and_return([
         {"id": "redhat-image-name1"},
         {"id": "redhat-prefix-image-name2"}
      ]))
    (flexmock(dockpulp.Pulp)
     .should_receive('createRepo'))

    mock_docker()
    return tasker, workflow
def prepare(testfile="test-image", check_repo_retval=0):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, testfile)
    workflow.source = StubSource()
    workflow.builder = StubInsideBuilder()
    workflow.tag_conf = StubTagConf().set_images([
        ImageName(repo="image-name1"),
        ImageName(namespace="prefix", repo="image-name2"),
        ImageName(repo="image-name3", tag="asd"),
    ])

    # Mock dockpulp and docker
    dockpulp.Pulp = flexmock(dockpulp.Pulp)
    dockpulp.Pulp.registry = 'registry.example.com'
    (flexmock(dockpulp.imgutils).should_receive('get_metadata').with_args(
        object).and_return([{
            'id': 'foo'
        }]))
    (flexmock(dockpulp.imgutils).should_receive('get_manifest').with_args(
        object).and_return([{
            'id': 'foo'
        }]))
    (flexmock(dockpulp.imgutils).should_receive('get_versions').with_args(
        object).and_return({'id': '1.6.0'}))
    (flexmock(dockpulp.imgutils).should_receive('check_repo').and_return(
        check_repo_retval))
    (flexmock(dockpulp.Pulp).should_receive('set_certs').with_args(
        object, object))
    (flexmock(dockpulp.Pulp).should_receive('login').with_args(object, object))
    (flexmock(dockpulp.Pulp).should_receive('getRepos').with_args(
        list, fields=list, distributors=True).and_return([{
            "id":
            "redhat-image-name1"
        }, {
            "id":
            "redhat-prefix-image-name2"
        }]))
    (flexmock(dockpulp.Pulp).should_receive('createRepo'))

    mock_docker()
    return tasker, workflow