Exemple #1
0
def test_client_interface_e2e() -> None:
    """Test client object against live server."""
    client = init()
    assert isinstance(client.get_base_url(), str)
    assert client.get_base_url() == "http://localhost:19120/api/v1"
    references = client.list_references().references
    assert len(references) == 1
    assert references[0] == Branch("main", references[0].hash_)
    main_name = references[0].name
    main_commit = references[0].hash_
    with pytest.raises(NessieConflictException):
        client.create_branch("main")
    created_reference = client.create_branch("test", main_name, main_commit)
    references = client.list_references().references
    assert len(references) == 2
    assert next(i for i in references
                if i.name == "main") == Branch("main", main_commit)
    assert next(i for i in references
                if i.name == "test") == Branch("test", main_commit)
    reference = client.get_reference("test")
    assert created_reference == reference
    tables = client.list_keys(reference.name, reference.hash_)
    assert isinstance(tables, Entries)
    assert len(tables.entries) == 0
    client.delete_branch("test", main_commit)
    references = client.list_references().references
    assert len(references) == 1
Exemple #2
0
def test_client_interface(requests_mock: requests_mock) -> None:
    """Test client object."""
    client = init()
    requests_mock.get("http://localhost:19120/api/v1/trees", text=json.dumps([]))
    references = client.list_references()
    assert len(references) == 0

    requests_mock.post("http://localhost:19120/api/v1/trees/branch/main")
    assert client.create_branch("main") is None

    requests_mock.get(
        "http://localhost:19120/api/v1/trees",
        text=json.dumps([{"name": "main", "type": "BRANCH", "hash": "1234567890abcdef"}]),
    )
    references = client.list_references()
    assert len(references) == 1

    requests_mock.post("http://localhost:19120/api/v1/trees/branch/test/1234567890fedcba")
    assert client.create_branch("test", "1234567890fedcba") is None

    requests_mock.get(
        "http://localhost:19120/api/v1/trees",
        text=json.dumps(
            [
                {"name": "main", "type": "BRANCH", "hash": "1234567890abcdef"},
                {"name": "test", "type": "BRANCH", "hash": "1234567890fedcba"},
            ]
        ),
    )
    references = client.list_references()
    assert len(references) == 2
    assert [i.name for i in references] == ["main", "test"]
Exemple #3
0
def test_client_interface_e2e() -> None:
    """Test client object against live server."""
    client = init()
    assert isinstance(client._token, str)
    references = client.list_references()
    assert len(references) == 1
    assert references[0] == Reference("main", "BRANCH", references[0].hash_)
    main_commit = references[0].id
    with pytest.raises(NessieConflictException):
        client.create_branch("main")
    client.create_branch("test", main_commit)
    references = client.list_references()
    assert len(references) == 2
    assert references[0] == Reference("main", "BRANCH", main_commit)
    assert references[1] == Reference("test", "BRANCH", main_commit)
    reference = client.get_branch("test")
    tables = client.list_references(reference.name)
    assert isinstance(tables, list)
    assert len(tables) == 0
    client.delete_branch("test")
    references = client.list_references()
    assert len(references) == 1