From 04da18d5f63b9c4f22ec22c8cea8dbeb3a56d084 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Tue, 9 May 2017 15:06:44 +0200 Subject: [PATCH 1/7] refactoring: #845 rename module "statuses" to "status" --- osmaxx/conversion/constants/{statuses.py => status.py} | 0 osmaxx/conversion/management/commands/result_harvester.py | 2 +- osmaxx/conversion/models.py | 2 +- osmaxx/excerptexport/models/export.py | 2 +- osmaxx/excerptexport/views.py | 4 ++-- osmaxx/job_progress/middleware.py | 2 +- tests/conversion/conftest.py | 2 +- tests/conversion/management/commands/result_harvester_test.py | 2 +- tests/conversion/model_test.py | 2 +- tests/conversion/view_test.py | 2 +- tests/excerptexport/test_conversion_api_client.py | 2 +- tests/excerptexport/test_models.py | 2 +- tests/job_progress/test_job_progress.py | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) rename osmaxx/conversion/constants/{statuses.py => status.py} (100%) diff --git a/osmaxx/conversion/constants/statuses.py b/osmaxx/conversion/constants/status.py similarity index 100% rename from osmaxx/conversion/constants/statuses.py rename to osmaxx/conversion/constants/status.py diff --git a/osmaxx/conversion/management/commands/result_harvester.py b/osmaxx/conversion/management/commands/result_harvester.py index 59997ab06..aac86ba54 100644 --- a/osmaxx/conversion/management/commands/result_harvester.py +++ b/osmaxx/conversion/management/commands/result_harvester.py @@ -12,7 +12,7 @@ from osmaxx.conversion import models as conversion_models from osmaxx.conversion._settings import CONVERSION_SETTINGS -from osmaxx.conversion.constants.statuses import FINAL_STATUSES, FINISHED, FAILED +from osmaxx.conversion.constants.status import FINAL_STATUSES, FINISHED, FAILED logging.basicConfig() logger = logging.getLogger(__name__) diff --git a/osmaxx/conversion/models.py b/osmaxx/conversion/models.py index bd3165559..ed5a4ca32 100644 --- a/osmaxx/conversion/models.py +++ b/osmaxx/conversion/models.py @@ -12,7 +12,7 @@ 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.formats import FORMAT_CHOICES -from osmaxx.conversion.constants.statuses import STATUS_CHOICES, RECEIVED +from osmaxx.conversion.constants.status import STATUS_CHOICES, RECEIVED def job_directory_path(instance, filename): diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index 18aca9415..8c09e2db9 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -41,7 +41,7 @@ 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 + from osmaxx.conversion.constants.status import RECEIVED, QUEUED, FINISHED, FAILED, STARTED, DEFERRED, FINAL_STATUSES, STATUS_CHOICES # noqa INITIAL = 'initial' INITIAL_CHOICE = (INITIAL, _('initial')) STATUS_CHOICES = (INITIAL_CHOICE,) + STATUS_CHOICES diff --git a/osmaxx/excerptexport/views.py b/osmaxx/excerptexport/views.py index e9e219d47..eec0f3579 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.constants 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): diff --git a/osmaxx/job_progress/middleware.py b/osmaxx/job_progress/middleware.py index b527ba3bb..86419a8c4 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.constants.status import FINAL_STATUSES, FAILED from osmaxx.excerptexport.models import Export from osmaxx.utils.shortcuts import get_cached_or_set diff --git a/tests/conversion/conftest.py b/tests/conversion/conftest.py index e5146e18a..787a5167a 100644 --- a/tests/conversion/conftest.py +++ b/tests/conversion/conftest.py @@ -8,7 +8,7 @@ import osmaxx.conversion.constants.formats 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 +from osmaxx.conversion.constants.status import STARTED, FAILED, FINISHED format_list = osmaxx.conversion.constants.formats.FORMAT_DEFINITIONS.keys() diff --git a/tests/conversion/management/commands/result_harvester_test.py b/tests/conversion/management/commands/result_harvester_test.py index 342babc78..b2b1cc9e7 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.constants.status import STARTED @pytest.fixture diff --git a/tests/conversion/model_test.py b/tests/conversion/model_test.py index 9be5de96f..ea3a1835d 100644 --- a/tests/conversion/model_test.py +++ b/tests/conversion/model_test.py @@ -2,7 +2,7 @@ import pytest -from osmaxx.conversion.constants.statuses import STARTED, FAILED, FINISHED +from osmaxx.conversion.constants.status import STARTED, FAILED, FINISHED @pytest.mark.django_db() diff --git a/tests/conversion/view_test.py b/tests/conversion/view_test.py index 73548e999..117408d47 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.constants.status import RECEIVED authenticated_access_urls = [ reverse('clipping_area-list'), diff --git a/tests/excerptexport/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index 14838715a..0c8ade1e2 100644 --- a/tests/excerptexport/test_conversion_api_client.py +++ b/tests/excerptexport/test_conversion_api_client.py @@ -10,7 +10,7 @@ from osmaxx.api_client import ConversionApiClient, API_client from osmaxx.conversion.constants.formats import FGDB, SPATIALITE -from osmaxx.conversion.constants.statuses import RECEIVED +from osmaxx.conversion.constants.status 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 diff --git a/tests/excerptexport/test_models.py b/tests/excerptexport/test_models.py index 74b8a223d..73cf4e531 100644 --- a/tests/excerptexport/test_models.py +++ b/tests/excerptexport/test_models.py @@ -4,7 +4,7 @@ from hamcrest import assert_that, contains_inanyorder as contains_in_any_order from osmaxx.conversion.constants.formats import GARMIN -from osmaxx.conversion.constants.statuses import FINISHED +from osmaxx.conversion.constants.status import FINISHED from osmaxx.excerptexport import models diff --git a/tests/job_progress/test_job_progress.py b/tests/job_progress/test_job_progress.py index 387ac50de..1c9251624 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.constants.status import STARTED, QUEUED, FINISHED, FAILED from osmaxx.excerptexport.models.excerpt import Excerpt from osmaxx.excerptexport.models.export import Export from osmaxx.excerptexport.models.extraction_order import ExtractionOrder From 2229d253978fb808a89c2514b95620287d396ba9 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Thu, 11 May 2017 16:51:49 +0200 Subject: [PATCH 2/7] #845 replace status INITIAL by None/NULL --- .../migrations/0058_auto_20170511_1639.py | 20 +++++++++++++++++++ osmaxx/excerptexport/models/export.py | 7 ++----- .../test_update_exports_of_request_user.py | 8 ++++---- .../test_conversion_api_client.py | 4 ++-- .../views/test_excerpt_delete_view.py | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 osmaxx/excerptexport/migrations/0058_auto_20170511_1639.py 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 ab6e7a7d4..a8d0d6975 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -42,15 +42,12 @@ class Export(TimeStampModelMixin, models.Model): - the actual export to one specific GIS or navigation file format with one specific set of parameters """ from osmaxx.conversion.constants.status 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,7 +78,7 @@ 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(self.STATUS_CHOICES) or new_status is None if self.status == new_status and self.update_is_overdue: new_status = self.FAILED 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..3546dfa91 100644 --- a/tests/excerptexport/middleware/test_update_exports_of_request_user.py +++ b/tests/excerptexport/middleware/test_update_exports_of_request_user.py @@ -22,7 +22,7 @@ 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 @@ -40,7 +40,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 +48,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,7 +70,7 @@ 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 diff --git a/tests/excerptexport/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index 76dc414b1..32de57382 100644 --- a/tests/excerptexport/test_conversion_api_client.py +++ b/tests/excerptexport/test_conversion_api_client.py @@ -158,9 +158,9 @@ 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)) 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 From e58991b53720a4ca59db57730b5a4fa91869a75d Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 12 May 2017 11:10:14 +0200 Subject: [PATCH 3/7] refactoring: #845 don't expose status constants via Export model class --- osmaxx/excerptexport/models/export.py | 28 +++++++++---------- osmaxx/excerptexport/views.py | 2 +- osmaxx/job_progress/middleware.py | 2 +- .../export_status_changed.unsave_text | 2 +- .../test_update_exports_of_request_user.py | 5 ++-- .../excerptexport/models/test_export_model.py | 9 +++--- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index a8d0d6975..2854292d1 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -9,6 +9,7 @@ from rest_framework.reverse import reverse from osmaxx.conversion import output_format +from osmaxx.conversion.constants import status from osmaxx.excerptexport._settings import RESULT_FILE_AVAILABILITY_DURATION, EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA logger = logging.getLogger(__name__) @@ -41,13 +42,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.status import RECEIVED, QUEUED, FINISHED, FAILED, STARTED, DEFERRED, FINAL_STATUSES, STATUS_CHOICES # noqa 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=None, max_length=20, null=True) + status = models.CharField(_('job status'), choices=status.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): @@ -78,9 +78,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) or new_status is None + assert new_status in dict(status.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 @@ -97,9 +97,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() @@ -157,7 +157,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): @@ -167,7 +167,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 @@ -182,11 +182,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 eec0f3579..edd0ec7ff 100644 --- a/osmaxx/excerptexport/views.py +++ b/osmaxx/excerptexport/views.py @@ -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.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 86419a8c4..07517ba58 100644 --- a/osmaxx/job_progress/middleware.py +++ b/osmaxx/job_progress/middleware.py @@ -37,7 +37,7 @@ def handle_unsent_exports(user): exclude(status__in=FINAL_STATUSES).\ filter(extraction_order__orderer=user, conversion_service_job_id__isnull=True): if export.update_is_overdue: - export.status = export.FAILED + export.status = FAILED export.save() 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/excerptexport/middleware/test_update_exports_of_request_user.py b/tests/excerptexport/middleware/test_update_exports_of_request_user.py index 3546dfa91..dae88cd1d 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.constants import status @pytest.fixture @@ -29,7 +30,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.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): @@ -77,4 +78,4 @@ def side_effect_function(*args, **kwargs): 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..5b0ec0ac9 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.constants 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 From afa7e96f55c2ba41856005540dc85aa95f832375 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 12 May 2017 13:56:37 +0200 Subject: [PATCH 4/7] #845 import module "status" instead of its members --- .../management/commands/result_harvester.py | 12 ++++++------ osmaxx/conversion/models.py | 4 ++-- osmaxx/job_progress/middleware.py | 10 +++++----- tests/conversion/conftest.py | 10 +++++----- .../management/commands/result_harvester_test.py | 4 ++-- tests/conversion/model_test.py | 10 +++++----- tests/conversion/view_test.py | 4 ++-- tests/excerptexport/test_conversion_api_client.py | 10 +++++----- tests/excerptexport/test_models.py | 4 ++-- tests/job_progress/test_job_progress.py | 12 ++++++------ 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/osmaxx/conversion/management/commands/result_harvester.py b/osmaxx/conversion/management/commands/result_harvester.py index aac86ba54..0f410173d 100644 --- a/osmaxx/conversion/management/commands/result_harvester.py +++ b/osmaxx/conversion/management/commands/result_harvester.py @@ -12,7 +12,7 @@ from osmaxx.conversion import models as conversion_models from osmaxx.conversion._settings import CONVERSION_SETTINGS -from osmaxx.conversion.constants.status import FINAL_STATUSES, FINISHED, FAILED +from osmaxx.conversion.constants import status logging.basicConfig() logger = logging.getLogger(__name__) @@ -42,7 +42,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 +67,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 +75,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 +136,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 4e49a9532..ae2a59a09 100644 --- a/osmaxx/conversion/models.py +++ b/osmaxx/conversion/models.py @@ -12,7 +12,7 @@ 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.status import STATUS_CHOICES, RECEIVED +from osmaxx.conversion.constants import status def job_directory_path(instance, filename): @@ -40,7 +40,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.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/job_progress/middleware.py b/osmaxx/job_progress/middleware.py index 07517ba58..e1f698f28 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.status import FINAL_STATUSES, FAILED +from osmaxx.conversion.constants 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 = 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/tests/conversion/conftest.py b/tests/conversion/conftest.py index 0e70e0881..e49bce352 100644 --- a/tests/conversion/conftest.py +++ b/tests/conversion/conftest.py @@ -8,7 +8,7 @@ from osmaxx.conversion import output_format from osmaxx.conversion.converters.converter_gis import detail_levels from osmaxx.conversion.constants import coordinate_reference_systems as crs -from osmaxx.conversion.constants.status import STARTED, FAILED, FINISHED +from osmaxx.conversion.constants import status format_list = output_format.DEFINITIONS.keys() @@ -116,20 +116,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 b2b1cc9e7..b79363401 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.status import STARTED +from osmaxx.conversion.constants 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 ea3a1835d..b098762bb 100644 --- a/tests/conversion/model_test.py +++ b/tests/conversion/model_test.py @@ -2,19 +2,19 @@ import pytest -from osmaxx.conversion.constants.status import STARTED, FAILED, FINISHED +from osmaxx.conversion.constants 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 117408d47..8ebfb1585 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.status import RECEIVED +from osmaxx.conversion.constants 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/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index 32de57382..cd0736123 100644 --- a/tests/excerptexport/test_conversion_api_client.py +++ b/tests/excerptexport/test_conversion_api_client.py @@ -10,7 +10,7 @@ from osmaxx.conversion import output_format from osmaxx.api_client import ConversionApiClient, API_client -from osmaxx.conversion.constants.status import RECEIVED +from osmaxx.conversion.constants import status 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 +88,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', @@ -167,8 +167,8 @@ def test_create_jobs_for_extraction_order(extraction_order, 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 +201,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 6e4c33360..a66a2caac 100644 --- a/tests/excerptexport/test_models.py +++ b/tests/excerptexport/test_models.py @@ -4,7 +4,7 @@ from hamcrest import assert_that, contains_inanyorder as contains_in_any_order from osmaxx.conversion import output_format -from osmaxx.conversion.constants.status import FINISHED +from osmaxx.conversion.constants import status from osmaxx.excerptexport import models @@ -63,6 +63,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/job_progress/test_job_progress.py b/tests/job_progress/test_job_progress.py index 1c9251624..8e4948ca3 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.status import STARTED, QUEUED, FINISHED, FAILED +from osmaxx.conversion.constants 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') From d8560d989a446cd1d8e8253c386fc2087a28709b Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 12 May 2017 13:58:27 +0200 Subject: [PATCH 5/7] refactoring: #845 rename constant "status.STATUS_CHOICES" to "status.CHOICES" --- osmaxx/conversion/constants/status.py | 2 +- osmaxx/conversion/models.py | 2 +- osmaxx/excerptexport/models/export.py | 4 ++-- osmaxx/excerptexport/views.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osmaxx/conversion/constants/status.py b/osmaxx/conversion/constants/status.py index 003ce006a..60ff19089 100644 --- a/osmaxx/conversion/constants/status.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/models.py b/osmaxx/conversion/models.py index ae2a59a09..8e899d723 100644 --- a/osmaxx/conversion/models.py +++ b/osmaxx/conversion/models.py @@ -40,7 +40,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.STATUS_CHOICES, default=status.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/models/export.py b/osmaxx/excerptexport/models/export.py index 2854292d1..c71eb7254 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -47,7 +47,7 @@ class Export(TimeStampModelMixin, models.Model): 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.STATUS_CHOICES, default=None, max_length=20, null=True) + 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): @@ -78,7 +78,7 @@ 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(status.STATUS_CHOICES) or new_status is None + assert new_status in dict(status.CHOICES) or new_status is None if self.status == new_status and self.update_is_overdue: new_status = status.FAILED diff --git a/osmaxx/excerptexport/views.py b/osmaxx/excerptexport/views.py index edd0ec7ff..b93dd092f 100644 --- a/osmaxx/excerptexport/views.py +++ b/osmaxx/excerptexport/views.py @@ -85,7 +85,7 @@ def excerpt_ids(self): @property def status_choices(self): - return [choice for choice in status.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( From e2a518bfe76a3f54586d9832b938c3bf2980a474 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 12 May 2017 14:44:41 +0200 Subject: [PATCH 6/7] refactoring: #845 add and use convenience import for module "status" --- osmaxx/conversion/__init__.py | 4 ++-- osmaxx/conversion/management/commands/result_harvester.py | 2 +- osmaxx/conversion/models.py | 2 +- osmaxx/excerptexport/models/export.py | 2 +- osmaxx/excerptexport/views.py | 2 +- osmaxx/job_progress/middleware.py | 2 +- tests/conversion/conftest.py | 2 +- tests/conversion/management/commands/result_harvester_test.py | 2 +- tests/conversion/model_test.py | 2 +- tests/conversion/view_test.py | 2 +- .../middleware/test_update_exports_of_request_user.py | 2 +- tests/excerptexport/models/test_export_model.py | 2 +- tests/excerptexport/test_conversion_api_client.py | 2 +- tests/excerptexport/test_models.py | 2 +- tests/job_progress/test_job_progress.py | 2 +- 15 files changed, 16 insertions(+), 16 deletions(-) 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/management/commands/result_harvester.py b/osmaxx/conversion/management/commands/result_harvester.py index 0f410173d..68567b19a 100644 --- a/osmaxx/conversion/management/commands/result_harvester.py +++ b/osmaxx/conversion/management/commands/result_harvester.py @@ -12,7 +12,7 @@ from osmaxx.conversion import models as conversion_models from osmaxx.conversion._settings import CONVERSION_SETTINGS -from osmaxx.conversion.constants import status +from osmaxx.conversion import status logging.basicConfig() logger = logging.getLogger(__name__) diff --git a/osmaxx/conversion/models.py b/osmaxx/conversion/models.py index 8e899d723..b6c27a27e 100644 --- a/osmaxx/conversion/models.py +++ b/osmaxx/conversion/models.py @@ -12,7 +12,7 @@ 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 import status +from osmaxx.conversion import status def job_directory_path(instance, filename): diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index c71eb7254..2fc34f197 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -9,7 +9,7 @@ from rest_framework.reverse import reverse from osmaxx.conversion import output_format -from osmaxx.conversion.constants import status +from osmaxx.conversion import status from osmaxx.excerptexport._settings import RESULT_FILE_AVAILABILITY_DURATION, EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA logger = logging.getLogger(__name__) diff --git a/osmaxx/excerptexport/views.py b/osmaxx/excerptexport/views.py index b93dd092f..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 status +from osmaxx.conversion import status from osmaxx.excerptexport.forms import ExcerptForm, ExistingForm from osmaxx.excerptexport.models import Excerpt from osmaxx.excerptexport.models import ExtractionOrder diff --git a/osmaxx/job_progress/middleware.py b/osmaxx/job_progress/middleware.py index e1f698f28..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 import status +from osmaxx.conversion import status from osmaxx.excerptexport.models import Export from osmaxx.utils.shortcuts import get_cached_or_set diff --git a/tests/conversion/conftest.py b/tests/conversion/conftest.py index e49bce352..86617a94d 100644 --- a/tests/conversion/conftest.py +++ b/tests/conversion/conftest.py @@ -8,7 +8,7 @@ from osmaxx.conversion import output_format from osmaxx.conversion.converters.converter_gis import detail_levels from osmaxx.conversion.constants import coordinate_reference_systems as crs -from osmaxx.conversion.constants import status +from osmaxx.conversion import status format_list = output_format.DEFINITIONS.keys() diff --git a/tests/conversion/management/commands/result_harvester_test.py b/tests/conversion/management/commands/result_harvester_test.py index b79363401..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 import status +from osmaxx.conversion import status @pytest.fixture diff --git a/tests/conversion/model_test.py b/tests/conversion/model_test.py index b098762bb..9dab96fda 100644 --- a/tests/conversion/model_test.py +++ b/tests/conversion/model_test.py @@ -2,7 +2,7 @@ import pytest -from osmaxx.conversion.constants import status +from osmaxx.conversion import status @pytest.mark.django_db() diff --git a/tests/conversion/view_test.py b/tests/conversion/view_test.py index 8ebfb1585..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 import status +from osmaxx.conversion import status authenticated_access_urls = [ reverse('clipping_area-list'), 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 dae88cd1d..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,7 +2,7 @@ import requests from osmaxx.api_client import ConversionApiClient -from osmaxx.conversion.constants import status +from osmaxx.conversion import status @pytest.fixture diff --git a/tests/excerptexport/models/test_export_model.py b/tests/excerptexport/models/test_export_model.py index 5b0ec0ac9..c8404778f 100644 --- a/tests/excerptexport/models/test_export_model.py +++ b/tests/excerptexport/models/test_export_model.py @@ -4,7 +4,7 @@ from django.utils import timezone -from osmaxx.conversion.constants import status +from osmaxx.conversion import status from osmaxx.excerptexport.models.export import TimeStampModelMixin from osmaxx.excerptexport._settings import EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA diff --git a/tests/excerptexport/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index cd0736123..b6bbebf17 100644 --- a/tests/excerptexport/test_conversion_api_client.py +++ b/tests/excerptexport/test_conversion_api_client.py @@ -10,7 +10,7 @@ from osmaxx.conversion import output_format from osmaxx.api_client import ConversionApiClient, API_client -from osmaxx.conversion.constants import status +from osmaxx.conversion import status from osmaxx.excerptexport.models import Excerpt, ExtractionOrder from osmaxx.job_progress.views import tracker from tests.test_helpers import vcr_explicit_path as vcr diff --git a/tests/excerptexport/test_models.py b/tests/excerptexport/test_models.py index a66a2caac..3e175a5ee 100644 --- a/tests/excerptexport/test_models.py +++ b/tests/excerptexport/test_models.py @@ -4,7 +4,7 @@ from hamcrest import assert_that, contains_inanyorder as contains_in_any_order from osmaxx.conversion import output_format -from osmaxx.conversion.constants import status +from osmaxx.conversion import status from osmaxx.excerptexport import models diff --git a/tests/job_progress/test_job_progress.py b/tests/job_progress/test_job_progress.py index 8e4948ca3..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 import status +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 From 99f6b1158f921315a357f8adbf4a4604196eafa7 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 12 May 2017 15:41:00 +0200 Subject: [PATCH 7/7] refactoring: #845 (manually) reorganize imports --- osmaxx/conversion/management/commands/result_harvester.py | 3 +-- osmaxx/conversion/models.py | 3 +-- osmaxx/excerptexport/models/export.py | 3 +-- tests/conversion/conftest.py | 3 +-- tests/excerptexport/test_conversion_api_client.py | 3 +-- tests/excerptexport/test_models.py | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/osmaxx/conversion/management/commands/result_harvester.py b/osmaxx/conversion/management/commands/result_harvester.py index 68567b19a..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 import status logging.basicConfig() logger = logging.getLogger(__name__) diff --git a/osmaxx/conversion/models.py b/osmaxx/conversion/models.py index b6c27a27e..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 import status def job_directory_path(instance, filename): diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index 2fc34f197..694daa8ee 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -8,8 +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 status +from osmaxx.conversion import output_format, status from osmaxx.excerptexport._settings import RESULT_FILE_AVAILABILITY_DURATION, EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA logger = logging.getLogger(__name__) diff --git a/tests/conversion/conftest.py b/tests/conversion/conftest.py index 86617a94d..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 import status format_list = output_format.DEFINITIONS.keys() diff --git a/tests/excerptexport/test_conversion_api_client.py b/tests/excerptexport/test_conversion_api_client.py index b6bbebf17..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 import status from osmaxx.excerptexport.models import Excerpt, ExtractionOrder from osmaxx.job_progress.views import tracker from tests.test_helpers import vcr_explicit_path as vcr diff --git a/tests/excerptexport/test_models.py b/tests/excerptexport/test_models.py index 3e175a5ee..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 import status +from osmaxx.conversion import output_format, status from osmaxx.excerptexport import models