|
1 | 1 | import unittest
|
2 | 2 | import weaviate
|
3 |
| -from weaviate import SEMANTIC_TYPE_ACTIONS |
4 | 3 | 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 |
7 | 5 |
|
8 | 6 |
|
9 | 7 | class TestCRUDProperty(unittest.TestCase):
|
10 | 8 |
|
11 | 9 | 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") |
13 | 15 | test_prop = {
|
14 | 16 | "dataType": ["string"],
|
15 |
| - "cardinality": "atMostOne", |
16 | 17 | "description": "my Property",
|
17 |
| - "vectorizePropertyName": True, |
| 18 | + "moduleConfig" : { |
| 19 | + "text2vec-contextionary": { |
| 20 | + "vectorizePropertyName": True |
| 21 | + } |
| 22 | + }, |
18 | 23 | # "name": "superProp", missing name
|
19 |
| - "index": True |
| 24 | + "indexInverted": True |
20 | 25 | }
|
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) |
26 | 29 | 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"]) |
37 | 34 |
|
38 | 35 | def test_create(self):
|
39 |
| - w = weaviate.Client("http://localhorst:8080") |
| 36 | + """ |
| 37 | + Test create. |
| 38 | + """ |
| 39 | + |
| 40 | + client = weaviate.Client("http://localhorst:8080") |
40 | 41 |
|
41 | 42 | connection_mock = Mock() # Mock calling weaviate
|
42 | 43 | add_run_rest_to_mock(connection_mock)
|
43 |
| - replace_connection(w, connection_mock) |
| 44 | + replace_connection(client, connection_mock) |
44 | 45 |
|
45 | 46 | test_prop = {
|
46 | 47 | "dataType": ["string"],
|
47 |
| - "cardinality": "atMostOne", |
48 | 48 | "description": "my Property",
|
49 |
| - "vectorizePropertyName": True, |
| 49 | + "moduleConfig" : { |
| 50 | + "text2vec-contextionary": { |
| 51 | + "vectorizePropertyName": True |
| 52 | + } |
| 53 | + }, |
50 | 54 | "name": "superProp",
|
51 |
| - "index": True |
| 55 | + "indexInverted": True |
52 | 56 | }
|
53 | 57 |
|
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) |
56 | 59 |
|
57 | 60 | connection_mock.run_rest.assert_called()
|
58 | 61 |
|
59 | 62 | 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] |
61 | 64 |
|
62 |
| - self.assertEqual("/schema/things/TestThing/properties", call_args[0]) |
| 65 | + self.assertEqual("/schema/TestThing/properties", call_args[0]) |
63 | 66 | self.assertEqual(REST_METHOD_POST, call_args[1])
|
64 | 67 | self.assertEqual(test_prop, call_args[2])
|
65 | 68 |
|
66 |
| - call_args, call_kwargs = call_args_list[1] |
| 69 | + def test_delete_bad_input(self): |
| 70 | + """ |
| 71 | + Test create with bad input. |
| 72 | + """ |
67 | 73 |
|
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") |
71 | 75 |
|
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") |
84 | 80 |
|
85 | 81 | 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") |
87 | 87 |
|
88 | 88 | connection_mock = Mock() # Mock calling weaviate
|
89 | 89 | add_run_rest_to_mock(connection_mock)
|
90 |
| - replace_connection(w, connection_mock) |
| 90 | + replace_connection(client, connection_mock) |
91 | 91 |
|
92 |
| - w.schema.property._delete("ThingClass", "propUno") |
93 |
| - w.schema.property._delete("ActionClass", "propDos", SEMANTIC_TYPE_ACTIONS) |
| 92 | + client.schema.property._delete("ThingClass", "propUno") |
94 | 93 |
|
95 | 94 | connection_mock.run_rest.assert_called()
|
96 | 95 |
|
97 | 96 | 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] |
104 | 98 |
|
105 |
| - self.assertEqual("/schema/actions/ActionClass/properties/propDos", call_args[0]) |
| 99 | + self.assertEqual("/schema/ThingClass/properties/propUno", call_args[0]) |
106 | 100 | self.assertEqual(REST_METHOD_DELETE, call_args[1])
|
107 |
| - |
0 commit comments