Ejemplo n.º 1
0
    def wait_for_copy(self, timeout=None):
        """
        Wait for a copy operation to complete. Copies occur asynchronously
        and can take a long time to complete.  Features will not be accessible
        in the FeatureCollection until the copy completes.

        If the product was not created using a copy job, a BadRequestError is raised.
        If the copy job ran, but failed, a FailedJobError is raised.
        If a timeout is specified and the timeout is reached, a WaitTimeoutError is raised.

        Parameters
        ----------
        timeout : int
            Number of seconds to wait before the wait times out.  If not specified, will
            wait indefinitely.

        Example
        -------
        >>> from descarteslabs.vectors import FeatureCollection, properties as p
        >>> aoi_geometry = {
        ...    'type': 'Polygon',
        ...    'coordinates': [[[-109, 31], [-102, 31], [-102, 37], [-109, 37], [-109, 31]]]}
        >>> all_us_cities = FeatureCollection('d1349cc2d8854d998aa6da92dc2bd24')  # doctest: +SKIP
        >>> filtered_cities = all_us_cities.filter(properties=(p.name.like("S%")))  # doctest: +SKIP
        >>> filtered_cities_fc = filtered_cities.copy(name='filtered-cities',
        ...    title='My Filtered US Cities Vector Collection',
        ...    description='A collection of cities in the US')  # doctest: +SKIP
        >>> filtered_cities_fc.wait_for_copy(timeout=120)  # doctest: +SKIP
        """
        job = CopyJob(self.id, self.vector_client)
        job.wait_for_completion(timeout)
Ejemplo n.º 2
0
    def test_copy_job_check_complete(self, vector_client):
        vector_client.get_product_from_query_status.return_value = self.get_product_from_query_status_response
        job = CopyJob("product_id", vector_client)

        self.assertTrue(job._check_complete())

        job.properties["state"] = "RUNNING"
        self.assertFalse(job._check_complete())
    def test_copy_job_check_complete(self, vector_client):
        vector_client.get_product_from_query_status.return_value = (
            self.get_product_from_query_status_response)
        job = CopyJob("product_id", vector_client)

        assert job._check_complete()

        job.properties["state"] = "RUNNING"
        assert not job._check_complete()
Ejemplo n.º 4
0
    def test_copy_job_check_complete_exception(self, vector_client):
        vector_client.get_product_from_query_status.return_value = self.get_product_from_query_status_response
        job = CopyJob("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 wait_for_copy(self, timeout=None):
        """
        Wait for a copy operation to complete. Copies occur asynchronously
        and can take a long time to complete.  Features will not be accessible
        in the FeatureCollection until the copy completes.

        If the product was not created using a copy job, a ``BadRequestError`` is raised.
        If the copy job ran, but failed, a FailedJobError is raised.
        If a timeout is specified and the timeout is reached, a ``WaitTimeoutError`` is raised.

        Parameters
        ----------
        timeout : int
            Number of seconds to wait before the wait times out.  If not specified, will
            wait indefinitely.

        Raises
        ------
        ~descarteslabs.vectors.exceptions.FailedJobError
            Raised when the copy job fails to complete successfully.
        ~descarteslabs.client.exceptions.NotFoundError
            Raised if the product or status 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.
        ~descarteslabs.vectors.exceptions.WaitTimeoutError
            Raised when the copy job doesn't complete before the timeout is reached.

        Example
        -------
        >>> from descarteslabs.vectors import FeatureCollection, properties as p
        >>> aoi_geometry = {
        ...    'type': 'Polygon',
        ...    'coordinates': [[[-109, 31], [-102, 31], [-102, 37], [-109, 37], [-109, 31]]]}
        >>> all_us_cities = FeatureCollection('d1349cc2d8854d998aa6da92dc2bd24')  # doctest: +SKIP
        >>> filtered_cities = all_us_cities.filter(properties=(p.name.like("S%")))  # doctest: +SKIP
        >>> filtered_cities_fc = filtered_cities.copy(product_id='filtered-cities',
        ...    title='My Filtered US Cities Vector Collection',
        ...    description='A collection of cities in the US')  # doctest: +SKIP
        >>> filtered_cities_fc.wait_for_copy(timeout=120)  # doctest: +SKIP
        """
        job = CopyJob(self.id, self.vector_client)
        job.wait_for_completion(timeout)
Ejemplo n.º 6
0
    def test_copy_job(self, vector_client):
        vector_client.get_product_from_query_status.return_value = self.get_product_from_query_status_response

        job = CopyJob("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_copy_job(self, vector_client):
        vector_client.get_product_from_query_status.return_value = (
            self.get_product_from_query_status_response)

        job = CopyJob("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"