Beispiel #1
0
    def test_calling_tracker_with_payload_indicating_final_status_for_only_remaining_nonfinal_export_of_extraction_order_advertises_downloads(
            self, emissary_class_mock, *args, **mocks):
        self.export.conversion_service_job_id = 1
        self.export.save()
        for other_export in self.export.extraction_order.exports.exclude(id=self.export.id):
            other_export.status = FAILED
            other_export.save()
        emissary_mock = emissary_class_mock()
        factory = APIRequestFactory()
        request = factory.get(
            reverse('job_progress:tracker', kwargs=dict(export_id=self.export.id)),
            data=dict(status='finished', job='http://localhost:8901/api/conversion_job/1/')
        )

        resulting_file = tempfile.NamedTemporaryFile()
        resulting_file.write(b'dummy file')
        resulting_file.seek(0)

        requests_mock = mocks['requests']
        requests_mock.get(
            'http://localhost:8901/api/conversion_job/1/',
            json=dict(
                resulting_file_path=resulting_file.name
            )
        )

        views.tracker(request, export_id=str(self.export.id))

        expected_body = '\n'.join(
            [
                'The extraction order #{order_id} "Neverland" has been processed.',
                'Results available for download:',
                '- Esri File Geodatabase (http://testserver{download_url})',
                '',
                'The following exports have failed:',
                '- SpatiaLite',
                'Please order them anew if you need them. '
                'If there are repeated failures please inform the administrators.',
                '',
                'View the complete order at http://testserver/exports/',
            ]
        ).format(
            order_id=self.export.extraction_order.id,
            download_url=self.export.output_file.file.url,
        )
        assert_that(
            emissary_mock.mock_calls, contains_in_any_order(
                call.success(
                    'Export #{export_id} "Neverland" to Esri File Geodatabase has finished.'.format(
                        export_id=self.export.id,
                    ),
                ),
                call.inform_mail(
                    subject='Extraction Order #{order_id} "Neverland": 1 Export finished successfully, 1 failed'.format(
                        order_id=self.export.extraction_order.id,
                    ),
                    mail_body=expected_body,
                ),
            )
        )
Beispiel #2
0
 def test_create_and_retrieve_extraction_configuration_on_exising_extraction_configuration(
         self):
     extraction_order = models.ExtractionOrder.objects.create(
         excerpt=self.excerpt,
         orderer=self.user,
     )
     extraction_order.coordinate_reference_system = self.coordinate_reference_system
     extraction_order.extraction_formats = ['txt']
     assert_that(extraction_order.extraction_formats,
                 contains_in_any_order('txt'))
     assert extraction_order.coordinate_reference_system == 4326
Beispiel #3
0
 def test_create_extraction_order_with_extraction_configuration_and_retrieve_extraction_configuration(
         self):
     extraction_order_id = models.ExtractionOrder.objects.create(
         excerpt=self.excerpt,
         orderer=self.user,
         coordinate_reference_system=self.coordinate_reference_system,
         extraction_formats=['txt'],
     ).id
     extraction_order = models.ExtractionOrder.objects.get(
         pk=extraction_order_id)
     assert_that(extraction_order.extraction_formats,
                 contains_in_any_order('txt'))
     assert extraction_order.coordinate_reference_system == 4326
    def test_create_with_new_excerpt_persists_a_new_order(self):
        """
        When logged in, POSTing an export request with a new excerpt persists a new ExtractionOrder.
        """
        self.add_valid_email()
        self.assertEqual(ExtractionOrder.objects.count(), 0)
        self.client.login(username='******', password='******')
        self.client.post(reverse('excerptexport:order_new_excerpt'),
                         self.new_excerpt_post_data, HTTP_HOST='thehost.example.com')
        self.assertEqual(ExtractionOrder.objects.count(), 1)

        newly_created_order = ExtractionOrder.objects.first()  # only reproducible because there is only 1
        self.assertEqual(newly_created_order.coordinate_reference_system, self.coordinate_reference_system)
        self.assertEqual(newly_created_order.detail_level, self.detail_level)
        assert_that(newly_created_order.extraction_formats, contains_in_any_order('fgdb'))
        self.assertEqual(newly_created_order.orderer, self.user)
        self.assertEqual(newly_created_order.excerpt.name, 'A very interesting region')
Beispiel #5
0
    def test_calling_tracker_with_payload_indicating_queued_informs_user(
            self, emissary_class_mock, *args, **mocks):
        emissary_mock = emissary_class_mock()

        factory = APIRequestFactory()
        request = factory.get(
            reverse('job_progress:tracker',
                    kwargs=dict(export_id=self.export.id)),
            data=dict(status='queued',
                      job='http://localhost:8901/api/conversion_job/1/'))

        views.tracker(request, export_id=str(self.export.id))
        assert_that(
            emissary_mock.mock_calls,
            contains_in_any_order(
                call.info(
                    'Export #{export_id} "Neverland" to Esri File Geodatabase has been queued.'
                    .format(export_id=self.export.id), ), ))
Beispiel #6
0
    def test_calling_tracker_with_payload_indicating_final_status_for_only_remaining_nonfinal_export_of_extraction_order_advertises_downloads(
            self, emissary_class_mock, *args, **mocks):
        self.export.conversion_service_job_id = 1
        self.export.save()
        for other_export in self.export.extraction_order.exports.exclude(
                id=self.export.id):
            other_export.status = status.FAILED
            other_export.save()
        emissary_mock = emissary_class_mock()
        factory = APIRequestFactory()
        request = factory.get(
            reverse('job_progress:tracker',
                    kwargs=dict(export_id=self.export.id)),
            data=dict(status='finished',
                      job='http://*****:*****@hsr.ch',
        ]).format(
            order_id=self.export.extraction_order.id,
            download_url=self.export.output_file.file.url,
        )
        assert_that(
            emissary_mock.mock_calls,
            contains_in_any_order(
                call.success(
                    'Export #{export_id} "Neverland" to Esri File Geodatabase has finished.'
                    .format(export_id=self.export.id, ), ),
                call.inform_mail(
                    subject=expected_subject,
                    mail_body=expected_body,
                ),
            ))