Skip to content

Commit

Permalink
Merge pull request #685 from praekeltfoundation/location-survey-airti…
Browse files Browse the repository at this point in the history
…me-changes

Update location survey timestamp
  • Loading branch information
erikh360 authored Sep 12, 2023
2 parents fc50e84 + 67362e4 commit 6400f36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion yal/surveys/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from yal import config, contentrepo, rapidpro
from yal.askaquestion import Application as AAQApplication
from yal.change_preferences import Application as ChangePreferencesApplication
from yal.utils import get_generic_error, normalise_phonenumber
from yal.utils import get_current_datetime, get_generic_error, normalise_phonenumber


class Application(BaseApplication):
Expand Down Expand Up @@ -329,10 +329,12 @@ async def state_location_update_status(self):

optin = self.user.answers["state_location_group_invite"]

current_datetime = get_current_datetime().isoformat()
error = await rapidpro.update_profile(
whatsapp_id,
{
"ejaf_location_survey_status": "completed",
"ejaf_location_survey_complete_time": current_datetime,
"ejaf_location_survey_optin": optin,
},
self.user.metadata,
Expand Down
14 changes: 12 additions & 2 deletions yal/tests/surveys/test_location.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from datetime import datetime
from unittest import mock

import pytest
from sanic import Sanic, response
Expand Down Expand Up @@ -391,7 +393,11 @@ async def test_state_location_group_invite(tester: AppTester):


@pytest.mark.asyncio
async def test_state_location_group_invite_submit(tester: AppTester, rapidpro_mock):
@mock.patch("yal.surveys.location.get_current_datetime")
async def test_state_location_group_invite_submit(
get_current_datetime, tester: AppTester, rapidpro_mock
):
get_current_datetime.return_value = datetime(2022, 6, 19, 17, 30)
tester.setup_state("state_location_group_invite")
await tester.user_input("1")

Expand All @@ -417,14 +423,17 @@ async def test_state_location_group_invite_submit(tester: AppTester, rapidpro_mo
"fields": {
"ejaf_location_survey_status": "completed",
"ejaf_location_survey_optin": "yes",
"ejaf_location_survey_complete_time": "2022-06-19T17:30:00",
},
}


@pytest.mark.asyncio
@mock.patch("yal.surveys.location.get_current_datetime")
async def test_state_location_group_invite_submit_dont_understand(
tester: AppTester, rapidpro_mock
get_current_datetime, tester: AppTester, rapidpro_mock
):
get_current_datetime.return_value = datetime(2022, 6, 19, 17, 30)
tester.setup_state("state_location_group_invite")
await tester.user_input("3")

Expand All @@ -451,5 +460,6 @@ async def test_state_location_group_invite_submit_dont_understand(
"fields": {
"ejaf_location_survey_status": "completed",
"ejaf_location_survey_optin": "dont_understand",
"ejaf_location_survey_complete_time": "2022-06-19T17:30:00",
},
}

0 comments on commit 6400f36

Please sign in to comment.