def test_get_open_id_configuration(self):
        """
        Test the `get_open_id_configuration` method.
        """

        client = Client("http://localhost:8080")
        # Request to weaviate returns 200
        connection_mock = mock_connection_method('get', return_json="OK!")
        client._connection = connection_mock
        self.assertEqual(client.get_open_id_configuration(), "OK!")
        connection_mock.get.assert_called_with(
            path="/.well-known/openid-configuration")

        # Request to weaviate returns 404
        connection_mock = mock_connection_method('get', status_code=404)
        client._connection = connection_mock
        self.assertIsNone(client.get_open_id_configuration())
        connection_mock.get.assert_called_with(
            path="/.well-known/openid-configuration")

        # Request to weaviate returns 204
        connection_mock = mock_connection_method('get', status_code=204)
        client._connection = connection_mock
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            client.get_open_id_configuration()
        error_message = f"Meta endpoint! Unexpected status code: 204, with response body: None"
        check_error_message(self, error, error_message)
        connection_mock.get.assert_called_with(
            path="/.well-known/openid-configuration")
    def test___init__(self):
        """
        Test the `__init__` method.
        """

        type_error_message = "URL is expected to be string but is "
        # test incalid calls
        with self.assertRaises(TypeError) as error:
            Client(None)
        check_error_message(self, error, type_error_message + str(type(None)))
        with self.assertRaises(TypeError) as error:
            Client(42)
        check_error_message(self, error, type_error_message + str(int))

        # test valid calls
        with patch('weaviate.client.Connection') as mock_obj:
            Client("some_URL", auth_client_secret=None, timeout_config=(1, 2))
            mock_obj.assert_called_with(url='some_URL',
                                        auth_client_secret=None,
                                        timeout_config=(1, 2))
        with patch('weaviate.client.Connection') as mock_obj:
            Client("some_URL/",
                   auth_client_secret=None,
                   timeout_config=(5, 20))
            mock_obj.assert_called_with(url='some_URL',
                                        auth_client_secret=None,
                                        timeout_config=(5, 20))
    def test__is_sub_schema(self):
        """
        Test the `_is_sub_schema` function.
        """

        self.assertTrue(_is_sub_schema(schema_set, schema_set))
        self.assertTrue(_is_sub_schema(schema_set['classes'][0], schema_set))
        self.assertTrue(_is_sub_schema(schema_sub_set, schema_set))

        schema_set_copy = deepcopy(schema_set)
        for schema_class in schema_set_copy['classes']:
            schema_class['class'] = schema_class['class'].lower()
        self.assertTrue(_is_sub_schema(schema_set_copy, schema_set))
        self.assertTrue(_is_sub_schema(schema_set, schema_set_copy))
        self.assertTrue(_is_sub_schema(schema_set_copy, schema_set_copy))

        self.assertFalse(_is_sub_schema({'class': 'A'}, schema_set))
        self.assertFalse(_is_sub_schema(disjoint_set, schema_set))
        self.assertFalse(_is_sub_schema(partial_set, schema_set))
        self.assertFalse(_is_sub_schema(schema_set_extended_prop, schema_set))

        # invalid calls

        invalid_sub_schema_msg = "The sub schema class/es MUST have a 'class' keyword each!"

        with self.assertRaises(SchemaValidationException) as error:
            _is_sub_schema({}, schema_set)
        check_error_message(self, error, invalid_sub_schema_msg)
    def test_get_vector(self):
        """
        Test the `get_vector` function.
        """

        vector_list  = [1., 2., 3.]
        # vector is a list
        self.assertEqual(get_vector(vector_list), vector_list)

        # vector is a `torch.Tensor` or `numpy.ndarray`
        vector_mock = Mock()
        mock_tolist = Mock()
        mock_tolist.tolist.return_value = vector_list
        mock_squeeze = Mock(return_value = mock_tolist)
        vector_mock.squeeze = mock_squeeze
        self.assertEqual(get_vector(vector_mock), vector_list)

        # vector is a `tf.Tensor`
        vector_mock = Mock()
        mock_tolist = Mock()
        mock_squeeze = Mock()
        mock_tolist.tolist.return_value = vector_list
        mock_squeeze.squeeze.return_value = mock_tolist
        mock_numpy = Mock(return_value = mock_squeeze)
        vector_mock.numpy = mock_numpy
        vector_mock.squeeze = Mock(side_effect = AttributeError("TEST TensorFlow Tensor"))
        self.assertEqual(get_vector(vector_mock), vector_list)

        # invalid call
        type_error_message = ("The type of the 'vector' argument is not supported!\n"
                "Supported types are `list`, 'numpy.ndarray`, `torch.Tensor` "
                "and `tf.Tensor`")
        with self.assertRaises(TypeError) as error:
            get_vector('[1., 2., 3.]')
        check_error_message(self, error, type_error_message)
        def helper_after_call(message, *args, **kwargs):
            """
            initialize mock objects and connection after testing th exception.

            Returns
            -------
            weaviate.connect.Connection
                Connection.
            """

            if message is not None:
                check_error_message(self, error, message)
            self.check_connection_attributes(
                connection,
                url=kwargs.get("url", 'test_url'),
                timeout_config=kwargs.get("timeout_config", (2, 20)),
                auth_expires=kwargs.get("auth_expires", 0),
                auth_bearer=kwargs.get("auth_bearer", None),
                auth_client_secret=kwargs.get("auth_client_secret", None),
                is_authentication_required=kwargs.get(
                    "is_authentication_required", False),
            )
            if 'get' in kwargs:
                mock_requests.get.assert_called_with(
                    *kwargs['get_args'],
                    **kwargs['get'])  # only last call of this method
            if 'post' in kwargs:
                mock_requests.post.assert_called_with(
                    *kwargs['post_args'],
                    **kwargs['post'])  # only last call of this method
    def test_build_ask(self):
        """
        Test the `with_ask` method.
        """

        ask = {
            "question": "What is k8s?",
            "certainty": 0.55,
            'autocorrect': False,
        }

        # valid calls
        query = GetBuilder("Person", "name", None).with_ask(ask).build()
        self.assertEqual(
            '{Get{Person(ask: {question: "What is k8s?" certainty: 0.55 autocorrect: false} ){name}}}',
            query)

        # invalid calls
        near_error_msg = "Cannot use multiple 'near' filters, or a 'near' filter along with a 'ask' filter!"

        near_text = {
            "concepts": "computer",
            "moveTo": {
                "concepts": ["science"],
                "force": 0.5
            },
        }
        with self.assertRaises(AttributeError) as error:
            GetBuilder("Person", "name",
                       None).with_near_text(near_text).with_ask(ask)
        check_error_message(self, error, near_error_msg)
    def test_generate_local_beacon(self):
        """
        Test the `generate_local_beacon` function.
        """

        type_error_message = "Expected to_object_uuid of type str or uuid.UUID"
        value_error_message = "Uuid does not have the propper form"
        # wrong data type
        with self.assertRaises(TypeError) as error:
            generate_local_beacon(None)
        check_error_message(self, error, type_error_message)
        # wrong value
        with self.assertRaises(ValueError) as error:
            generate_local_beacon("Leeroy Jenkins")
        check_error_message(self, error, value_error_message)

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

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

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

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

        # test valid call
        connection_mock = mock_connection_method('get', return_json={"A": "B"})
        contextionary = Contextionary(connection_mock)
        self.assertEqual("B", contextionary.get_concept_vector("sauce")["A"])
        connection_mock.get.assert_called_with(
            path="/modules/text2vec-contextionary/concepts/sauce", )

        # test exceptions

        # error messages
        requests_error_message = 'text2vec-contextionary vector was not retrieved.'
        unexpected_exception_error_message = "text2vec-contextionary vector"

        ## test UnexpectedStatusCodeException
        contextionary = Contextionary(
            mock_connection_method('get', status_code=404))
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            contextionary.get_concept_vector("Palantir")
        check_startswith_error_message(self, error,
                                       unexpected_exception_error_message)

        ## test requests error
        contextionary = Contextionary(
            mock_connection_method(
                'get', side_effect=RequestsConnectionError("Test!")))
        with self.assertRaises(RequestsConnectionError) as error:
            contextionary.get_concept_vector("Palantir")
        check_error_message(self, error, requests_error_message)
    def test_build_with_near_text(self):
        """
        Test the `with_near_text` method.
        """

        near_text = {
            "concepts": "computer",
            "moveTo": {
                "concepts": ["science"],
                "force": 0.5
            },
            'autocorrect': True,
        }

        # valid calls
        query = GetBuilder("Person", "name",
                           None).with_near_text(near_text).build()
        self.assertEqual(
            '{Get{Person(nearText: {concepts: ["computer"] moveTo: {concepts: ["science"] force: 0.5} autocorrect: true} ){name}}}',
            query)

        # invalid calls
        near_error_msg = "Cannot use multiple 'near' filters, or a 'near' filter along with a 'ask' filter!"

        near_vector = {
            "vector": [1, 2, 3, 4, 5, 6, 7, 8, 9],
            "certainty": 0.55
        }
        with self.assertRaises(AttributeError) as error:
            GetBuilder(
                "Person", "name",
                None).with_near_vector(near_vector).with_near_text(near_text)
        check_error_message(self, error, near_error_msg)
