示例#1
0
    def test_delete_job_check_complete(self, vector_client):
        vector_client.get_delete_features_status.return_value = self.get_delete_features_status_response
        job = DeleteJob("product_id", vector_client)

        self.assertTrue(job._check_complete())

        job.properties["state"] = "RUNNING"
        self.assertFalse(job._check_complete())
    def test_delete_job_check_complete(self, vector_client):
        vector_client.get_delete_features_status.return_value = (
            self.get_delete_features_status_response)
        job = DeleteJob("product_id", vector_client)

        assert job._check_complete()

        job.properties["state"] = "RUNNING"
        assert not job._check_complete()
示例#3
0
    def test_delete_job_check_complete_exception(self, vector_client):
        vector_client.get_delete_features_status.return_value = self.get_delete_features_status_response
        job = DeleteJob("product_id", vector_client)
        job.properties["state"] = "FAILURE"

        with self.assertRaises(FailedJobError):
            job._check_complete()

        job.properties["state"] = "DONE"
        job.properties["errors"] = ["some error description"]
        with self.assertRaises(FailedJobError):
            job._check_complete()
    def delete_features(self):
        """
        Apply a filter to a product and delete features that match the filter criteria,
        taking into account calls to :meth:`filter`.  Cannot be used with
        calls to :meth:`limit`

        A query of some sort must be set, otherwise a ``BadRequestError`` will be raised.

        Delete jobs occur asynchronously and can take a long time to complete. You
        can access :meth:`features` while a delete job is running,
        but you cannot issue another :meth:`delete_features` until
        the current job has completed running.  Use
        :meth:`DeleteJob.wait_for_completion() <descarteslabs.vectors.async_job.DeleteJob.wait_for_completion>`
        to block until the job is done.

        Returns
        -------
        :class:`DeleteJob <descarteslabs.vectors.async_job.DeleteJob>`
            A new `DeleteJob`.

        Raises
        ------
        ~descarteslabs.client.exceptions.BadRequestError
            Raised when the request is malformed, e.g. the query limit is not a number.
        ~descarteslabs.vectors.exceptions.InvalidQueryException
            Raised when a limit was applied to the ``FeatureCollection``.
        ~descarteslabs.client.exceptions.NotFoundError
            Raised if the product cannot be found.
        ~descarteslabs.client.exceptions.RateLimitError
            Raised when too many requests have been made within a given time period.
        ~descarteslabs.client.exceptions.ServerError
            Raised when a unknown error occurred on the server.

        Example
        -------
        >>> from descarteslabs.vectors import FeatureCollection
        >>> aoi_geometry = {
        ...    'type': 'Polygon',
        ...    'coordinates': [[[-109, 31], [-102, 31], [-102, 37], [-109, 37], [-109, 31]]]}
        >>> fc = FeatureCollection('my-vector-product-id')  # doctest: +SKIP
        >>> fc.filter(geometry=aoi_geometry)  # doctest: +SKIP
        >>> delete_job = fc.delete_features()  # doctest: +SKIP
        >>> delete_job.wait_for_completion()  # doctest: +SKIP
        """
        if self._query_limit:
            raise InvalidQueryException(
                "limits cannot be used when deleting features")

        params = dict(
            product_id=self.id,
            geometry=self._query_geometry,
            query_expr=self._query_property_expression,
        )

        product = self.vector_client.delete_features_from_query(**params).data
        return DeleteJob(product.id)
示例#5
0
    def test_delete_job(self, vector_client):
        vector_client.get_delete_features_status.return_value = self.get_delete_features_status_response

        job = DeleteJob("product_id", vector_client)

        self.assertEqual(job.id, 'product_id')
        self.assertEqual(job.state, 'DONE')
        self.assertEqual(job.created, '2019-01-03T20:07:51.720000+00:00')
        self.assertEqual(job.started, '2019-01-03T20:07:51.903000+00:00')
        self.assertEqual(job.ended, '2019-01-03T20:07:53.903000+00:00')
    def test_delete_job(self, vector_client):
        vector_client.get_delete_features_status.return_value = (
            self.get_delete_features_status_response)

        job = DeleteJob("product_id", vector_client)

        assert job.id == "product_id"
        assert job.state == "DONE"
        assert job.created == "2019-01-03T20:07:51.720000+00:00"
        assert job.started == "2019-01-03T20:07:51.903000+00:00"
        assert job.ended == "2019-01-03T20:07:53.903000+00:00"
示例#7
0
    def delete_features(self):
        """
        Apply a filter to a product and delete features that match the filter criteria,
        taking into account calls to `FeatureCollection.filter()`.  Cannot be used with
        calls to `FeatureCollection.limit()`

        A query of some sort must be set, otherwise a BadRequestError will be raised.

        Delete jobs occur asynchronously and can take a long time to complete. You
        can access `FeatureCollection.features()` while a delete job is running,
        but you cannot issue another `FeatureCollection.delete_features()` until
        the current job has completed running.  Use `DeleteJob.wait_for_completion()`
        to block until the job is done.

        Parameters
        ----------
        vectors.async_job.DeleteJob
            A new `DeleteJob`.

        Example
        -------
        >>> from descarteslabs.vectors import FeatureCollection
        >>> aoi_geometry = {
        ...    'type': 'Polygon',
        ...    'coordinates': [[[-109, 31], [-102, 31], [-102, 37], [-109, 37], [-109, 31]]]}
        >>> fc = FeatureCollection('d1349cc2d8854d998aa6da92dc2bd24')  # doctest: +SKIP
        >>> fc.filter(geometry=aoi_geometry)  # doctest: +SKIP
        >>> delete_job = fc.delete_features()  # doctest: +SKIP
        >>> delete_job.wait_for_completion()  # doctest: +SKIP
        """
        if self._query_limit:
            raise InvalidQueryException(
                "limits cannot be used when deleting features")

        params = dict(
            product_id=self.id,
            geometry=self._query_geometry,
            query_expr=self._query_property_expression,
        )

        product = self.vector_client.delete_features_from_query(**params).data
        return DeleteJob(product.id)