From d27a82849cfa8052ca1463c8ead2982e7f71bccd Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 5 May 2017 10:28:57 +0200 Subject: [PATCH 1/4] refactoring: #845 move module dict_helpers to utils package --- osmaxx/excerptexport/forms/excerpt_form.py | 2 +- osmaxx/{utilities => utils}/dict_helpers.py | 0 tests/{utilities => utils}/test_dict_helpers.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename osmaxx/{utilities => utils}/dict_helpers.py (100%) rename tests/{utilities => utils}/test_dict_helpers.py (92%) diff --git a/osmaxx/excerptexport/forms/excerpt_form.py b/osmaxx/excerptexport/forms/excerpt_form.py index 126ca4e7a..6e27e9d15 100644 --- a/osmaxx/excerptexport/forms/excerpt_form.py +++ b/osmaxx/excerptexport/forms/excerpt_form.py @@ -10,7 +10,7 @@ from .order_options_mixin import OrderOptionsMixin from osmaxx.excerptexport.models import Excerpt, ExtractionOrder -from osmaxx.utilities.dict_helpers import select_keys +from osmaxx.utils.dict_helpers import select_keys class ExcerptForm(OrderOptionsMixin, forms.ModelForm): diff --git a/osmaxx/utilities/dict_helpers.py b/osmaxx/utils/dict_helpers.py similarity index 100% rename from osmaxx/utilities/dict_helpers.py rename to osmaxx/utils/dict_helpers.py diff --git a/tests/utilities/test_dict_helpers.py b/tests/utils/test_dict_helpers.py similarity index 92% rename from tests/utilities/test_dict_helpers.py rename to tests/utils/test_dict_helpers.py index b48fc32f8..c18df6954 100644 --- a/tests/utilities/test_dict_helpers.py +++ b/tests/utils/test_dict_helpers.py @@ -1,6 +1,6 @@ from unittest.case import TestCase -from osmaxx.utilities.dict_helpers import are_all_keys_in +from osmaxx.utils.dict_helpers import are_all_keys_in class AreAllKeysInTest(TestCase): From d1a08a59aada4e0df3eecc5dc6f919cc1ed90a7e Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 5 May 2017 11:31:30 +0200 Subject: [PATCH 2/4] refactoring: #845 move module shortcuts to utils package --- osmaxx/excerptexport/models/export.py | 2 +- osmaxx/excerptexport/models/extraction_order.py | 2 +- osmaxx/job_progress/middleware.py | 2 +- osmaxx/locale/en/LC_MESSAGES/django.po | 2 +- osmaxx/{utilities => utils}/shortcuts.py | 0 .../models/test_plain_text_email_rendering.py | 2 +- tests/job_progress/test_job_progress.py | 12 ++++++------ 7 files changed, 11 insertions(+), 11 deletions(-) rename osmaxx/{utilities => utils}/shortcuts.py (100%) diff --git a/osmaxx/excerptexport/models/export.py b/osmaxx/excerptexport/models/export.py index d929fc403..db6b55470 100644 --- a/osmaxx/excerptexport/models/export.py +++ b/osmaxx/excerptexport/models/export.py @@ -97,7 +97,7 @@ def update_is_overdue(self): return (self.updated_at + EXTRACTION_PROCESSING_TIMEOUT_TIMEDELTA) < timezone.now() def _handle_changed_status(self, *, incoming_request): - from osmaxx.utilities.shortcuts import Emissary + 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: diff --git a/osmaxx/excerptexport/models/extraction_order.py b/osmaxx/excerptexport/models/extraction_order.py index 863192169..f08f35936 100644 --- a/osmaxx/excerptexport/models/extraction_order.py +++ b/osmaxx/excerptexport/models/extraction_order.py @@ -74,7 +74,7 @@ def get_absolute_url(self): def send_email_if_all_exports_done(self, incoming_request): if all(export.is_status_final for export in self.exports.all()): - from osmaxx.utilities.shortcuts import Emissary + from osmaxx.utils.shortcuts import Emissary emissary = Emissary(recipient=self.orderer) emissary.inform_mail( subject=self._get_all_exports_done_email_subject(), diff --git a/osmaxx/job_progress/middleware.py b/osmaxx/job_progress/middleware.py index 3c08200bb..54c9120cc 100644 --- a/osmaxx/job_progress/middleware.py +++ b/osmaxx/job_progress/middleware.py @@ -7,7 +7,7 @@ from osmaxx.api_client import ConversionApiClient from osmaxx.conversion_api.statuses import FINAL_STATUSES, FAILED from osmaxx.excerptexport.models import Export -from osmaxx.utilities.shortcuts import get_cached_or_set +from osmaxx.utils.shortcuts import get_cached_or_set logger = logging.getLogger(__name__) diff --git a/osmaxx/locale/en/LC_MESSAGES/django.po b/osmaxx/locale/en/LC_MESSAGES/django.po index 01c86e8e3..d4b73f079 100644 --- a/osmaxx/locale/en/LC_MESSAGES/django.po +++ b/osmaxx/locale/en/LC_MESSAGES/django.po @@ -1124,7 +1124,7 @@ msgstr "" msgid "Rest API" msgstr "" -#: osmaxx/utilities/shortcuts.py:43 +#: osmaxx/utils/shortcuts.py:43 msgid "" "There is no email address assigned to your account. You won't be notified by " "email!" diff --git a/osmaxx/utilities/shortcuts.py b/osmaxx/utils/shortcuts.py similarity index 100% rename from osmaxx/utilities/shortcuts.py rename to osmaxx/utils/shortcuts.py diff --git a/tests/excerptexport/models/test_plain_text_email_rendering.py b/tests/excerptexport/models/test_plain_text_email_rendering.py index b20b1f525..c8c7dcc3b 100644 --- a/tests/excerptexport/models/test_plain_text_email_rendering.py +++ b/tests/excerptexport/models/test_plain_text_email_rendering.py @@ -1,7 +1,7 @@ from django.contrib.auth import get_user_model from osmaxx.excerptexport.models import ExtractionOrder, Excerpt -from osmaxx.utilities.shortcuts import Emissary +from osmaxx.utils.shortcuts import Emissary from hamcrest import contains_string, match_equality diff --git a/tests/job_progress/test_job_progress.py b/tests/job_progress/test_job_progress.py index 9a4d83916..d15693e88 100644 --- a/tests/job_progress/test_job_progress.py +++ b/tests/job_progress/test_job_progress.py @@ -81,7 +81,7 @@ def test_calling_tracker_with_payload_indicating_started_updates_export_status(s self.export.refresh_from_db() self.assertEqual(self.export.status, STARTED) - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_queued_informs_user( self, emissary_class_mock, *args, **mocks): emissary_mock = emissary_class_mock() @@ -103,7 +103,7 @@ def test_calling_tracker_with_payload_indicating_queued_informs_user( ) ) - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_started_informs_user( self, emissary_class_mock, *args, **mocks): emissary_mock = emissary_class_mock() @@ -126,7 +126,7 @@ def test_calling_tracker_with_payload_indicating_started_informs_user( ) ) - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_failed_informs_user_with_error( self, emissary_class_mock, *args, **mocks): emissary_mock = emissary_class_mock() @@ -149,7 +149,7 @@ def test_calling_tracker_with_payload_indicating_failed_informs_user_with_error( ) @patch.object(Export, '_fetch_result_file') - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_finished_informs_user_with_success( self, emissary_class_mock, *args, **mocks): emissary_mock = emissary_class_mock() @@ -171,7 +171,7 @@ def test_calling_tracker_with_payload_indicating_finished_informs_user_with_succ ) ) - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') def test_calling_tracker_with_payload_indicating_unchanged_status_does_not_inform_user( self, emissary_class_mock, *args, **mocks): self.export.status = 'started' @@ -222,7 +222,7 @@ def test_calling_tracker_with_payload_indicating_status_finished_downloads_resul @requests_mock.Mocker(kw='requests') @patch.object(ConversionApiClient, 'authorized_get', ConversionApiClient.get) # circumvent authorization logic - @patch('osmaxx.utilities.shortcuts.Emissary') + @patch('osmaxx.utils.shortcuts.Emissary') 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 From a89eb09ac64715065066d51c46b79226d6b83815 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 5 May 2017 11:35:46 +0200 Subject: [PATCH 3/4] refactoring: #845 remove empty packages --- osmaxx/utilities/__init__.py | 0 tests/utilities/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 osmaxx/utilities/__init__.py delete mode 100644 tests/utilities/__init__.py diff --git a/osmaxx/utilities/__init__.py b/osmaxx/utilities/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/utilities/__init__.py b/tests/utilities/__init__.py deleted file mode 100644 index e69de29bb..000000000 From fda015d9e330ae61194ec46d001b35fb8aefba75 Mon Sep 17 00:00:00 2001 From: Raphael Das Gupta Date: Fri, 5 May 2017 11:54:38 +0200 Subject: [PATCH 4/4] refactoring: reorganize some imports --- osmaxx/excerptexport/forms/excerpt_form.py | 11 +++++------ .../models/test_plain_text_email_rendering.py | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/osmaxx/excerptexport/forms/excerpt_form.py b/osmaxx/excerptexport/forms/excerpt_form.py index 6e27e9d15..216f16223 100644 --- a/osmaxx/excerptexport/forms/excerpt_form.py +++ b/osmaxx/excerptexport/forms/excerpt_form.py @@ -1,16 +1,15 @@ import json -from django.core.exceptions import ValidationError -from django.utils.translation import ugettext_lazy as _ -from django import forms -from django.core.urlresolvers import reverse - from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Fieldset, Field, Submit +from django import forms +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext_lazy as _ -from .order_options_mixin import OrderOptionsMixin from osmaxx.excerptexport.models import Excerpt, ExtractionOrder from osmaxx.utils.dict_helpers import select_keys +from .order_options_mixin import OrderOptionsMixin class ExcerptForm(OrderOptionsMixin, forms.ModelForm): diff --git a/tests/excerptexport/models/test_plain_text_email_rendering.py b/tests/excerptexport/models/test_plain_text_email_rendering.py index c8c7dcc3b..9125c2829 100644 --- a/tests/excerptexport/models/test_plain_text_email_rendering.py +++ b/tests/excerptexport/models/test_plain_text_email_rendering.py @@ -1,10 +1,9 @@ from django.contrib.auth import get_user_model +from hamcrest import contains_string, match_equality from osmaxx.excerptexport.models import ExtractionOrder, Excerpt from osmaxx.utils.shortcuts import Emissary -from hamcrest import contains_string, match_equality - def test_send_email_if_all_exports_done_keeps_special_characters_unescaped(mocker, rf): User = get_user_model() # noqa