Beispiel #10
0
    def test_is_ready(self, mock_get_cluster_config,):
        """
        Test the `is_ready` method.
        """

        wcs = WCS(AuthClientPassword('test_user', 'test_pass'))

        # invalid calls
        ## error messages
        value_error_msg = "No cluster with name: 'test_name'. Check the name again!"

        mock_get_cluster_config.return_value = {}
        with self.assertRaises(ValueError) as error:
            wcs.is_ready('TEST_NAME')
        check_error_message(self, error, value_error_msg)
        mock_get_cluster_config.assert_called_with('test_name')

        # valid calls
        mock_get_cluster_config.return_value = {'status': {'state': {'percentage' : 99}}}
        self.assertEqual(wcs.is_ready('test_name'), False)
        mock_get_cluster_config.assert_called_with('test_name')

        mock_get_cluster_config.return_value = {'status': {'state': {'percentage' : 100}}}
        self.assertEqual(wcs.is_ready('test_name2'), True)
        mock_get_cluster_config.assert_called_with('test_name2')
Beispiel #11
0
    def test_get_cluster_config(self, mock_get):
        """
        Test the `get_cluster_config` method.
        """

        wcs = WCS(AuthClientPassword('test_secret_username', 'test_secret_password'))
        wcs._auth_bearer = 'test_bearer'

        # invalid calls

        ## error messages
        connection_error_message = 'WCS cluster info was not fetched.'
        unexpected_error_message = 'Checking WCS instance'

        ## connection error
        mock_get.side_effect = RequestsConnectionError('Test!')
        with self.assertRaises(RequestsConnectionError) as error:
            wcs.get_cluster_config('test_name')
        check_error_message(self, error, connection_error_message)
        mock_get.assert_called_with(
            path='/clusters/test_name',
        )

        ## unexpected error
        mock_get.side_effect = None
        mock_get.return_value = Mock(status_code=400)
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            wcs.get_cluster_config('test_name')
        check_startswith_error_message(self, error, unexpected_error_message)
        mock_get.assert_called_with(
            path='/clusters/test_name',
        )

        # valid calls
        return_mock = Mock(status_code=200)
        return_mock.json.return_value = {'clusterIDs': 'test!'}
        mock_get.return_value = return_mock
        result = wcs.get_cluster_config('test_name')
        self.assertEqual(result, {'clusterIDs': 'test!'})
        mock_get.assert_called_with(
            path='/clusters/test_name',
        )

        return_mock = Mock(status_code=200)
        return_mock.json.return_value = {'clusterIDs': 'test!'}
        mock_get.return_value = return_mock
        result = wcs.get_cluster_config('Test_Name')
        self.assertEqual(result, {'clusterIDs': 'test!'})
        mock_get.assert_called_with(
            path='/clusters/test_name',
        )

        return_mock = Mock(status_code=404)
        return_mock.json.return_value = {'clusterIDs': 'test!'}
        mock_get.return_value = return_mock
        result = wcs.get_cluster_config('test_name')
        self.assertEqual(result, {})
        mock_get.assert_called_with(
            path='/clusters/test_name',
        )
    def test_build_near_object(self):
        """
        Test the `with_near_object` method.
        """

        near_object = {"id": "test_id", "certainty": 0.55}

        # valid calls
        query = GetBuilder("Person", "name",
                           None).with_near_object(near_object).build()
        self.assertEqual(
            '{Get{Person(nearObject: {id: "test_id" certainty: 0.55} ){name}}}',
            query)

        # invalid calls
        near_error_msg = "Cannot use multiple 'near' filters, or a 'near' filter along with a 'ask' filter!"

        near_text = {
            "concepts": "computer",
            "moveTo": {
                "concepts": ["science"],
                "force": 0.5
            },
        }
        with self.assertRaises(AttributeError) as error:
            GetBuilder(
                "Person", "name",
                None).with_near_text(near_text).with_near_object(near_object)
        check_error_message(self, error, near_error_msg)
    def test_build_near_vector(self):
        """
        Test the `with_near_vector` method.
        """

        near_vector = {
            "vector": [1, 2, 3, 4, 5, 6, 7, 8, 9],
            "certainty": 0.55
        }

        # valid calls
        query = GetBuilder("Person", "name",
                           None).with_near_vector(near_vector).build()
        self.assertEqual(
            '{Get{Person(nearVector: {vector: [1, 2, 3, 4, 5, 6, 7, 8, 9] certainty: 0.55} ){name}}}',
            query)

        # invalid calls
        near_error_msg = "Cannot use multiple 'near' filters, or a 'near' filter along with a 'ask' filter!"

        near_object = {"id": "test_id", "certainty": 0.55}
        with self.assertRaises(AttributeError) as error:
            GetBuilder("Person", "name", None).with_near_object(
                near_object).with_near_vector(near_vector)
        check_error_message(self, error, near_error_msg)
    def test_get(self, mock_get_params):
        """
        Test the `get` method.
        """

        # error messages
        requests_error_message = 'Could not get object/s.'
        unexpected_error_message = "Get object/s"

        # test exceptions

        data_object = DataObject(
            mock_connection_method('get', side_effect=RequestsConnectionError("Test!"))
        )
        with self.assertRaises(RequestsConnectionError) as error:
            data_object.get()
        check_error_message(self, error, requests_error_message)
        
        data_object = DataObject(
            mock_connection_method('get', status_code=204)
        )
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            data_object.get()
        check_startswith_error_message(self, error, unexpected_error_message)

        # test valid calls
        return_value_get = {"my_key": 12341}
        mock_get_params.return_value = {'include': "test1,test2"}
        connection_mock = mock_connection_method('get', return_json=return_value_get, status_code=200)
        data_object = DataObject(connection_mock)
        result = data_object.get()
        self.assertEqual(result, return_value_get)
        connection_mock.get.assert_called_with(
            path="/objects",
            params={'include': "test1,test2"}
        )

        return_value_get = {"my_key": '12341'}
        mock_get_params.return_value = {'include': "test1,test2"}
        connection_mock = mock_connection_method('get', return_json=return_value_get, status_code=200)
        data_object = DataObject(connection_mock)
        result = data_object.get(uuid="1d420c9c98cb11ec9db61e008a366d49")
        self.assertEqual(result, return_value_get)
        connection_mock.get.assert_called_with(
            path="/objects/1d420c9c-98cb-11ec-9db6-1e008a366d49",
            params={'include': "test1,test2"}
        )

        return_value_get = {"my_key": '12341'}
        mock_get_params.return_value = {'include': "test1,test2"}
        connection_mock = mock_connection_method('get', return_json=return_value_get, status_code=404)
        data_object = DataObject(connection_mock)
        result = data_object.get(uuid="1d420c9c-98cb-11ec-9db6-1e008a366d49")
        self.assertIsNone(result)
        connection_mock.get.assert_called_with(
            path="/objects/1d420c9c-98cb-11ec-9db6-1e008a366d49",
            params={'include': "test1,test2"}
        )
    def test_get_valid_uuid(self):
        """
        Test the `get_valid_uuid` function.
        """

        # valid calls
        result = get_valid_uuid("weaviate://localhost/28f3f61b-b524-45e0-9bbe-2c1550bf73d2")
        self.assertEqual(result, "28f3f61b-b524-45e0-9bbe-2c1550bf73d2")

        result = get_valid_uuid("weaviate://otherhost.com/28f3f61b-b524-45e0-9bbe-2c1550bf73d2")
        self.assertEqual(result, "28f3f61b-b524-45e0-9bbe-2c1550bf73d2")

        result = get_valid_uuid("http://localhost:8080/v1/objects/1c9cd584-88fe-5010-83d0-017cb3fcb446")
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        result = get_valid_uuid("http://otherhost_2:8080/v1/objects/1c9cd584-88fe-5010-83d0-017cb3fcb446")
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        result = get_valid_uuid("http://otherhost_2:8080/v1/objects/1c9cd58488fe501083d0017cb3fcb446")
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        result = get_valid_uuid("1c9cd584-88fe-5010-83d0-017cb3fcb446")
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        result = get_valid_uuid("1c9cd58488fe501083d0017cb3fcb446")
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        result = get_valid_uuid(uuid_lib.UUID("1c9cd58488fe501083d0017cb3fcb446"))
        self.assertEqual(result, "1c9cd584-88fe-5010-83d0-017cb3fcb446")

        # invalid formats
        type_error_message = "'uuid' must be of type str or uuid.UUID, but was: "
        value_error_message = "Not valid 'uuid' or 'uuid' can not be extracted from value"
        ## neither an object URL nor a weaviate object URL
        with self.assertRaises(ValueError) as error:
            get_valid_uuid("http://localhost:8080/v1/1c9cd584-88fe-5010-83d0-017cb3fcb")
        check_error_message(self, error, value_error_message)

        # wrong UUID format
        with self.assertRaises(ValueError) as error:
            get_valid_uuid("http://localhost:8080/v1/objects/some-UUID")
        check_error_message(self, error, value_error_message)

        ## wrong '/v2', shoudl be '/v1'
        with self.assertRaises(ValueError) as error:
            get_valid_uuid("http://localhost:8080/v2/objects/1c9cd584-88fe-5010-83d0-017cb3fcb")
        check_error_message(self, error, value_error_message)

        ## wrong URL
        with self.assertRaises(ValueError) as error:
            get_valid_uuid("weaviate://INVALID_URL//1c9cd584-88fe-5010-83d0-017cb3fcb")
        check_error_message(self, error, value_error_message)

        ## wrong UUID data type
        with self.assertRaises(TypeError) as error:
            get_valid_uuid(12)
        check_error_message(self, error, type_error_message + str(int))
