diff --git a/deployment/docker-dev/REQUIREMENTS.txt b/deployment/docker-dev/REQUIREMENTS.txt index b6892aed..b7d95124 100644 --- a/deployment/docker-dev/REQUIREMENTS.txt +++ b/deployment/docker-dev/REQUIREMENTS.txt @@ -28,3 +28,4 @@ django-filebrowser==3.7.2 django-tinymce-filebrowser==0.2.1 urllib3==1.23 pyyaml==3.12 +mock==3.0.5 diff --git a/deployment/production/docker/uwsgi/REQUIREMENTS.txt b/deployment/production/docker/uwsgi/REQUIREMENTS.txt index b6892aed..b7d95124 100644 --- a/deployment/production/docker/uwsgi/REQUIREMENTS.txt +++ b/deployment/production/docker/uwsgi/REQUIREMENTS.txt @@ -28,3 +28,4 @@ django-filebrowser==3.7.2 django-tinymce-filebrowser==0.2.1 urllib3==1.23 pyyaml==3.12 +mock==3.0.5 diff --git a/django_project/realtime/report_urls.py b/django_project/realtime/report_urls.py index 6f6e9b65..602fdcc4 100644 --- a/django_project/realtime/report_urls.py +++ b/django_project/realtime/report_urls.py @@ -20,4 +20,21 @@ r'(?P[-\d]+)-(?P[-\w]+).png$', reports.report_image, name='report_image'), + + # with source type + url(r'^(?P[-\w]+)/' + r'(?P[\w]+)/' + r'(?P[-\d]+)-(?P[-\w]+).pdf$', + reports.report_pdf, + name='report_pdf'), + url(r'^(?P[-\w]+)/' + r'(?P[\w]+)/' + r'(?P[-\d]+)-thumb-(?P[-\w]+).png$', + reports.report_thumbnail, + name='report_thumbnail'), + url(r'^(?P[-\w]+)/' + r'(?P[\w]+)/' + r'(?P[-\d]+)-(?P[-\w]+).png$', + reports.report_image, + name='report_image'), ] diff --git a/django_project/realtime/tasks/earthquake.py b/django_project/realtime/tasks/earthquake.py index 79c09bcd..4ff2f0f4 100644 --- a/django_project/realtime/tasks/earthquake.py +++ b/django_project/realtime/tasks/earthquake.py @@ -73,6 +73,7 @@ def push_shake_to_inaware(self, shake_id, source_type): pdf_url) inaware.post_url_product( hazard_id, pdf_url, 'InaSAFE Perkiraan Dampak Gempa - ID') + return True except ValueError as exc: LOGGER.debug(exc) diff --git a/django_project/realtime/tests/test_scenarios.py b/django_project/realtime/tests/test_scenarios.py index 9eb4874a..f6d193b8 100644 --- a/django_project/realtime/tests/test_scenarios.py +++ b/django_project/realtime/tests/test_scenarios.py @@ -20,6 +20,7 @@ from django.core.files.base import File from django.core.urlresolvers import reverse from django.utils.translation import activate +from mock import patch, MagicMock from rest_framework import status from core.celery_app import app as django_app @@ -36,6 +37,7 @@ from realtime.models.impact import Impact from realtime.models.volcano import Volcano from realtime.serializers.earthquake_serializer import EarthquakeSerializer +from realtime.tasks.earthquake import push_shake_to_inaware from realtime.tasks.headless.celery_app import app as headless_app from realtime.tasks.realtime.celery_app import app as realtime_app from realtime.tasks.realtime.flood import process_flood @@ -239,6 +241,17 @@ def loop_check(self, shake_id, source_type): class TestEarthquakeTasks(BaseTestEarthquakeTasks): + class InAWARERestMock(MagicMock): + + def get_hazard_id(self, shake_id): + """Arbitrary hazard ID returned by InAWARE""" + return 123 + + def post_url_product( + self, hazard_id, url_product, title='Automated URL Product'): + """Do nothing. Emulate successful post""" + return True + @timeout_decorator.timeout(LOCAL_TIMEOUT) @unittest.skipUnless( check_full_scenario_test_condition(), @@ -324,6 +337,15 @@ def test_process_earthquake(self): expected_value.pop('shake_grid') self.assertEqual(actual_value, expected_value) + # Test InAWARE push using mock + with patch( + 'realtime.tasks.earthquake.InAWARERest', + new=self.InAWARERestMock): + result = push_shake_to_inaware( + initial_event.shake_id, + initial_event.source_type) + self.assertTrue(result) + initial_event.delete() corrected_event.delete()