diff --git a/osmaxx/conversion/__init__.py b/osmaxx/conversion/__init__.py index df64b7849..baf8706f2 100644 --- a/osmaxx/conversion/__init__.py +++ b/osmaxx/conversion/__init__.py @@ -1,5 +1,5 @@ -from .constants import output_format +from .constants import output_format, status default_app_config = 'osmaxx.conversion.apps.ConversionConfig' -__all__ = ['default_app_config', 'output_format'] +__all__ = ['default_app_config', 'output_format', 'status'] diff --git a/osmaxx/conversion/constants/statuses.py b/osmaxx/conversion/constants/status.py similarity index 96% rename from osmaxx/conversion/constants/statuses.py rename to osmaxx/conversion/constants/status.py index 003ce006a..60ff19089 100644 --- a/osmaxx/conversion/constants/statuses.py +++ b/osmaxx/conversion/constants/status.py @@ -8,7 +8,7 @@ STARTED = JobStatus.STARTED DEFERRED = JobStatus.DEFERRED -STATUS_CHOICES = ( +CHOICES = ( (RECEIVED, _('received')), # these are identical to the job-statuses of rq (JobStatus.QUEUED, _('queued')), diff --git a/osmaxx/conversion/management/commands/result_harvester.py b/osmaxx/conversion/management/commands/result_harvester.py index 59997ab06..ed8d8dc21 100644 --- a/osmaxx/conversion/management/commands/result_harvester.py +++ b/osmaxx/conversion/management/commands/result_harvester.py @@ -10,9 +10,8 @@ from django.core.management.base import BaseCommand from pbf_file_size_estimation import estimate_size -from osmaxx.conversion import models as conversion_models +from osmaxx.conversion import models as conversion_models, status from osmaxx.conversion._settings import CONVERSION_SETTINGS -from osmaxx.conversion.constants.statuses import FINAL_STATUSES, FINISHED, FAILED logging.basicConfig() logger = logging.getLogger(__name__) @@ -42,7 +41,7 @@ def _handle_failed_jobs(self): self._notify(conversion_job) def _handle_running_jobs(self): - active_jobs = conversion_models.Job.objects.exclude(status__in=FINAL_STATUSES)\ + active_jobs = conversion_models.Job.objects.exclude(status__in=status.FINAL_STATUSES)\ .values_list('rq_job_id', flat=True) for job_id in active_jobs: self._update_job(rq_job_id=job_id) @@ -67,7 +66,7 @@ def _update_job(self, rq_job_id): logger.info('updating job %d', rq_job_id) conversion_job.status = job.status - if job.status == FINISHED: + if job.status == status.FINISHED: add_file_to_job(conversion_job=conversion_job, result_zip_file=job.kwargs['output_zip_file_path']) add_meta_data_to_job(conversion_job=conversion_job, rq_job=job) conversion_job.save() @@ -75,11 +74,11 @@ def _update_job(self, rq_job_id): def _set_failed_unless_final(self, conversion_job, rq_job_id): conversion_job.refresh_from_db() - if conversion_job.status not in FINAL_STATUSES: + if conversion_job.status not in status.FINAL_STATUSES: logger.error("job {} of conversion job {} not found in queue but status is {} on database.".format( rq_job_id, conversion_job.id, conversion_job.status )) - conversion_job.status = FAILED + conversion_job.status = status.FAILED conversion_job.save() def _notify(self, conversion_job): @@ -136,5 +135,5 @@ def cleanup_old_jobs(): queues.append(django_rq.get_failed_queue()) for queue in queues: for job in queue.get_jobs(): - if job.status in FINAL_STATUSES: + if job.status in status.FINAL_STATUSES: job.delete() diff --git a/osmaxx/conversion/models.py b/osmaxx/conversion/models.py index 3901ae5fa..d523e2aba 100644 --- a/osmaxx/conversion/models.py +++ b/osmaxx/conversion/models.py @@ -7,12 +7,11 @@ from django.utils.translation import gettext_lazy as _ from rest_framework.reverse import reverse -from osmaxx.conversion import output_format +from osmaxx.conversion import output_format, status from osmaxx.clipping_area.models import ClippingArea from osmaxx.conversion.converters.converter import convert from osmaxx.conversion.converters.converter_gis.detail_levels import DETAIL_LEVEL_CHOICES, DETAIL_LEVEL_ALL from osmaxx.conversion.constants.coordinate_reference_systems import CRS_CHOICES -from osmaxx.conversion.constants.statuses import STATUS_CHOICES, RECEIVED def job_directory_path(instance, filename): @@ -40,7 +39,7 @@ class Job(models.Model): callback_url = models.URLField(_('callback url'), max_length=250) parametrization = models.ForeignKey(verbose_name=_('parametrization'), to=Parametrization, on_delete=models.CASCADE) rq_job_id = models.CharField(_('rq job id'), max_length=250, null=True) - status = models.CharField(_('job status'), choices=STATUS_CHOICES, default=RECEIVED, max_length=20) + status = models.CharField(_('job status'), choices=status.CHOICES, default=status.RECEIVED, max_length=20) resulting_file = models.FileField(_('resulting file'), upload_to=job_directory_path, null=True, max_length=250) estimated_pbf_size = models.FloatField(_('estimated pbf size in bytes'), null=True) unzipped_result_size = models.FloatField( diff --git a/osmaxx/excerptexport/migrations/0058_auto_20170511_1639.py b/osmaxx/excerptexport/migrations/0058_auto_20170511_1639.py new file mode 100644 index 000000000..39184d7dd --- /dev/null +++ b/osmaxx/excerptexport/migrations/0058_auto_20170511_1639.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-05-11 14:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('excerptexport', '0057_auto_20170511_1406'), + ] + + operations = [ + migrations.AlterField( + model_name='export', + name='status', + field=models.CharField(choices=[('received', 'received'), ('queued', 'queued'), ('finished', 'finished'), ('failed', 'failed'), ('started', 'started'), ('deferred', 'deferred')], default=None, max_length=20, null=True, verbose_name='job status'), + ), + ] diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index 45e5d6614..694daa8ee 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework.reverse import reverse -from osmaxx.conversion import output_format +from osmaxx.conversion import output_format, status from osmaxx.excerptexport._settings import RESULT_FILE_AVAILABILITY_DURATION, EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA logger = logging.getLogger(__name__) @@ -41,16 +41,12 @@ class Export(TimeStampModelMixin, models.Model): - the transformation of the data from the data sources' schemata (e.g. ``osm2pgsql`` schema) to the OSMaxx schema - the actual export to one specific GIS or navigation file format with one specific set of parameters """ - from osmaxx.conversion.constants.statuses import RECEIVED, QUEUED, FINISHED, FAILED, STARTED, DEFERRED, FINAL_STATUSES, STATUS_CHOICES # noqa - INITIAL = 'initial' - INITIAL_CHOICE = (INITIAL, _('initial')) - STATUS_CHOICES = (INITIAL_CHOICE,) + STATUS_CHOICES extraction_order = models.ForeignKey('excerptexport.ExtractionOrder', related_name='exports', verbose_name=_('extraction order'), on_delete=models.CASCADE) file_format = models.CharField(choices=output_format.CHOICES, verbose_name=_('file format / data format'), max_length=10) conversion_service_job_id = models.IntegerField(verbose_name=_('conversion service job ID'), null=True) - status = models.CharField(_('job status'), choices=STATUS_CHOICES, default=INITIAL, max_length=20) + status = models.CharField(_('job status'), choices=status.CHOICES, default=None, max_length=20, null=True) finished_at = models.DateTimeField(_('finished at'), default=None, blank=True, editable=False, null=True) def delete(self, *args, **kwargs): @@ -81,9 +77,9 @@ def status_update_url(self): return reverse('job_progress:tracker', kwargs=dict(export_id=self.id)) def set_and_handle_new_status(self, new_status, *, incoming_request): - assert new_status in dict(self.STATUS_CHOICES) + assert new_status in dict(status.CHOICES) or new_status is None if self.status == new_status and self.update_is_overdue: - new_status = self.FAILED + new_status = status.FAILED if self.status != new_status: self.status = new_status @@ -100,9 +96,9 @@ def _handle_changed_status(self, *, incoming_request): from osmaxx.utils.shortcuts import Emissary emissary = Emissary(recipient=self.extraction_order.orderer) status_changed_message = self._get_export_status_changed_message() - if self.status == self.FAILED: + if self.status == status.FAILED: emissary.error(status_changed_message) - elif self.status == self.FINISHED: + elif self.status == status.FINISHED: from osmaxx.api_client.conversion_api_client import ResultFileNotAvailableError try: self._fetch_result_file() @@ -160,7 +156,7 @@ def result_file_available_until(self): @property def is_status_final(self): - return self.status in self.FINAL_STATUSES + return self.status in status.FINAL_STATUSES @property def can_be_deleted(self): @@ -170,7 +166,7 @@ def can_be_deleted(self): def is_running(self): if self.update_is_overdue: now = timezone.now() - self.status = self.FAILED + self.status = status.FAILED self.finished_at = now self.save() return not self.is_status_final @@ -185,11 +181,11 @@ def css_status_class(self): default_class = 'default' status_map = { - self.RECEIVED: 'info', - self.QUEUED: 'info', - self.FINISHED: 'success', - self.FAILED: 'danger', - self.STARTED: 'info', - self.DEFERRED: 'default', + status.RECEIVED: 'info', + status.QUEUED: 'info', + status.FINISHED: 'success', + status.FAILED: 'danger', + status.STARTED: 'info', + status.DEFERRED: 'default', } return status_map.get(self.status, default_class) diff --git a/osmaxx/excerptexport/views.py b/osmaxx/excerptexport/views.py index e9e219d47..a5b484391 100644 --- a/osmaxx/excerptexport/views.py +++ b/osmaxx/excerptexport/views.py @@ -14,7 +14,7 @@ from django.views.generic.list import ListView from osmaxx.contrib.auth.frontend_permissions import EmailRequiredMixin -from osmaxx.conversion.constants import statuses +from osmaxx.conversion import status from osmaxx.excerptexport.forms import ExcerptForm, ExistingForm from osmaxx.excerptexport.models import Excerpt from osmaxx.excerptexport.models import ExtractionOrder @@ -70,7 +70,7 @@ def get_object(self, queryset=None): class ExportsListMixin: - _filterable_statuses = frozenset({statuses.FINISHED, statuses.FAILED}) + _filterable_statuses = frozenset({status.FINISHED, status.FAILED}) @property def excerpt_ids(self): @@ -85,7 +85,7 @@ def excerpt_ids(self): @property def status_choices(self): - return [choice for choice in Export.STATUS_CHOICES if choice[0] in self._filterable_statuses] + return [choice for choice in status.CHOICES if choice[0] in self._filterable_statuses] def get_user_exports(self): return self._filter_exports( diff --git a/osmaxx/job_progress/middleware.py b/osmaxx/job_progress/middleware.py index b527ba3bb..caa8915cd 100644 --- a/osmaxx/job_progress/middleware.py +++ b/osmaxx/job_progress/middleware.py @@ -5,7 +5,7 @@ from requests import HTTPError from osmaxx.api_client import ConversionApiClient -from osmaxx.conversion.constants.statuses import FINAL_STATUSES, FAILED +from osmaxx.conversion import status from osmaxx.excerptexport.models import Export from osmaxx.utils.shortcuts import get_cached_or_set @@ -34,10 +34,10 @@ def process_request(self, request): def handle_unsent_exports(user): for export in Export.objects.\ - exclude(status__in=FINAL_STATUSES).\ + exclude(status__in=status.FINAL_STATUSES).\ filter(extraction_order__orderer=user, conversion_service_job_id__isnull=True): if export.update_is_overdue: - export.status = export.FAILED + export.status = status.FAILED export.save() @@ -49,7 +49,7 @@ def update_exports_of_request_user(request): handle_unsent_exports(user=current_user) pending_exports = Export.objects.\ - exclude(status__in=FINAL_STATUSES).\ + exclude(status__in=status.FINAL_STATUSES).\ filter(extraction_order__orderer=current_user, conversion_service_job_id__isnull=False) for export in pending_exports: try: @@ -57,7 +57,7 @@ def update_exports_of_request_user(request): except HTTPError as e: if e.response.status_code == requests.codes['not_found']: logger.exception("Export #%s doesn't exist on the conversion service.", export.id) - export.status = FAILED + export.status = status.FAILED export.save() else: logger.exception("Failed to update status of pending export #%s.", export.id) diff --git a/osmaxx/job_progress/templates/job_progress/messages/export_status_changed.unsave_text b/osmaxx/job_progress/templates/job_progress/messages/export_status_changed.unsave_text index 852fd4643..504f0385f 100644 --- a/osmaxx/job_progress/templates/job_progress/messages/export_status_changed.unsave_text +++ b/osmaxx/job_progress/templates/job_progress/messages/export_status_changed.unsave_text @@ -1,3 +1,3 @@ {% autoescape off %} -Export #{{ export.id }} "{{ export.extraction_order.excerpt_name }}" to {{ export.get_file_format_display }} has {% if not export.is_status_final %}been {% endif %}{{ export.status }}.{% if export.status == export.STARTED %} Exporting will take around 30 minutes.{% endif %} +Export #{{ export.id }} "{{ export.extraction_order.excerpt_name }}" to {{ export.get_file_format_display }} has {% if not export.is_status_final %}been {% endif %}{{ export.status }}.{% if export.status == 'started' %} Exporting will take around 30 minutes.{% endif %} {% endautoescape %} diff --git a/tests/conversion/conftest.py b/tests/conversion/conftest.py index 1d7b13940..3d210ac9d 100644 --- a/tests/conversion/conftest.py +++ b/tests/conversion/conftest.py @@ -5,10 +5,9 @@ import pytest from django.conf import settings -from osmaxx.conversion import output_format +from osmaxx.conversion import output_format, status from osmaxx.conversion.converters.converter_gis import detail_levels from osmaxx.conversion.constants import coordinate_reference_systems as crs -from osmaxx.conversion.constants.statuses import STARTED, FAILED, FINISHED format_list = output_format.DEFINITIONS.keys() @@ -116,20 +115,20 @@ def conversion_job(conversion_parametrization, server_url): @pytest.fixture def started_conversion_job(conversion_parametrization, server_url, fake_rq_id): from osmaxx.conversion.models import Job - return Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=STARTED) + return Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=status.STARTED) @pytest.fixture def failed_conversion_job(conversion_parametrization, server_url, fake_rq_id): from osmaxx.conversion.models import Job - return Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=FAILED) + return Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=status.FAILED) @pytest.fixture def finished_conversion_job(request, conversion_parametrization, server_url, fake_rq_id, empty_zip): from osmaxx.conversion.models import Job - conversion_job = Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=FAILED) - conversion_job.status = FINISHED + conversion_job = Job.objects.create(own_base_url=server_url, parametrization=conversion_parametrization, rq_job_id=fake_rq_id, status=status.FAILED) + conversion_job.status = status.FINISHED from osmaxx.conversion.management.commands.result_harvester import add_file_to_job empty_zip_path = add_file_to_job(conversion_job=conversion_job, result_zip_file=empty_zip.name) diff --git a/tests/conversion/management/commands/result_harvester_test.py b/tests/conversion/management/commands/result_harvester_test.py index 342babc78..6f0d26667 100644 --- a/tests/conversion/management/commands/result_harvester_test.py +++ b/tests/conversion/management/commands/result_harvester_test.py @@ -3,7 +3,7 @@ import pytest -from osmaxx.conversion.constants.statuses import STARTED +from osmaxx.conversion import status @pytest.fixture @@ -12,7 +12,7 @@ def queue(fake_rq_id): Job = namedtuple('Job', ['status']) def fetch_job(job_id): - job = Job(status=STARTED) + job = Job(status=status.STARTED) return job queue = Queue(job_ids=[str(fake_rq_id)], fetch_job=fetch_job) return queue diff --git a/tests/conversion/model_test.py b/tests/conversion/model_test.py index 9be5de96f..9dab96fda 100644 --- a/tests/conversion/model_test.py +++ b/tests/conversion/model_test.py @@ -2,19 +2,19 @@ import pytest -from osmaxx.conversion.constants.statuses import STARTED, FAILED, FINISHED +from osmaxx.conversion import status @pytest.mark.django_db() def test_job_statuses_for_jobs(started_conversion_job, failed_conversion_job, finished_conversion_job): - assert started_conversion_job.status == STARTED - assert failed_conversion_job.status == FAILED - assert finished_conversion_job.status == FINISHED + assert started_conversion_job.status == status.STARTED + assert failed_conversion_job.status == status.FAILED + assert finished_conversion_job.status == status.FINISHED @pytest.mark.django_db() def test_job_removes_file_when_deleted(finished_conversion_job): - assert finished_conversion_job.status == FINISHED + assert finished_conversion_job.status == status.FINISHED file_path = finished_conversion_job.resulting_file.path assert file_path is not None assert os.path.exists(file_path) diff --git a/tests/conversion/view_test.py b/tests/conversion/view_test.py index 73548e999..0c1982a77 100644 --- a/tests/conversion/view_test.py +++ b/tests/conversion/view_test.py @@ -1,7 +1,7 @@ import pytest from rest_framework.reverse import reverse -from osmaxx.conversion.constants.statuses import RECEIVED +from osmaxx.conversion import status authenticated_access_urls = [ reverse('clipping_area-list'), @@ -85,7 +85,7 @@ def test_conversion_job_detail_access_success(authenticated_api_client, conversi assert data['id'] == conversion_job.id assert data['callback_url'] == conversion_job.callback_url assert data['parametrization'] == conversion_parametrization.id - assert data['status'] == RECEIVED + assert data['status'] == status.RECEIVED assert data['resulting_file_path'] is None diff --git a/tests/excerptexport/middleware/test_update_exports_of_request_user.py b/tests/excerptexport/middleware/test_update_exports_of_request_user.py index 75b91171e..054fa9896 100644 --- a/tests/excerptexport/middleware/test_update_exports_of_request_user.py +++ b/tests/excerptexport/middleware/test_update_exports_of_request_user.py @@ -2,6 +2,7 @@ import requests from osmaxx.api_client import ConversionApiClient +from osmaxx.conversion import status @pytest.fixture @@ -22,14 +23,14 @@ def side_effect_function(*args, **kwargs): with mocker.patch.object(ConversionApiClient, 'authorized_get'): with mocker.patch('osmaxx.job_progress.middleware.update_export_if_stale', side_effect=side_effect_function): from osmaxx.job_progress.middleware import update_exports_of_request_user - assert export_with_job.status == export_with_job.INITIAL + assert export_with_job.status is None http_request_mock = rf.get('/') http_request_mock.user = user update_exports_of_request_user(http_request_mock) export_with_job.refresh_from_db() - assert export_with_job.status == export_with_job.FAILED + assert export_with_job.status == status.FAILED def test_update_exports_of_request_user_does_not_change_status_when_exception_occurs(rf, mocker, export_with_job, user): @@ -40,7 +41,7 @@ def side_effect_function(*args, **kwargs): with mocker.patch('osmaxx.job_progress.middleware.update_export_if_stale', side_effect=side_effect_function): from osmaxx.job_progress.middleware import update_exports_of_request_user - assert export_with_job.status == export_with_job.INITIAL + assert export_with_job.status is None http_request_mock = rf.get('/') http_request_mock.user = user @@ -48,7 +49,7 @@ def side_effect_function(*args, **kwargs): update_exports_of_request_user(http_request_mock) export_with_job.refresh_from_db() - assert export_with_job.status == export_with_job.INITIAL + assert export_with_job.status is None def test_update_exports_of_request_user_sets_export_to_failed_if_status_is_overdue(rf, mocker, export, user): @@ -70,11 +71,11 @@ def side_effect_function(*args, **kwargs): with mocker.patch.object(ConversionApiClient, 'authorized_get'): with mocker.patch('osmaxx.job_progress.middleware.update_export_if_stale', side_effect=side_effect_function): from osmaxx.job_progress.middleware import update_exports_of_request_user - assert export.status == export.INITIAL + assert export.status is None http_request_mock = rf.get('/') http_request_mock.user = user update_exports_of_request_user(http_request_mock) export.refresh_from_db() - assert export.status == export.FAILED + assert export.status == status.FAILED diff --git a/tests/excerptexport/models/test_export_model.py b/tests/excerptexport/models/test_export_model.py index 716a1a234..c8404778f 100644 --- a/tests/excerptexport/models/test_export_model.py +++ b/tests/excerptexport/models/test_export_model.py @@ -4,6 +4,7 @@ from django.utils import timezone +from osmaxx.conversion import status from osmaxx.excerptexport.models.export import TimeStampModelMixin from osmaxx.excerptexport._settings import EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA @@ -59,19 +60,19 @@ def test_saved_again_export_doesnt_change_finished(export): def test_set_and_handle_new_status_when_status_outdated_is_set_to_failed(db, mocker, export_stale_status): mocker.patch.object(export_stale_status, '_handle_changed_status') export_stale_status.set_and_handle_new_status(export_stale_status.status, incoming_request=None) - assert export_stale_status.status == export_stale_status.FAILED + assert export_stale_status.status == status.FAILED def test_set_and_handle_new_status_when_not_outdated_isnt_marked_as_failed(db, mocker, export): mocker.patch.object(export, '_handle_changed_status') export.set_and_handle_new_status(export.status, incoming_request=None) - assert export.status != export.FAILED + assert export.status != status.FAILED def test_set_and_handle_new_status_when_outdated_isnt_marked_as_failed_when_status_is_failed(db, mocker, export_stale_status): - export_stale_status.status = export_stale_status.FINISHED + export_stale_status.status = status.FINISHED export_stale_status.save() mocker.patch.object(export_stale_status, '_handle_changed_status') export_stale_status.set_and_handle_new_status(export_stale_status.status, incoming_request=None) - assert export_stale_status.status == export_stale_status.FINISHED + assert export_stale_status.status == status.FINISHED diff --git a/tests/excerptexport/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index c08002d90..6b7fd33b5 100644 --- a/tests/excerptexport/test_conversion_api_client.py +++ b/tests/excerptexport/test_conversion_api_client.py @@ -8,9 +8,8 @@ from requests import HTTPError from rest_framework.reverse import reverse -from osmaxx.conversion import output_format +from osmaxx.conversion import output_format, status from osmaxx.api_client import ConversionApiClient, API_client -from osmaxx.conversion.constants.statuses import RECEIVED from osmaxx.excerptexport.models import Excerpt, ExtractionOrder from osmaxx.job_progress.views import tracker from tests.test_helpers import vcr_explicit_path as vcr @@ -88,7 +87,7 @@ def test_extraction_order_forward_to_conversion_service( rf, mocker, excerpt, extraction_order, bounding_geometry, the_host): mocker.patch.object( ConversionApiClient, 'create_job', - side_effect=[{'id': 5, 'status': RECEIVED}, {'id': 23, 'status': RECEIVED}], + side_effect=[{'id': 5, 'status': status.RECEIVED}, {'id': 23, 'status': status.RECEIVED}], ) mocker.patch.object( ConversionApiClient, 'create_parametrization', @@ -158,17 +157,17 @@ def test_create_jobs_for_extraction_order(extraction_order, excerpt_request): spatialite_export = extraction_order.exports.get(file_format=output_format.SPATIALITE) assert fgdb_export.conversion_service_job_id is None - assert fgdb_export.status == fgdb_export.INITIAL + assert fgdb_export.status is None assert spatialite_export.conversion_service_job_id is None - assert spatialite_export.status == spatialite_export.INITIAL + assert spatialite_export.status is None jobs_json = extraction_order.forward_to_conversion_service(incoming_request=(excerpt_request)) fgdb_export.refresh_from_db() spatialite_export.refresh_from_db() - assert fgdb_export.status == RECEIVED - assert spatialite_export.status == RECEIVED + assert fgdb_export.status == status.RECEIVED + assert spatialite_export.status == status.RECEIVED assert len(jobs_json) == 2 for job_json in jobs_json: expected_keys_in_response = ['callback_url', 'rq_job_id', 'id', 'status', 'resulting_file', 'parametrization'] @@ -201,7 +200,7 @@ def test_create_job_for_export(extraction_order, job_progress_request, clipping_ assert job_json['callback_url'] == "http://the-host.example.com/job_progress/tracker/23/" assert job_json['rq_job_id'] == "6692fa44-cc19-4252-88ae-8687496da421" assert job_json['id'] == 29 - assert job_json['status'] == RECEIVED + assert job_json['status'] == status.RECEIVED assert job_json['resulting_file'] is None assert job_json['parametrization'] == 38 diff --git a/tests/excerptexport/test_models.py b/tests/excerptexport/test_models.py index 59c22f9da..9a977e0c8 100644 --- a/tests/excerptexport/test_models.py +++ b/tests/excerptexport/test_models.py @@ -3,8 +3,7 @@ from django.contrib.gis import geos from hamcrest import assert_that, contains_inanyorder as contains_in_any_order -from osmaxx.conversion import output_format -from osmaxx.conversion.constants.statuses import FINISHED +from osmaxx.conversion import output_format, status from osmaxx.excerptexport import models @@ -63,6 +62,6 @@ def test_retrieve_extraction_configuration_on_saved_extraction_configuration(sel def test_export_get_export_status_changed_message_does_not_html_escape_format_description(): excerpt = models.Excerpt(name='Obersee') extraction_order = models.ExtractionOrder(excerpt=excerpt) - export = models.Export(id=5, status=FINISHED, extraction_order=extraction_order, file_format=output_format.GARMIN) + export = models.Export(id=5, status=status.FINISHED, extraction_order=extraction_order, file_format=output_format.GARMIN) assert export._get_export_status_changed_message() == \ 'Export #5 "Obersee" to Garmin navigation & map data has finished.' diff --git a/tests/excerptexport/views/test_excerpt_delete_view.py b/tests/excerptexport/views/test_excerpt_delete_view.py index 5bbd78f32..1a0c8cfd0 100644 --- a/tests/excerptexport/views/test_excerpt_delete_view.py +++ b/tests/excerptexport/views/test_excerpt_delete_view.py @@ -28,7 +28,7 @@ def test_delete_fails_when_exports_in_progress(authorized_client, user, extracti extraction_order.excerpt = excerpt extraction_order.save() Export.objects.create( - extraction_order=extraction_order, file_format=output_format.FGDB, conversion_service_job_id=None, status=Export.INITIAL, finished_at=None + extraction_order=extraction_order, file_format=output_format.FGDB, conversion_service_job_id=None, status=None, finished_at=None ) assert excerpt.has_running_exports diff --git a/tests/job_progress/test_job_progress.py b/tests/job_progress/test_job_progress.py index 387ac50de..3836c0830 100644 --- a/tests/job_progress/test_job_progress.py +++ b/tests/job_progress/test_job_progress.py @@ -13,7 +13,7 @@ from osmaxx import excerptexport from osmaxx.api_client.conversion_api_client import ConversionApiClient -from osmaxx.conversion.constants.statuses import STARTED, QUEUED, FINISHED, FAILED +from osmaxx.conversion import status from osmaxx.excerptexport.models.excerpt import Excerpt from osmaxx.excerptexport.models.export import Export from osmaxx.excerptexport.models.extraction_order import ExtractionOrder @@ -68,7 +68,7 @@ def test_calling_tracker_with_payload_indicating_queued_updates_export_status(se views.tracker(request, export_id=str(self.export.id)) self.export.refresh_from_db() - self.assertEqual(self.export.status, QUEUED) + self.assertEqual(self.export.status, status.QUEUED) def test_calling_tracker_with_payload_indicating_started_updates_export_status(self, *args): factory = APIRequestFactory() @@ -79,7 +79,7 @@ def test_calling_tracker_with_payload_indicating_started_updates_export_status(s views.tracker(request, export_id=str(self.export.id)) self.export.refresh_from_db() - self.assertEqual(self.export.status, STARTED) + self.assertEqual(self.export.status, status.STARTED) @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_queued_informs_user( @@ -228,7 +228,7 @@ def test_calling_tracker_with_payload_indicating_final_status_for_only_remaining 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.status = status.FAILED other_export.save() emissary_mock = emissary_class_mock() factory = APIRequestFactory() @@ -355,9 +355,9 @@ def setUp(self): for i in range(4): own_order.exports.create(file_format='fgdb') for i in range(8): - own_order.exports.create(file_format='fgdb', conversion_service_job_id=1, status=FINISHED) + own_order.exports.create(file_format='fgdb', conversion_service_job_id=1, status=status.FINISHED) for i in range(16): - own_order.exports.create(file_format='fgdb', conversion_service_job_id=1, status=FAILED) + own_order.exports.create(file_format='fgdb', conversion_service_job_id=1, status=status.FAILED) for i in range(32): foreign_order.exports.create(file_format='fgdb', conversion_service_job_id=1) self.client.login(username='user', password='pw')