Beispiel #16
0
    def test_auto_create(self, mock_flush):
        """
        Test `_auto_create` method through `add_*` methods.
        """

        batch = Batch(Mock())
        batch.batch_size = 2  # this enables auto_create with batching `fixed`

        #######################################################################
        # only objects and batching_type 'fixed'
        batch.add_data_object({}, 'Test')
        mock_flush.assert_not_called()
        batch.add_data_object({}, 'Test')
        mock_flush.assert_called()
        mock_flush.reset_mock()

        #######################################################################
        # add references too, batching_type 'fixed'
        batch.batch_size = 4
        batch.add_reference('f0153f24-3923-4046-919b-6a3e8fd37393', 'Test',
                            'test', 'f0153f24-3923-4046-919b-6a3e8fd37394')
        mock_flush.assert_not_called()
        batch.add_reference('f0153f24-3923-4046-919b-6a3e8fd37396', 'Test',
                            'test', 'f0153f24-3923-4046-919b-6a3e8fd37397')
        mock_flush.assert_called()
        mock_flush.reset_mock()

        #######################################################################
        # batching_type 'dynamic'
        batch = Batch(Mock())
        batch.batch_size = 2  # this enables auto_create with batching `fixed`
        batch.dynamic = True  # NOTE: recommended are set to 2 when we set the batch_size to 2
        batch.add_data_object({}, 'Test')
        mock_flush.assert_not_called()
        batch.add_reference('f0153f24-3923-4046-919b-6a3e8fd37393', 'Test',
                            'test', 'f0153f24-3923-4046-919b-6a3e8fd37394')
        mock_flush.assert_not_called()
        batch.add_reference('f0153f24-3923-4046-919b-6a3e8fd37396', 'Test',
                            'test', 'f0153f24-3923-4046-919b-6a3e8fd37397')
        mock_flush.assert_called()
        batch.add_data_object({}, 'Test')
        mock_flush.assert_called()
        mock_flush.reset_mock()

        #######################################################################
        # exceptions
        ## error messages
        value_error = f'Unsupported batching type "{None}"'
        batch = Batch(Mock())
        with self.assertRaises(ValueError) as error:
            batch._auto_create(
            )  # This should not be called like this, only for test purposes
        check_error_message(self, error, value_error)
    def test__init__(self, mock_requests, mock_refresh_authentication):
        """
        Test the `__init__` method.
        """

        # error messages
        auth_error_message = (
            "No login credentials provided. The weaviate instance at "
            "test_url requires login credential, use argument 'auth_client_secret'."
        )

        # requests error
        mock_session = mock_requests.Session.return_value = Mock()

        # non 200 status_code return
        mock_session.get.side_effect = None
        mock_response = Mock(status_code=400)
        mock_session.get.return_value = mock_response
        connection = Connection('test_url', timeout_config=(3, 23))
        self.check_connection_attributes(connection, timeout_config=(3, 23))
        mock_session.get.assert_called_with(
            "test_url/v1/.well-known/openid-configuration",
            headers={"content-type": "application/json"},
            timeout=(3, 23))
        mock_refresh_authentication.assert_not_called()

        # 200 status_code return and no auth provided
        mock_session.get.side_effect = None
        mock_response = Mock(status_code=200)
        mock_session.get.return_value = mock_response
        with self.assertRaises(ValueError) as error:
            Connection('test_url')
        check_error_message(self, error, auth_error_message)
        mock_session.get.assert_called_with(
            "test_url/v1/.well-known/openid-configuration",
            headers={"content-type": "application/json"},
            timeout=(2, 20))

        # 200 status_code return and auth provided
        with patch("weaviate.connect.connection.isinstance"
                   ) as mock_func:  # mock is instance method
            mock_func.return_value = True  # isinstance returns True for any calls
            mock_session.get.side_effect = None
            mock_response = Mock(status_code=200)
            mock_session.get.return_value = mock_response
            connection = Connection('test_url')
            self.check_connection_attributes(connection,
                                             is_authentication_required=True)
            mock_session.get.assert_called_with(
                "test_url/v1/.well-known/openid-configuration",
                headers={"content-type": "application/json"},
                timeout=(2, 20))
            mock_refresh_authentication.assert_called()
