def test_build_image_passes_and_pushes(monkeypatch): flow = Flow("test") storage = Docker(registry_url="reg", base_image="python:3.6") pull_image = MagicMock() monkeypatch.setattr("prefect.environments.storage.Docker.pull_image", pull_image) push_image = MagicMock() monkeypatch.setattr("prefect.environments.storage.Docker.push_image", push_image) build = MagicMock() monkeypatch.setattr("docker.APIClient.build", build) images = MagicMock(return_value=["test"]) monkeypatch.setattr("docker.APIClient.images", images) remove = MagicMock() monkeypatch.setattr("docker.APIClient.remove_image", remove) image_name, image_tag = storage.build_image(flow) assert image_name assert image_tag assert "reg" in push_image.call_args[0][0] assert "reg" in remove.call_args[1]["image"]
def test_build_image_fails_no_registry(monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() monkeypatch.setattr("docker.APIClient", client) with pytest.raises(ValueError): image_name, image_tag = storage.build_image()
def test_build_image_fails_deserialization_no_registry(monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() monkeypatch.setattr("docker.APIClient", client) with pytest.raises(SerializationError): image_name, image_tag = storage.build_image(push=False)
def test_build_image_fails_deserialization(monkeypatch): flow = Flow("test") storage = Docker(registry_url="reg", base_image="python:3.6") client = MagicMock() monkeypatch.setattr("docker.APIClient", client) with pytest.raises(SerializationError): image_name, image_tag = storage.build_image(flow)
def test_build_image_passes(monkeypatch): flow = Flow("test") storage = Docker(registry_url="reg", base_image="python:3.6") pull_image = MagicMock() monkeypatch.setattr("prefect.environments.storage.Docker.pull_image", pull_image) build = MagicMock() monkeypatch.setattr("docker.APIClient.build", build) images = MagicMock(return_value=["test"]) monkeypatch.setattr("docker.APIClient.images", images) image_name, image_tag = storage.build_image(flow, push=False) assert image_name assert image_tag