Skip to content

Commit

Permalink
Merge 686c924 into b401920
Browse files Browse the repository at this point in the history
  • Loading branch information
OMosimege committed Jul 12, 2018
2 parents b401920 + 686c924 commit 2e38fc9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ db.sqlite3
docs/_build
.DS_Store
.cache
.pytest_cache
.vscode
.pytest_cache/
.vscode/
22 changes: 19 additions & 3 deletions malaria24/ona/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime

import pytz
import re


class Digest(models.Model):
Expand Down Expand Up @@ -656,7 +657,11 @@ class ReportedCase(models.Model):

def get_data(self):
'''JSON Formats need create_date_time & date_of_birth
to be overridden'''
to be overridden
need to validate msisdn and reported_by fields are in
correct format'''

try:
birth_date = datetime.strptime(self.date_of_birth, '%Y-%m-%d')
except ValueError:
Expand All @@ -666,16 +671,27 @@ def get_data(self):
# old format.
birth_date = datetime.strptime(self.date_of_birth, '%y%m%d')

valid_prefix = '[+27]'
if re.match('^' + valid_prefix + '*([0-9]{9})$', self.reported_by):
reported_by = self.reported_by
else:
reported_by = '+27' + self.reported_by[1:]

if re.match('^' + valid_prefix + '*([0-9]{9})$', self.msisdn):
msisdn = self.msisdn
else:
msisdn = '+27' + self.msisdn[1:]

return {"first_name": self.first_name,
"last_name": self.last_name,
"gender": self.gender,
"msisdn": self.msisdn,
"msisdn": msisdn,
"landmark_description": self.landmark_description,
"id_type": self.id_type,
"case_number": self.case_number,
"abroad": self.abroad,
"locality": self.locality,
"reported_by": self.reported_by,
"reported_by": reported_by,
"date_of_birth": birth_date.strftime("%Y-%m-%d"),
"sa_id_number": self.sa_id_number,
"create_date_time": self.create_date_time.strftime(
Expand Down
21 changes: 18 additions & 3 deletions malaria24/ona/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,28 @@ def test_sms_junebug_if_set(self):
[sms] = SMS.objects.all()
self.assertEqual(sms.content, "test message")

@responses.activate
def test_get_data(self):
case = self.mk_case(first_name="John", last_name="Day", gender="male",
msisdn="0711111111", landmark_description="None",
id_type="said", case_number="20171214-123456-42",
abroad="No", locality="None",
reported_by="+27722222222",
sa_id_number="5608071111083",
landmark="School", facility_code="123456",
date_of_birth="1995-01-01")
case.save()
data = case.get_data()
self.assertEqual(data['msisdn'], '+27711111111')
self.assertEqual(data['reported_by'], '+27722222222')

@responses.activate
def test_compile_and_send_jembi(self):
case = self.mk_case(first_name="John", last_name="Day", gender="male",
msisdn="0711111111", landmark_description="None",
id_type="said", case_number="20171214-123456-42",
abroad="No", locality="None",
reported_by="+27721111111",
reported_by="+27722222222",
sa_id_number="5608071111083",
landmark="School", facility_code="123456",
date_of_birth="1995-01-01")
Expand Down Expand Up @@ -458,10 +473,10 @@ def test_compile_and_send_jembi(self):
self.assertEqual(data['first_name'], 'John')
self.assertEqual(data['last_name'], 'Day')
self.assertEqual(data['gender'], 'male')
self.assertEqual(data['msisdn'], '0711111111')
self.assertEqual(data['msisdn'], '+27711111111')
self.assertEqual(data['case_number'], '20171214-123456-42')
self.assertEqual(data['sa_id_number'], '5608071111083')
self.assertEqual(data['reported_by'], '+27721111111')
self.assertEqual(data['reported_by'], '+27722222222')
self.assertEqual(data['id_type'], 'said')
self.assertEqual(data['abroad'], 'No')
self.assertEqual(data['landmark_description'], 'None')
Expand Down

0 comments on commit 2e38fc9

Please sign in to comment.