Beispiel #18
0
    def test_get_clusters(self, mock_get):
        """
        Test the `get_clusters` method.
        """


        wcs = WCS(AuthClientPassword('*****@*****.**', 'testPassoword'))
        wcs._auth_bearer = 'test_bearer'

        # invalid calls

        ## error messages
        connection_error_message = 'WCS clusters were not fetched.'
        unexpected_error_message = 'Checking WCS instance'

        # connection error
        mock_get.side_effect = RequestsConnectionError('Test!')
        with self.assertRaises(RequestsConnectionError) as error:
            wcs.get_clusters()
        check_error_message(self, error, connection_error_message)
        mock_get.assert_called_with(
            path='/clusters/list',
            params={
                'email': '*****@*****.**'
            }
        )

        # unexpected error
        mock_get.side_effect = None
        mock_get.return_value = Mock(status_code=400)
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            wcs.get_clusters()
        check_startswith_error_message(self, error, unexpected_error_message)
        mock_get.assert_called_with(
            path='/clusters/list',
            params={
                'email': '*****@*****.**'
            }
        )

        # valid calls
        return_mock = Mock(status_code=200)
        return_mock.json.return_value = {'clusterIDs': 'test!'}
        mock_get.return_value = return_mock
        result = wcs.get_clusters()
        self.assertEqual(result, 'test!')
        mock_get.assert_called_with(
            path='/clusters/list',
            params={
                'email': '*****@*****.**'
            }
        )
