Skip to content

Commit

Permalink
Add unittests for InAWARE REST push
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Jul 21, 2019
1 parent 448faf2 commit 9bd7dda
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions deployment/docker-dev/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions deployment/production/docker/uwsgi/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions django_project/realtime/report_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
r'(?P<shake_id>[-\d]+)-(?P<language2>[-\w]+).png$',
reports.report_image,
name='report_image'),

# with source type
url(r'^(?P<language>[-\w]+)/'
r'(?P<source_type>[\w]+)/'
r'(?P<shake_id>[-\d]+)-(?P<language2>[-\w]+).pdf$',
reports.report_pdf,
name='report_pdf'),
url(r'^(?P<language>[-\w]+)/'
r'(?P<source_type>[\w]+)/'
r'(?P<shake_id>[-\d]+)-thumb-(?P<language2>[-\w]+).png$',
reports.report_thumbnail,
name='report_thumbnail'),
url(r'^(?P<language>[-\w]+)/'
r'(?P<source_type>[\w]+)/'
r'(?P<shake_id>[-\d]+)-(?P<language2>[-\w]+).png$',
reports.report_image,
name='report_image'),
]
1 change: 1 addition & 0 deletions django_project/realtime/tasks/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions django_project/realtime/tests/test_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 9bd7dda

Please sign in to comment.