def test_other_registration_from_invite(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() user_data = {'abc': 'def'} # Initiate Registration Workflow SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123', user_data)], app_id=self.app_id, ) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=None, android_only=False, require_email=False, custom_user_data=user_data, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS( '+999123', [_MESSAGES[MSG_MOBILE_WORKER_INVITATION_START]]) # Choose phone type 'other' incoming('+999123', '2', self.backend.hq_api_id) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=SelfRegistrationInvitation.PHONE_TYPE_OTHER, android_only=False, require_email=False, custom_user_data=user_data, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS( '+999123', [_MESSAGES[MSG_MOBILE_WORKER_JAVA_INVITATION].format(self.domain)]) # Register over SMS incoming('+999123', 'JOIN {} WORKER test'.format(self.domain), self.backend.hq_api_id) user = CommCareUser.get_by_username( format_username('test', self.domain)) self.assertIsNotNone(user) self.assertEqual(user.user_data, dict(self.default_user_data, **user_data)) self.assertEqual( PhoneNumber.get_two_way_number('999123').owner_id, user.get_id) self.assertLastOutgoingSMS( '+999123', [_MESSAGES[MSG_REGISTRATION_WELCOME_MOBILE_WORKER]]) self.assertRegistrationInvitation( status=SelfRegistrationInvitation.STATUS_REGISTERED, )
def test_android_only_registration_from_invite(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow with patch('corehq.apps.sms.models.SelfRegistrationInvitation.odk_url') as mock_odk_url, \ patch.object(SelfRegistrationInvitation, 'get_user_registration_url', return_value=DUMMY_REGISTRATION_URL), \ patch.object(SelfRegistrationInvitation, 'get_app_info_url', return_value=DUMMY_APP_INFO_URL): mock_odk_url.__get__ = Mock(return_value=DUMMY_APP_ODK_URL) SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, android_only=True, ) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=SelfRegistrationInvitation.PHONE_TYPE_ANDROID, android_only=True, require_email=False, custom_user_data={}, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS('+999123', [ _MESSAGES[MSG_MOBILE_WORKER_ANDROID_INVITATION].format( DUMMY_REGISTRATION_URL), '[commcare app - do not delete] {}'.format(DUMMY_APP_INFO_URL_B64), ]) invite = self._get_sms_registration_invitation() c = Client() response = c.post( '/a/{}/settings/users/commcare/register/{}/'.format( self.domain, invite.token), { 'username': '******', 'password': '******', 'password2': 'abc', 'email': '*****@*****.**', }) self.assertEqual(response.status_code, 200) user = CommCareUser.get_by_username( format_username('new_user', self.domain)) self.assertIsNotNone(user) self.assertEqual(user.user_data, self.default_user_data) self.assertEqual(user.email, '*****@*****.**') self.assertEqual( PhoneNumber.get_two_way_number('999123').owner_id, user.get_id) self.assertRegistrationInvitation( status=SelfRegistrationInvitation.STATUS_REGISTERED, )
def test_other_registration_from_invite(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() user_data = {'abc': 'def'} # Initiate Registration Workflow SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123', user_data)], app_id=self.app_id, ) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=None, android_only=False, require_email=False, custom_user_data=user_data, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS('+999123', [_MESSAGES[MSG_MOBILE_WORKER_INVITATION_START]]) # Choose phone type 'other' incoming('+999123', '2', self.backend.hq_api_id) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=SelfRegistrationInvitation.PHONE_TYPE_OTHER, android_only=False, require_email=False, custom_user_data=user_data, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS('+999123', [_MESSAGES[MSG_MOBILE_WORKER_JAVA_INVITATION].format(self.domain)]) # Register over SMS incoming('+999123', 'JOIN {} WORKER test'.format(self.domain), self.backend.hq_api_id) user = CommCareUser.get_by_username(format_username('test', self.domain)) self.assertIsNotNone(user) self.assertEqual(user.user_data, user_data) self.assertEqual(PhoneNumber.by_phone('999123').owner_id, user.get_id) self.assertLastOutgoingSMS('+999123', [_MESSAGES[MSG_REGISTRATION_WELCOME_MOBILE_WORKER]]) self.assertRegistrationInvitation( status=SelfRegistrationInvitation.STATUS_REGISTERED, )
def test_android_only_registration_from_invite(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow with patch('corehq.apps.sms.models.SelfRegistrationInvitation.odk_url') as mock_odk_url, \ patch.object(SelfRegistrationInvitation, 'get_user_registration_url', return_value=DUMMY_REGISTRATION_URL), \ patch.object(SelfRegistrationInvitation, 'get_app_info_url', return_value=DUMMY_APP_INFO_URL): mock_odk_url.__get__ = Mock(return_value=DUMMY_APP_ODK_URL) SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, android_only=True, ) self.assertRegistrationInvitation( phone_number='999123', app_id=self.app_id, phone_type=SelfRegistrationInvitation.PHONE_TYPE_ANDROID, android_only=True, require_email=False, custom_user_data={}, status=SelfRegistrationInvitation.STATUS_PENDING, ) self.assertLastOutgoingSMS('+999123', [ _MESSAGES[MSG_MOBILE_WORKER_ANDROID_INVITATION].format(DUMMY_REGISTRATION_URL), '[commcare app - do not delete] {}'.format(DUMMY_APP_INFO_URL_B64), ]) invite = self._get_sms_registration_invitation() c = Client() response = c.post('/a/{}/settings/users/commcare/register/{}/'.format(self.domain, invite.token), { 'username': '******', 'password': '******', 'password2': 'abc', 'email': '*****@*****.**', }) self.assertEqual(response.status_code, 200) user = CommCareUser.get_by_username(format_username('new_user', self.domain)) self.assertIsNotNone(user) self.assertEqual(user.user_data, {}) self.assertEqual(user.email, '*****@*****.**') self.assertEqual(PhoneNumber.by_phone('999123').owner_id, user.get_id) self.assertRegistrationInvitation( status=SelfRegistrationInvitation.STATUS_REGISTERED, )
def test_custom_message_for_normal_workflow(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, custom_first_message='Custom Message', ) self.assertLastOutgoingSMS('+999123', ['Custom Message'])
def test_custom_message_for_normal_workflow(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, custom_first_message='Custom Message', ) self.assertLastOutgoingSMS('+999123', ['Custom Message'])
def test_custom_message_for_normal_workflow(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow with patch.object(SelfRegistrationInvitation, 'get_app_odk_url', return_value=DUMMY_APP_ODK_URL): SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, custom_first_message='Custom Message', ) self.assertLastOutgoingSMS('+999123', ['Custom Message'])
def obj_create(self, bundle, **kwargs): bundle = self.full_hydrate(bundle) self.registration_result = SelfRegistrationInvitation.initiate_workflow( bundle.request.domain, bundle.obj.users, app_id=bundle.obj.app_id, custom_first_message=bundle.obj.custom_registration_message, android_only=bundle.obj.android_only, require_email=bundle.obj.require_email, ) return bundle
def obj_create(self, bundle, **kwargs): bundle = self.full_hydrate(bundle) self.registration_result = SelfRegistrationInvitation.initiate_workflow( bundle.request.domain, bundle.obj.users, app_id=bundle.obj.app_id, custom_first_message=bundle.obj.custom_registration_message, android_only=bundle.obj.android_only, require_email=bundle.obj.require_email, ) return bundle
def test_custom_message_for_android_only_workflow(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow with patch.object(SelfRegistrationInvitation, 'get_app_odk_url', return_value=DUMMY_APP_ODK_URL), \ patch.object(SelfRegistrationInvitation, 'get_user_registration_url', return_value=DUMMY_REGISTRATION_URL), \ patch.object(SelfRegistrationInvitation, 'get_app_info_url', return_value=DUMMY_APP_INFO_URL): SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, android_only=True, custom_first_message='Sign up here: {}', ) self.assertLastOutgoingSMS('+999123', [ 'Sign up here: {}'.format(DUMMY_REGISTRATION_URL), '[commcare app - do not delete] {}'.format(DUMMY_APP_INFO_URL), ])
def test_custom_message_for_android_only_workflow(self): self.domain_obj.sms_mobile_worker_registration_enabled = True self.domain_obj.enable_registration_welcome_sms_for_mobile_worker = True self.domain_obj.save() # Initiate Registration Workflow with patch('corehq.apps.sms.models.SelfRegistrationInvitation.odk_url') as mock_odk_url, \ patch.object(SelfRegistrationInvitation, 'get_user_registration_url', return_value=DUMMY_REGISTRATION_URL), \ patch.object(SelfRegistrationInvitation, 'get_app_info_url', return_value=DUMMY_APP_INFO_URL): mock_odk_url.__get__ = Mock(return_value=DUMMY_APP_ODK_URL) SelfRegistrationInvitation.initiate_workflow( self.domain, [SelfRegistrationUserInfo('999123')], app_id=self.app_id, android_only=True, custom_first_message='Sign up here: {}', ) self.assertLastOutgoingSMS('+999123', [ 'Sign up here: {}'.format(DUMMY_REGISTRATION_URL), '[commcare app - do not delete] {}'.format(DUMMY_APP_INFO_URL_B64), ])