Beispiel #19
0
    def test_delete(self, mock_delete):
        """
        Test the `delete` method.
        """

        wcs = WCS(AuthClientPassword('test_secret_username', 'test_password'))
        wcs._auth_bearer = 'test_bearer'

        # invalid calls

        ## error messages
        connection_error_message = 'WCS cluster was not deleted.'
        unexpected_error_message = 'Deleting WCS instance'

        ## connection error
        mock_delete.side_effect = RequestsConnectionError('Test!')
        with self.assertRaises(RequestsConnectionError) as error:
            wcs.delete_cluster('test_name')
        check_error_message(self, error, connection_error_message)
        mock_delete.assert_called_with(
            path='/clusters/test_name',
        )

        ## unexpected error
        mock_delete.side_effect = None
        mock_delete.return_value = Mock(status_code=400)
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            wcs.delete_cluster('test_name')
        check_startswith_error_message(self, error, unexpected_error_message)
        mock_delete.assert_called_with(
            path='/clusters/test_name',
        )

        # valid calls
        mock_delete.return_value = Mock(status_code=200)
        self.assertIsNone(wcs.delete_cluster('test_name'))
        mock_delete.assert_called_with(
            path='/clusters/test_name',
        )

        mock_delete.return_value = Mock(status_code=404)
        self.assertIsNone(wcs.delete_cluster('test_name'))
        mock_delete.assert_called_with(
            path='/clusters/test_name',
        )

        mock_delete.return_value = Mock(status_code=404)
        self.assertIsNone(wcs.delete_cluster('TesT_naMe'))
        mock_delete.assert_called_with(
            path='/clusters/test_name',
        )
