Skip to content

Commit 746de2e

Browse files
committed
add and change unittest for the new weaviate version (v1.0.0) for the schema module
1 parent 34a4e1b commit 746de2e

File tree

4 files changed

+555
-762
lines changed

4 files changed

+555
-762
lines changed

test/schema/schema_company.json

Lines changed: 44 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,46 @@
11
{
2-
"actions": {
3-
"classes": [],
4-
"type": "action"
5-
},
6-
"things": {
7-
"@context": "",
8-
"version": "0.2.0",
9-
"type": "thing",
10-
"name": "company",
11-
"maintainer": "[email protected]",
12-
"classes": [
13-
{
14-
"class": "Company",
15-
"description": "A business that acts in the market",
16-
"keywords": [],
17-
"properties": [
18-
{
19-
"name": "name",
20-
"description": "The name under which the company is known",
21-
"dataType": [
22-
"text"
23-
],
24-
"cardinality": "atMostOne",
25-
"keywords": []
26-
},
27-
{
28-
"name": "legalBody",
29-
"description": "The legal body under which the company maintains its business",
30-
"dataType": [
31-
"text"
32-
],
33-
"cardinality": "atMostOne",
34-
"keywords": []
35-
},
36-
{
37-
"name": "hasEmployee",
38-
"description": "The employees of the company",
39-
"dataType": [
40-
"Employee"
41-
],
42-
"cardinality": "many",
43-
"keywords": []
44-
}
45-
]
46-
},
47-
{
48-
"class": "Employee",
49-
"description": "An employee of the company",
50-
"keywords": [],
51-
"properties": [
52-
{
53-
"name": "name",
54-
"description": "The name of the employee",
55-
"dataType": [
56-
"text"
57-
],
58-
"cardinality": "atMostOne",
59-
"keywords": []
60-
},
61-
{
62-
"name": "job",
63-
"description": "the job description of the employee",
64-
"dataType": [
65-
"text"
66-
],
67-
"cardinality": "atMostOne",
68-
"keywords": []
69-
},
70-
{
71-
"name": "yearsInTheCompany",
72-
"description": "The number of years this employee has worked in the company",
73-
"dataType": [
74-
"int"
75-
],
76-
"cardinality": "atMostOne",
77-
"keywords": []
78-
}
79-
]
80-
}
81-
]
82-
}
2+
"classes": [
3+
{
4+
"class": "Company",
5+
"description": "A business that acts in the market",
6+
"properties": [
7+
{
8+
"name": "name",
9+
"description": "The name under which the company is known",
10+
"dataType": ["text"]
11+
},
12+
{
13+
"name": "legalBody",
14+
"description": "The legal body under which the company maintains its business",
15+
"dataType": ["text"]
16+
},
17+
{
18+
"name": "hasEmployee",
19+
"description": "The employees of the company",
20+
"dataType": ["Employee"]
21+
}
22+
]
23+
},
24+
{
25+
"class": "Employee",
26+
"description": "An employee of the company",
27+
"properties": [
28+
{
29+
"name": "name",
30+
"description": "The name of the employee",
31+
"dataType": ["text"]
32+
},
33+
{
34+
"name": "job",
35+
"description": "the job description of the employee",
36+
"dataType": ["text"]
37+
},
38+
{
39+
"name": "yearsInTheCompany",
40+
"description": "The number of years this employee has worked in the company",
41+
"dataType": ["int"]
42+
}
43+
]
44+
}
45+
]
8346
}

test/schema/test_properties.py

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,100 @@
11
import unittest
22
import weaviate
3-
from weaviate import SEMANTIC_TYPE_ACTIONS
43
from weaviate.connect import REST_METHOD_POST, REST_METHOD_DELETE
5-
from unittest.mock import Mock
6-
from test.testing_util import replace_connection, add_run_rest_to_mock
4+
from test.testing_util import replace_connection, add_run_rest_to_mock, Mock
75

86

97
class TestCRUDProperty(unittest.TestCase):
108

119
def test_create_bad_input(self):
12-
w = weaviate.Client("http://localhorst:8080")
10+
"""
11+
Test create property exceptions.
12+
"""
13+
14+
client = weaviate.Client("http://localhorst:8080")
1315
test_prop = {
1416
"dataType": ["string"],
15-
"cardinality": "atMostOne",
1617
"description": "my Property",
17-
"vectorizePropertyName": True,
18+
"moduleConfig" : {
19+
"text2vec-contextionary": {
20+
"vectorizePropertyName": True
21+
}
22+
},
1823
# "name": "superProp", missing name
19-
"index": True
24+
"indexInverted": True
2025
}
21-
try:
22-
w.schema.property.create("Class", test_prop)
23-
self.fail("No error")
24-
except weaviate.SchemaValidationException:
25-
pass
26+
27+
with self.assertRaises(weaviate.SchemaValidationException):
28+
client.schema.property.create("Class", test_prop)
2629
test_prop["name"] = "someName"
27-
try:
28-
w.schema.property.create(35, test_prop)
29-
self.fail("No error")
30-
except TypeError:
31-
pass
32-
try:
33-
w.schema.property.create("Class", ["wrong", "type"])
34-
self.fail("No error")
35-
except TypeError:
36-
pass
30+
with self.assertRaises(TypeError):
31+
client.schema.property.create(35, test_prop)
32+
with self.assertRaises(TypeError):
33+
client.schema.property.create("Class", ["wrong", "type"])
3734

