示例#1
0
    def _fetch_result_file(self):
        from osmaxx.api_client import ConversionApiClient
        from . import OutputFile
        from osmaxx.excerptexport.models.output_file import uuid_directory_path
        api_client = ConversionApiClient()
        file_path = api_client.get_result_file_path(
            self.conversion_service_job_id)
        now = timezone.now()
        of = OutputFile.objects.create(
            export=self,
            mime_type='application/zip',
            file_extension='zip',
        )
        new_file_name = uuid_directory_path(of, file_path)
        new_file_path = os.path.join(settings.MEDIA_ROOT, new_file_name)

        of.file.name = new_file_name

        os.makedirs(os.path.dirname(new_file_path), exist_ok=True)
        shutil.move(file_path, new_file_path)
        of.file_removal_at = now + RESULT_FILE_AVAILABILITY_DURATION
        of.save()

        self.finished_at = now
        self.save()
def test_create_boundary_posts_to_clipping_area_resource(
        mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    args, kwargs = c.authorized_post.call_args
    assert kwargs['url'] == 'clipping_area/'
示例#3
0
 def send_to_conversion_service(self):
     from osmaxx.api_client.conversion_api_client import ConversionApiClient
     api_client = ConversionApiClient()
     bounding_geometry = self.bounding_geometry
     if self.excerpt_type == self.EXCERPT_TYPE_COUNTRY_BOUNDARY:
         bounding_geometry = self.simplified_buffered()
     return api_client.create_boundary(bounding_geometry, name=self.name)
def test_create_job_makes_authorized_post_with_json_payload(mocker, user):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_parametrization_reply = dict(id=sentinel.PARAMETRIZATION_ID)
    c.create_job(parametrization=post_parametrization_reply,
                 callback_url=sentinel.CALLBACK_URL,
                 user=user)
    c.authorized_post.assert_called_once_with(url=ANY, json_data=ANY)
def test_create_parametrization_returns_post_request_response_json_payload_as_dict(
        mocker):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_boundary_reply = dict(id=sentinel.CLIPPING_AREA_ID)
    result = \
        c.create_parametrization(boundary=post_boundary_reply, out_format=sentinel.OUT_FORMAT, detail_level=sentinel.DETAIL_LEVEL, out_srs=sentinel.OUT_SRS)
    assert result == c.authorized_post.return_value.json.return_value
def test_create_boundary_posts_payload_with_structure_expected_by_conversion_service_api(
        mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    args, kwargs = c.authorized_post.call_args
    assert_that(kwargs['json_data'].keys(),
                contains_inanyorder('name', 'clipping_multi_polygon'))
def test_create_boundary_posts_geojson(mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    args, kwargs = c.authorized_post.call_args
    assert kwargs['json_data']['clipping_multi_polygon'] == {
        "type": "MultiPolygon",
        "coordinates": nested_list(geos_multipolygon.coords)
    }
def test_create_job_returns_post_request_response_json_payload_as_dict(
        mocker, user):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_parametrization_reply = dict(id=sentinel.PARAMETRIZATION_ID)
    result = c.create_job(parametrization=post_parametrization_reply,
                          callback_url=sentinel.CALLBACK_URL,
                          user=user)
    assert result == c.authorized_post.return_value.json.return_value
def test_create_job_posts_callback_url(mocker, user):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_parametrization_reply = dict(id=sentinel.PARAMETRIZATION_ID)
    c.create_job(parametrization=post_parametrization_reply,
                 callback_url=sentinel.CALLBACK_URL,
                 user=user)
    args, kwargs = c.authorized_post.call_args
    assert kwargs['json_data']['callback_url'] == sentinel.CALLBACK_URL
def test_create_parametrization_makes_authorized_post_with_json_payload(
        mocker):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_boundary_reply = dict(id=sentinel.CLIPPING_AREA_ID)
    c.create_parametrization(boundary=post_boundary_reply,
                             out_format=sentinel.OUT_FORMAT,
                             detail_level=sentinel.DETAIL_LEVEL,
                             out_srs=sentinel.OUT_SRS)
    c.authorized_post.assert_called_once_with(url=ANY, json_data=ANY)
def test_create_parametrization_posts_out_srs(mocker):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_boundary_reply = dict(id=sentinel.CLIPPING_AREA_ID)
    c.create_parametrization(boundary=post_boundary_reply,
                             out_format=sentinel.OUT_FORMAT,
                             detail_level=sentinel.DETAIL_LEVEL,
                             out_srs=sentinel.OUT_SRS)
    args, kwargs = c.authorized_post.call_args
    assert kwargs['json_data']['out_srs'] == sentinel.OUT_SRS
def test_create_job_posts_payload_with_structure_expected_by_conversion_servic_api(
        mocker, user):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_parametrization_reply = dict(id=sentinel.PARAMETRIZATION_ID)
    c.create_job(parametrization=post_parametrization_reply,
                 callback_url=sentinel.CALLBACK_URL,
                 user=user)
    args, kwargs = c.authorized_post.call_args
    assert_that(
        kwargs['json_data'].keys(),
        contains_inanyorder('callback_url', 'parametrization', 'queue_name'))
示例#13
0
 def send_to_conversion_service(self, clipping_area_json, incoming_request):
     from osmaxx.api_client.conversion_api_client import ConversionApiClient
     api_client = ConversionApiClient()
     extraction_format = self.file_format
     out_srs = self.extraction_order.coordinate_reference_system
     detail_level = self.extraction_order.detail_level
     parametrization_json = api_client.create_parametrization(boundary=clipping_area_json, out_format=extraction_format, detail_level=detail_level, out_srs=out_srs)
     job_json = api_client.create_job(
         parametrization_json, self.get_full_status_update_uri(incoming_request), user=self.extraction_order.orderer
     )
     self.conversion_service_job_id = job_json['id']
     self.status = job_json['status']
     self.save()
     return job_json
def test_create_parametrization_posts_payload_with_structure_expected_by_conversion_service_api(
        mocker):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    post_boundary_reply = dict(id=sentinel.CLIPPING_AREA_ID)
    c.create_parametrization(boundary=post_boundary_reply,
                             out_format=sentinel.OUT_FORMAT,
                             detail_level=sentinel.DETAIL_LEVEL,
                             out_srs=sentinel.OUT_SRS)
    args, kwargs = c.authorized_post.call_args
    assert_that(
        kwargs['json_data'].keys(),
        contains_inanyorder('out_format', 'out_srs', 'detail_level',
                            'clipping_area'))
def test_create_boundary_makes_authorized_post_with_json_payload(
        mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    c.authorized_post.assert_called_once_with(url=ANY, json_data=ANY)
def test_create_boundary_returns_post_request_response_json_payload_as_dict(
        mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    result = c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    assert result == c.authorized_post.return_value.json.return_value
def test_create_boundary_posts_name(mocker, geos_multipolygon):
    c = ConversionApiClient()
    mocker.patch.object(c, 'authorized_post', autospec=True)
    c.create_boundary(geos_multipolygon, name=sentinel.NAME)
    args, kwargs = c.authorized_post.call_args
    assert kwargs['json_data']['name'] == sentinel.NAME