Beispiel #20
0
    def test_dynamic(self, mock_auto_create):
        """
        Test Setter and Getter for 'dynamic'.
        """

        batch = Batch(Mock())
        self.check_instance(batch)

        self.assertFalse(batch.dynamic)
        self.check_instance(batch)

        #######################################################################
        # test when batching_type is None (setter does nothing)
        batch.dynamic = True
        self.assertFalse(batch.dynamic)
        self.check_instance(batch, batching_type=None)

        #######################################################################
        # test when batching_type not None
        batch._batching_type = 'fixed'
        batch.dynamic = True
        self.assertTrue(batch.dynamic)
        self.check_instance(batch, batching_type='dynamic')
        mock_auto_create.assert_called()
        mock_auto_create.reset_mock()

        # set again to True
        batch.dynamic = True
        self.assertTrue(batch.dynamic)
        self.check_instance(batch, batching_type='dynamic')
        mock_auto_create.assert_called()
        mock_auto_create.reset_mock()

        batch.dynamic = False
        self.assertFalse(batch.dynamic)
        self.check_instance(batch, batching_type='fixed')
        mock_auto_create.assert_called()
        mock_auto_create.reset_mock()

        #######################################################################
        # test exceptions
        ## messages
        type_error = "'dynamic' must be of type bool."

        with self.assertRaises(TypeError) as error:
            batch.dynamic = 0
        check_error_message(self, error, type_error)
        self.check_instance(batch, batching_type='fixed')
        mock_auto_create.assert_not_called()
    def test___init__(self):
        """
        Test the `__init__` method.
        """

        # invalid calls

        ## error messages
        content_error_msg = lambda dt: f"NearObject filter is expected to be type dict but is {dt}"
        beacon_id_error_msg = "The 'content' argument should contain EITHER `id` OR `beacon`!"
        beacon_id_type_error_msg = lambda what, dt: (
            f"'{what}' key-value is expected to be of type <class 'str'> but is {dt}!"
        )
        certainty_error_msg = lambda dtype: (
            f"'certainty' key-value is expected to be of type <class 'float'> but is {dtype}!"
        )

        with self.assertRaises(TypeError) as error:
            NearObject(123)
        check_error_message(self, error, content_error_msg(int))

        with self.assertRaises(ValueError) as error:
            NearObject({'id': 123, 'beacon': 456})
        check_error_message(self, error, beacon_id_error_msg)

        with self.assertRaises(TypeError) as error:
            NearObject({
                'id': 123,
            })
        check_error_message(self, error, beacon_id_type_error_msg('id', int))

        with self.assertRaises(TypeError) as error:
            NearObject({
                'beacon': {123},
            })
        check_error_message(self, error,
                            beacon_id_type_error_msg('beacon', set))

        with self.assertRaises(TypeError) as error:
            NearObject({'beacon': 'test_beacon', 'certainty': False})
        check_error_message(self, error, certainty_error_msg(bool))

        # valid calls

        NearObject({
            'id': 'test_id',
        })

        NearObject({'beacon': 'test_beacon', 'certainty': 0.7})
    def test__get_params(self):
        """
        Test the `_get_params` function.
        """
        
        from weaviate.data.crud_data import _get_params

        # error messages
        type_error_message = lambda dt: f"Additional properties must be of type list but are {dt}"

        with self.assertRaises(TypeError) as error:
            _get_params("Test", False)
        check_error_message(self, error, type_error_message(str))

        self.assertEqual(_get_params(["test1","test2"], False), {'include': "test1,test2"})
        self.assertEqual(_get_params(None, True), {'include': "vector"})
        self.assertEqual(_get_params([], True), {'include': "vector"})
        self.assertEqual(_get_params(["test1","test2"], True), {'include': "test1,test2,vector"})
    def test_build_with_offset(self):
        """
        Test the `with_limit` method.
        """

        # valid calls
        query = GetBuilder("Person", "name", None).with_offset(20).build()
        self.assertEqual('{Get{Person(offset: 20 ){name}}}', query)

        # invalid calls
        limit_error_msg = 'offset cannot be non-positive (offset >=1).'
        with self.assertRaises(ValueError) as error:
            GetBuilder("A", ["str"], None).with_offset(0)
        check_error_message(self, error, limit_error_msg)

        with self.assertRaises(ValueError) as error:
            GetBuilder("A", ["str"], None).with_offset(-1)
        check_error_message(self, error, limit_error_msg)
