Exemplo n.º 1
0
def test_log_artifacts(mock_client, tmpdir):
    repo = AzureBlobArtifactRepository(TEST_URI, mock_client)

    parentd = tmpdir.mkdir("data")
    subd = parentd.mkdir("subdir")
    parentd.join("a.txt").write("A")
    subd.join("b.txt").write("B")
    subd.join("c.txt").write("C")

    repo.log_artifacts(parentd.strpath)

    mock_client.get_container_client.assert_called_with("container")
    call_list = mock_client.get_container_client().upload_blob.call_args_list

    # Ensure that the order of the calls do not matter
    for call in call_list:
        arg1, arg2 = call[0]
        assert arg1 in [
            posixpath.join(TEST_ROOT_PATH, x)
            for x in ["a.txt", "subdir/b.txt", "subdir/c.txt"]
        ]
        # arg2 should be a filebuffer
        if arg1.endswith("/a.txt"):
            assert arg2.name == os.path.normpath(parentd.strpath + "/a.txt")
        elif arg1.endswith("/b.txt"):
            assert arg2.name == os.path.normpath(subd.strpath + "/b.txt")
        elif arg1.endswith("/c.txt"):
            assert arg2.name == os.path.normpath(subd.strpath + "/c.txt")
        else:
            # This should be unreachable
            assert False
Exemplo n.º 2
0
def test_log_artifacts(mock_client, tmpdir):
    repo = AzureBlobArtifactRepository(TEST_URI, mock_client)

    parentd = tmpdir.mkdir("data")
    subd = parentd.mkdir("subdir")
    parentd.join("a.txt").write("A")
    subd.join("b.txt").write("B")
    subd.join("c.txt").write("C")

    repo.log_artifacts(parentd.strpath)

    mock_client.create_blob_from_path.assert_has_calls([
        mock.call("container", TEST_ROOT_PATH + "/a.txt",
                  os.path.normpath(parentd.strpath + "/a.txt")),
        mock.call("container", TEST_ROOT_PATH + "/subdir/b.txt",
                  os.path.normpath(subd.strpath + "/b.txt")),
        mock.call("container", TEST_ROOT_PATH + "/subdir/c.txt",
                  os.path.normpath(subd.strpath + "/c.txt")),
    ],
                                                       any_order=True)