Skip to content

Commit

Permalink
Merge pull request #450 from weaviate/gh-449
Browse files Browse the repository at this point in the history
fix gh-449
  • Loading branch information
tsmith023 authored Aug 29, 2023
2 parents 2b762f7 + 373daed commit 0d3344d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
8 changes: 4 additions & 4 deletions integration/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def test_add_data_object(client: weaviate.Client, uuid: Optional[UUID], vector:
def test_delete_objects(client: weaviate.Client):
with client.batch as batch:
batch.add_data_object(data_object={"name": "one"}, class_name="Test")
batch.add_data_object(data_object={"name": "two"}, class_name="Test")
batch.add_data_object(data_object={"name": "two"}, class_name="test")
batch.add_data_object(data_object={"name": "three"}, class_name="Test")
batch.add_data_object(data_object={"name": "four"}, class_name="Test")
batch.add_data_object(data_object={"name": "four"}, class_name="test")
batch.add_data_object(data_object={"name": "five"}, class_name="Test")

with client.batch as batch:
Expand All @@ -106,7 +106,7 @@ def test_delete_objects(client: weaviate.Client):

with client.batch as batch:
batch.delete_objects(
"Test",
"test",
where={
"path": ["name"],
"operator": "ContainsAny",
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_delete_objects(client: weaviate.Client):
with pytest.raises(ValueError) as error:
with client.batch as batch:
batch.delete_objects(
"Test",
"test",
where={
"path": ["name"],
"operator": "ContainsAny",
Expand Down
14 changes: 14 additions & 0 deletions integration/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_get_nodes_status_without_data(client):
def test_get_nodes_status_with_data(client):
"""get nodes status with data"""
class_name1 = "ClassA"
uncap_class_name1 = "classA"
client.schema.create(schema(class_name1))
for i in range(NUM_OBJECT):
client.data_object.create({"stringProp": f"object-{i}", "intProp": i}, class_name1)
Expand Down Expand Up @@ -85,3 +86,16 @@ def test_get_nodes_status_with_data(client):
assert shards[0]["class"] == class_name1
assert shards[0]["objectCount"] == NUM_OBJECT
assert resp[0]["stats"]["objectCount"] == NUM_OBJECT

resp = client.cluster.get_nodes_status(uncap_class_name1)
assert len(resp) == 1
assert resp[0]["gitHash"] == GIT_HASH
assert resp[0]["name"] == NODE_NAME
assert len(resp[0]["shards"]) == 1
assert resp[0]["stats"]["shardCount"] == 1
assert resp[0]["status"] == "HEALTHY"
assert resp[0]["version"] == SERVER_VERSION

assert shards[0]["class"] == class_name1
assert shards[0]["objectCount"] == NUM_OBJECT
assert resp[0]["stats"]["objectCount"] == NUM_OBJECT
27 changes: 24 additions & 3 deletions integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_schema_keys(client: weaviate.Client):

def test_class_tenants(client: weaviate.Client):
class_name = "MultiTenancySchemaTest"
uncap_class_name = "multiTenancySchemaTest"
single_class = {"class": class_name, "multiTenancyConfig": {"enabled": True}}
client.schema.delete_all()
client.schema.create_class(single_class)
Expand All @@ -108,17 +109,20 @@ def test_class_tenants(client: weaviate.Client):
Tenant(name="Tenant3"),
Tenant(name="Tenant4"),
]
client.schema.add_class_tenants(class_name, tenants)
client.schema.add_class_tenants(class_name, tenants[:2])
client.schema.add_class_tenants(uncap_class_name, tenants[2:])
tenants_get = client.schema.get_class_tenants(class_name)
assert len(tenants_get) == len(tenants)

client.schema.remove_class_tenants(class_name, ["Tenant2", "Tenant4"])
tenants_get = client.schema.get_class_tenants(class_name)
assert len(tenants_get) == 2
client.schema.remove_class_tenants(uncap_class_name, ["Tenant1"])
tenants_get = client.schema.get_class_tenants(uncap_class_name)
assert len(tenants_get) == 1


def test_class_tenants_activate_deactivate(client: weaviate.Client):
class_name = "MultiTenancyActivateDeactivateSchemaTest"
uncap_class_name = "multiTenancyActivateDeactivateSchemaTest"
single_class = {"class": class_name, "multiTenancyConfig": {"enabled": True}}
client.schema.delete_all()
client.schema.create_class(single_class)
Expand Down Expand Up @@ -160,3 +164,20 @@ def test_class_tenants_activate_deactivate(client: weaviate.Client):
assert tenant.activity_status == TenantActivityStatus.HOT
else:
raise AssertionError(f"Unexpected tenant: {tenant.name}")

updated_tenants = [
Tenant(activity_status=TenantActivityStatus.COLD, name="Tenant3"),
]
client.schema.update_class_tenants(uncap_class_name, updated_tenants)
tenants_get = client.schema.get_class_tenants(uncap_class_name)
assert len(tenants_get) == len(tenants)
# below required because tenants are returned in random order by the server
for tenant in tenants_get:
if tenant.name == "Tenant1":
assert tenant.activity_status == TenantActivityStatus.COLD
elif tenant.name == "Tenant2":
assert tenant.activity_status == TenantActivityStatus.HOT
elif tenant.name == "Tenant3":
assert tenant.activity_status == TenantActivityStatus.COLD
else:
raise AssertionError(f"Unexpected tenant: {tenant.name}")
12 changes: 12 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ def test_generate_local_beacon(self):
beacon["beacon"], "weaviate://localhost/fcf33178-1b5d-5174-b2e7-04a2129dd35b"
)

beacon = generate_local_beacon(uuid_lib.UUID("fcf331781b5d5174b2e704a2129dd35b"), "Test1")
self.assertTrue("beacon" in beacon)
self.assertEqual(
beacon["beacon"], "weaviate://localhost/Test1/fcf33178-1b5d-5174-b2e7-04a2129dd35b"
)

beacon = generate_local_beacon(uuid_lib.UUID("fcf331781b5d5174b2e704a2129dd35b"), "test2")
self.assertTrue("beacon" in beacon)
self.assertEqual(
beacon["beacon"], "weaviate://localhost/Test2/fcf33178-1b5d-5174-b2e7-04a2129dd35b"
)

def test__get_dict_from_object(self):
"""
Test the `_get_dict_from_object` function.
Expand Down
8 changes: 4 additions & 4 deletions weaviate/batch/crud_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,11 @@ def delete_objects(
if not isinstance(class_name, str):
raise TypeError(f"'class_name' must be of type str. Given type: {type(class_name)}.")
if not isinstance(where, dict):
raise TypeError(f"'where' must be of type dict. Given type: {type(class_name)}.")
raise TypeError(f"'where' must be of type dict. Given type: {type(where)}.")
if not isinstance(output, str):
raise TypeError(f"'output' must be of type str. Given type: {type(class_name)}.")
raise TypeError(f"'output' must be of type str. Given type: {type(output)}.")
if not isinstance(dry_run, bool):
raise TypeError(f"'dry_run' must be of type bool. Given type: {type(class_name)}.")
raise TypeError(f"'dry_run' must be of type bool. Given type: {type(dry_run)}.")

params = {}
if self._consistency_level is not None:
Expand All @@ -1308,7 +1308,7 @@ def delete_objects(

payload = {
"match": {
"class": class_name,
"class": _capitalize_first_letter(class_name),
"where": _clean_delete_objects_where(where),
},
"output": output,
Expand Down
4 changes: 3 additions & 1 deletion weaviate/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
EmptyResponseException,
)

from ..util import _capitalize_first_letter


class Cluster:
"""
Expand Down Expand Up @@ -54,7 +56,7 @@ def get_nodes_status(self, class_name: Optional[str] = None) -> list:
"""
path = "/nodes"
if class_name is not None:
path += "/" + class_name
path += "/" + _capitalize_first_letter(class_name)

try:
response = self._connection.get(path=path)
Expand Down
8 changes: 4 additions & 4 deletions weaviate/schema/crud_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def add_class_tenants(self, class_name: str, tenants: List[Tenant]) -> None:

loaded_tenants = [tenant._to_weaviate_object() for tenant in tenants]

path = "/schema/" + class_name + "/tenants"
path = f"/schema/{_capitalize_first_letter(class_name)}/tenants"
try:
response = self._connection.post(path=path, weaviate_object=loaded_tenants)
except RequestsConnectionError as conn_err:
Expand Down Expand Up @@ -874,7 +874,7 @@ def remove_class_tenants(self, class_name: str, tenants: List[str]) -> None:
weaviate.UnexpectedStatusCodeException
If Weaviate reports a non-OK status.
"""
path = "/schema/" + class_name + "/tenants"
path = f"/schema/{_capitalize_first_letter(class_name)}/tenants"
try:
response = self._connection.delete(path=path, weaviate_object=tenants)
except RequestsConnectionError as conn_err:
Expand Down Expand Up @@ -903,7 +903,7 @@ def get_class_tenants(self, class_name: str) -> List[Tenant]:
weaviate.UnexpectedStatusCodeException
If Weaviate reports a non-OK status.
"""
path = "/schema/" + class_name + "/tenants"
path = f"/schema/{_capitalize_first_letter(class_name)}/tenants"
try:
response = self._connection.get(path=path)
except RequestsConnectionError as conn_err:
Expand Down Expand Up @@ -958,7 +958,7 @@ def update_class_tenants(self, class_name: str, tenants: List[Tenant]) -> None:
weaviate.UnexpectedStatusCodeException
If Weaviate reports a non-OK status.
"""
path = "/schema/" + class_name + "/tenants"
path = f"/schema/{_capitalize_first_letter(class_name)}/tenants"
loaded_tenants = [tenant._to_weaviate_object() for tenant in tenants]
try:
response = self._connection.put(path=path, weaviate_object=loaded_tenants)
Expand Down
2 changes: 1 addition & 1 deletion weaviate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def generate_local_beacon(

if class_name is None:
return {"beacon": f"weaviate://localhost/{uuid}"}
return {"beacon": f"weaviate://localhost/{class_name}/{uuid}"}
return {"beacon": f"weaviate://localhost/{_capitalize_first_letter(class_name)}/{uuid}"}


def _get_dict_from_object(object_: Union[str, dict]) -> dict:
Expand Down

0 comments on commit 0d3344d

Please sign in to comment.