Beispiel #24
0
    def test___init__(self, mock_set_bearer):
        """
        Test the `__init__` method.
        """
        # invalid calls
        ## error messages
        login_error_message = (
                "No login credentials provided, or wrong type of credentials! "
                "Accepted type of credentials: weaviate.auth.AuthClientPassword"
            )

        with self.assertRaises(AuthenticationFailedException) as error:
            WCS(None)
        check_error_message(self, error, login_error_message)
        mock_set_bearer.assert_not_called()

        # valid calls
        # without DEV
        auth = AuthClientPassword('test_user', 'test_pass')
        wcs = WCS(auth)
        self.assertTrue(wcs._is_authentication_required)
        self.assertEqual(wcs.timeout_config, (2, 20))
        self.assertEqual(wcs._auth_expires, 0)
        self.assertIsNone(wcs._auth_bearer)
        self.assertEqual(wcs._auth_client_secret, auth)
        self.assertEqual(wcs.url, 'https://wcs.api.semi.technology')
        mock_set_bearer.assert_called_with(
            'wcs',
            'https://auth.wcs.api.semi.technology/auth/realms/SeMI/.well-known/openid-configuration'
        )

        # without DEV
        auth = AuthClientPassword('test_user', 'test_pass')
        wcs = WCS(auth, dev=True)
        self.assertTrue(wcs._is_authentication_required)
        self.assertEqual(wcs.timeout_config, (2, 20))
        self.assertEqual(wcs._auth_expires, 0)
        self.assertIsNone(wcs._auth_bearer)
        self.assertEqual(wcs._auth_client_secret, auth)
        self.assertEqual(wcs.url, 'https://dev.wcs.api.semi.technology')
        mock_set_bearer.assert_called_with(
            'wcs',
            'https://auth.dev.wcs.api.semi.technology/auth/realms/SeMI/.well-known/openid-configuration'
        )
    def test_validate_schema(self):
        """
        Test `validate_schema` function.
        """

        # incalid calls
        classess_error_message = ('Each schema has to have "classes" '
            'in the first level of the JSON format file/parameter/object')
        class_key_error_message = '"class" key is missing in class definition.'
        
        invalid_schema = {}
        with self.assertRaises(SchemaValidationException) as error:
            validate_schema(invalid_schema)
        check_error_message(self, error, classess_error_message)

        invalid_schema = {"classes": "my_class"}
        with self.assertRaises(SchemaValidationException) as error:
            validate_schema(invalid_schema)
        check_error_message(self, error, f'"classes" is type {str} but should be {list}.')

        invalid_schema = {"things": {"classes": []}}
        with self.assertRaises(SchemaValidationException) as error:
            validate_schema(invalid_schema)
        check_error_message(self, error, classess_error_message)

        invalid_schema = {"classes": ["my_class"]}
        with self.assertRaises(SchemaValidationException) as error:
            validate_schema(invalid_schema)
        check_error_message(self, error, f'"class" is type {str} but should be {dict}.')

        # test the call of the `check_class` function inside `validate_schema`
        invalid_schema = {"classes": [{"my_class": []}]}
        with self.assertRaises(SchemaValidationException) as error:
            validate_schema(invalid_schema)
        check_error_message(self, error, class_key_error_message)

        # valid calls
        valid_schema = {"classes": []}
        self.assertIsNone(validate_schema(valid_schema))
        valid_schema = {"classes": [], "author" : "Unit Test"}
        self.assertIsNone(validate_schema(valid_schema))
        self.assertIsNone(validate_schema(valid_schema_with_all_properties))
    def test___init__(self):
        """
        Test the `__init__` method.
        """

        # invalid calls

        ## error messages
        content_error_msg = lambda dt: f"NearImage filter is expected to be type dict but is {dt}"
        image_key_error_msg = '"content" is missing the mandatory key "image"!'
        image_value_error_msg = lambda dt: f"'image' key-value is expected to be of type <class 'str'> but is {dt}!"
        certainty_error_msg = lambda dtype: (
            f"'certainty' key-value is expected to be of type <class 'float'> but is {dtype}!"
        )

        with self.assertRaises(TypeError) as error:
            NearImage(123)
        check_error_message(self, error, content_error_msg(int))

        with self.assertRaises(ValueError) as error:
            NearImage({'id': 'image_path.png', 'certainty': 456})
        check_error_message(self, error, image_key_error_msg)

        with self.assertRaises(TypeError) as error:
            NearImage({'image': True})
        check_error_message(self, error, image_value_error_msg(bool))

        with self.assertRaises(TypeError) as error:
            NearImage({'image': b'True'})
        check_error_message(self, error, image_value_error_msg(bytes))

        with self.assertRaises(TypeError) as error:
            NearImage({'image': 'the_encoded_image', 'certainty': False})
        check_error_message(self, error, certainty_error_msg(bool))

        # valid calls

        NearImage({
            'image': 'test_image',
        })

        NearImage({'image': 'test_image_2', 'certainty': 0.7})