3835
def test_create(self):
39-
w = weaviate.Client("http://localhorst:8080")
36+
"""
37+
Test create.
38+
"""
39+
40+
client = weaviate.Client("http://localhorst:8080")
4041

4142
connection_mock = Mock() # Mock calling weaviate
4243
add_run_rest_to_mock(connection_mock)
43-
replace_connection(w, connection_mock)
44+
replace_connection(client, connection_mock)
4445

4546
test_prop = {
4647
"dataType": ["string"],
47-
"cardinality": "atMostOne",
4848
"description": "my Property",
49-
"vectorizePropertyName": True,
49+
"moduleConfig" : {
50+
"text2vec-contextionary": {
51+
"vectorizePropertyName": True
52+
}
53+
},
5054
"name": "superProp",
51-
"index": True
55+
"indexInverted": True
5256
}
5357

54-
w.schema.property.create("TestThing", test_prop)
55-
w.schema.property.create("TestAction", test_prop, SEMANTIC_TYPE_ACTIONS)
58+
client.schema.property.create("TestThing", test_prop)
5659

5760
connection_mock.run_rest.assert_called()
5861

5962
call_args_list = connection_mock.run_rest.call_args_list
60-
call_args, call_kwargs = call_args_list[0]
63+
call_args = call_args_list[0][0]
6164

62-
self.assertEqual("/schema/things/TestThing/properties", call_args[0])
65+
self.assertEqual("/schema/TestThing/properties", call_args[0])
6366
self.assertEqual(REST_METHOD_POST, call_args[1])
6467
self.assertEqual(test_prop, call_args[2])
6568

66-
call_args, call_kwargs = call_args_list[1]
69+
def test_delete_bad_input(self):
70+
"""
71+
Test create with bad input.
72+
"""
6773

68-
self.assertEqual("/schema/actions/TestAction/properties", call_args[0])
69-
self.assertEqual(REST_METHOD_POST, call_args[1])
70-
self.assertEqual(test_prop, call_args[2])
74+
client = weaviate.Client("http://localhorst:8080")
7175

72-
def test_delete_bad_input(self):
73-
w = weaviate.Client("http://localhorst:8080")
74-
try:
75-
w.schema.property._delete("Class", 4)
76-
self.fail("No error")
77-
except TypeError:
78-
pass
79-
try:
80-
w.schema.property._delete(35, "prop")
81-
self.fail("No error")
82-
except TypeError:
83-
pass
76+
with self.assertRaises(TypeError):
77+
client.schema.property._delete("Class", 4)
78+
with self.assertRaises(TypeError):
79+
client.schema.property._delete(35, "prop")
8480

8581
def test_delete(self):
86-
w = weaviate.Client("http://localhorst:8080")
82+
"""
83+
Test delete property. (currently not available)
84+
"""
85+
86+
client = weaviate.Client("http://localhorst:8080")
8787

8888
connection_mock = Mock() # Mock calling weaviate
8989
add_run_rest_to_mock(connection_mock)
90-
replace_connection(w, connection_mock)
90+
replace_connection(client, connection_mock)
9191

92-
w.schema.property._delete("ThingClass", "propUno")
93-
w.schema.property._delete("ActionClass", "propDos", SEMANTIC_TYPE_ACTIONS)
92+
client.schema.property._delete("ThingClass", "propUno")
9493

9594
connection_mock.run_rest.assert_called()
9695

9796
call_args_list = connection_mock.run_rest.call_args_list
98-
call_args, call_kwargs = call_args_list[0]
99-
100-
self.assertEqual("/schema/things/ThingClass/properties/propUno", call_args[0])
101-
self.assertEqual(REST_METHOD_DELETE, call_args[1])
102-
103-
call_args, call_kwargs = call_args_list[1]
97+
call_args = call_args_list[0][0]
10498

105-
self.assertEqual("/schema/actions/ActionClass/properties/propDos", call_args[0])
99+
self.assertEqual("/schema/ThingClass/properties/propUno", call_args[0])
106100
self.assertEqual(REST_METHOD_DELETE, call_args[1])
107-

0 commit comments

Comments
 (0)