def helper_test(test_class, test_class_call): mock_rest = mock_connection_method('post') schema = Schema(mock_rest) schema._create_class_with_premitives(test_class) self.assertEqual(mock_rest.post.call_count, 1) mock_rest.post.assert_called_with( path="/schema", weaviate_object=test_class_call, )
def test__create_classes_with_primitives(self): """ Test the `_create_classes_with_primitives` method. """ schema = Schema(Mock()) mock_primitive = Mock() schema._create_class_with_premitives = mock_primitive schema._create_classes_with_primitives(list("Test!!")) self.assertEqual(mock_primitive.call_count, 6)
def test_create_class(self): """ Test the `create_class` method. """ schema = Schema(Mock()) # mock function calls mock_primitive = Mock() mock_complex = Mock() schema._create_class_with_premitives = mock_primitive schema._create_complex_properties_from_class = mock_complex schema.create_class(company_test_schema["classes"][0]) mock_primitive.assert_called_with(company_test_schema["classes"][0]) mock_complex.assert_called_with(company_test_schema["classes"][0])
def test__create_class_with_premitives(self): """ Test the `_create_class_with_premitives` method. """ # valid calls def helper_test(test_class, test_class_call): mock_rest = mock_connection_method('post') schema = Schema(mock_rest) schema._create_class_with_premitives(test_class) self.assertEqual(mock_rest.post.call_count, 1) mock_rest.post.assert_called_with( path="/schema", weaviate_object=test_class_call, ) test_class = { "class": "TestClass", "properties": [{ 'dataType': ['int'], 'name': 'test_prop', 'description': 'None' }, { 'dataType': ['Test'], 'name': 'test_prop', 'description': 'None' }] } test_class_call = { "class": "TestClass", "properties": [ { 'dataType': ['int'], 'name': 'test_prop', 'description': 'None' }, ] } helper_test(test_class, test_class_call) test_class['description'] = 'description' test_class_call['description'] = 'description' helper_test(test_class, test_class_call) test_class['description'] = 'description' test_class_call['description'] = 'description' helper_test(test_class, test_class_call) test_class['vectorIndexType'] = 'vectorIndexType' test_class_call['vectorIndexType'] = 'vectorIndexType' helper_test(test_class, test_class_call) test_class['vectorIndexConfig'] = { 'vectorIndexConfig': 'vectorIndexConfig' } test_class_call['vectorIndexConfig'] = { 'vectorIndexConfig': 'vectorIndexConfig' } helper_test(test_class, test_class_call) test_class['vectorizer'] = 'test_vectorizer' test_class_call['vectorizer'] = 'test_vectorizer' helper_test(test_class, test_class_call) test_class['moduleConfig'] = {'moduleConfig': 'moduleConfig'} test_class_call['moduleConfig'] = {'moduleConfig': 'moduleConfig'} helper_test(test_class, test_class_call) test_class['shardingConfig'] = {'shardingConfig': 'shardingConfig'} test_class_call['shardingConfig'] = { 'shardingConfig': 'shardingConfig' } helper_test(test_class, test_class_call) # multiple properties do not imply multiple `run_rest` calls test_class['properties'].append( test_class['properties'][0]) # add another property test_class['properties'].append( test_class['properties'][0]) # add another property test_class_call['properties'].append( test_class['properties'][0]) # add another property test_class_call['properties'].append( test_class['properties'][0]) # add another property helper_test(test_class, test_class_call) # with uncapitalized class_name test_class['class'] = 'testClass' helper_test(test_class, test_class_call) # invalid calls requests_error_message = 'Class may not have been created properly.' mock_rest = mock_connection_method( 'post', side_effect=RequestsConnectionError('TEST1')) schema = Schema(mock_rest) with self.assertRaises(RequestsConnectionError) as error: schema._create_class_with_premitives(test_class) check_error_message(self, error, requests_error_message) mock_rest = mock_connection_method('post', status_code=404) schema = Schema(mock_rest) with self.assertRaises(UnexpectedStatusCodeException) as error: schema._create_class_with_premitives(test_class) check_startswith_error_message(self, error, "Create class")