Beispiel #27
0
    def test_get(self):
        """
        Test the `get` method.
        """

        # invalid calls
        requests_error_message = 'Schema could not be retrieved.'
        unexpected_error_msg = "Get schema"
        type_error_msg = lambda dt: f"'class_name' argument must be of type `str`! Given type: {dt}"

        mock_conn = mock_connection_method(
            'get', side_effect=RequestsConnectionError("Test!"))
        schema = Schema(mock_conn)
        with self.assertRaises(RequestsConnectionError) as error:
            schema.get()
        check_error_message(self, error, requests_error_message)

        mock_conn = mock_connection_method('get', status_code=404)
        schema = Schema(mock_conn)
        with self.assertRaises(UnexpectedStatusCodeException) as error:
            schema.get()
        check_startswith_error_message(self, error, unexpected_error_msg)

        connection_mock_file = mock_connection_method(
            'get', status_code=200, return_json={'Test': 'OK!'})
        schema = Schema(connection_mock_file)
        with self.assertRaises(TypeError) as error:
            schema.get(1234)
        check_error_message(self, error, type_error_msg(int))

        # valid calls

        self.assertEqual(schema.get(), {'Test': 'OK!'})
        connection_mock_file.get.assert_called_with(path="/schema", )

        self.assertEqual(schema.get("Artist"), {'Test': 'OK!'})
        connection_mock_file.get.assert_called_with(path="/schema/Artist")

        # with uncapitalized class_name
        self.assertEqual(schema.get("artist"), {'Test': 'OK!'})
        connection_mock_file.get.assert_called_with(path="/schema/Artist")
    def test_build_near_image(self, mock_image_encoder_b64):
        """
        Test the `with_near_object` method.
        """

        near_image = {"image": "test_image", "certainty": 0.55}

        # valid calls
        ## encode False
        query = GetBuilder("Person",
                           "name", None).with_near_image(near_image,
                                                         encode=False).build()
        self.assertEqual(
            '{Get{Person(nearImage: {image: "test_image" certainty: 0.55} ){name}}}',
            query)
        mock_image_encoder_b64.assert_not_called()

        ## encode True
        query = GetBuilder("Person",
                           "name", None).with_near_image(near_image,
                                                         encode=True).build()
        self.assertEqual(
            '{Get{Person(nearImage: {image: "test_call" certainty: 0.55} ){name}}}',
            query)
        mock_image_encoder_b64.assert_called()

        # invalid calls
        near_error_msg = "Cannot use multiple 'near' filters, or a 'near' filter along with a 'ask' filter!"

        near_text = {
            "concepts": "computer",
            "moveTo": {
                "concepts": ["science"],
                "force": 0.5
            },
        }
        with self.assertRaises(AttributeError) as error:
            GetBuilder(
                "Person", "name",
                None).with_near_text(near_text).with_near_image(near_image)
        check_error_message(self, error, near_error_msg)
    def test_image_encoder_b64(self):
        """
        Test the `image_encoder_b64` function.
        """


        encode_weaviate_logo_b64 = 'iVBORw0KGgoAAAANSUhEUgAAAZAAAAE5CAYAAAC+rHbqAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ1IDc5LjE2MzQ5OSwgMjAxOC8wOC8xMy0xNjo0MDoyMiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTkgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6Rjc3MkEzQzdGM0QxMTFFODlBRTRBNjMyNUE2MTk3NzgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6Rjc3MkEzQzhGM0QxMTFFODlBRTRBNjMyNUE2MTk3NzgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RS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yb5HdPnAP39A+xjDVJA9znECAA2wXIqPtlbHVCgACwA0eaAIBN/L8AAwBLF+9LrWiboAAAAABJRU5ErkJggg=='
        file_path_value_error_message = "No file found at location non-existingfile.png"
        type_error_message = ('"image_or_image_path" should be a image path or a binary read file'
                            ' (io.BufferedReader)')

        # invalid calls
        with self.assertRaises(ValueError) as error:
            image_encoder_b64('non-existingfile.png')
        check_error_message(self, error, file_path_value_error_message)

        with self.assertRaises(TypeError) as error:
            image_encoder_b64(True)
        check_error_message(self, error, type_error_message)

        with self.assertRaises(TypeError) as error:
            with open('image.png', 'wb') as file:
                image_encoder_b64(file)
        check_error_message(self, error, type_error_message)

        # valid calls
        encrypted_1 = image_encoder_b64('integration/weaviate-logo.png')
        self.assertEqual(encrypted_1, encode_weaviate_logo_b64)
        self.assertIsInstance(encrypted_1, str)

        with open('integration/weaviate-logo.png', 'rb') as file:
            encrypted_2 = image_encoder_b64(file)
        self.assertEqual(encrypted_2, encode_weaviate_logo_b64)
        self.assertIsInstance(encrypted_2, str)
    def test___init__(self):
        """
        Test the `__init__` method.
        """

        class_name_error_msg = f"class name must be of type str but was {int}"
        properties_error_msg = ("properties must be of type str or "
                                f"list of str but was {int}")
        property_error_msg = "All the `properties` must be of type `str`!"

        # invalid calls
        with self.assertRaises(TypeError) as error:
            GetBuilder(1, ["a"], None)
        check_error_message(self, error, class_name_error_msg)

        with self.assertRaises(TypeError) as error:
            GetBuilder("A", 2, None)
        check_error_message(self, error, properties_error_msg)

        with self.assertRaises(TypeError) as error:
            GetBuilder("A", [True], None)
        check_error_message(self, error, property_error_msg)

        # valid calls
        GetBuilder("name", "prop", None)
        GetBuilder("name", ["prop1", "prop2"], None)