当前位置: 首页>>代码示例>>Python>>正文


Python PhoneNumber.get_two_way_number方法代码示例

本文整理汇总了Python中corehq.apps.sms.models.PhoneNumber.get_two_way_number方法的典型用法代码示例。如果您正苦于以下问题:Python PhoneNumber.get_two_way_number方法的具体用法?Python PhoneNumber.get_two_way_number怎么用?Python PhoneNumber.get_two_way_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.sms.models.PhoneNumber的用法示例。


在下文中一共展示了PhoneNumber.get_two_way_number方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_opt_out_and_opt_in

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_opt_out_and_opt_in(self):
        self.assertEqual(PhoneBlacklist.objects.count(), 0)

        incoming('99912345678', 'join opt-test', 'GVI')
        v = PhoneNumber.get_two_way_number('99912345678')
        self.assertIsNotNone(v)

        incoming('99912345678', 'stop', 'GVI')
        self.assertEqual(PhoneBlacklist.objects.count(), 1)
        phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
        self.assertFalse(phone_number.send_sms)
        self.assertEqual(phone_number.domain, self.domain)
        self.assertIsNotNone(phone_number.last_sms_opt_out_timestamp)
        self.assertIsNone(phone_number.last_sms_opt_in_timestamp)

        sms = self.get_last_sms('+99912345678')
        self.assertEqual(sms.direction, 'O')
        self.assertEqual(sms.text, get_message(MSG_OPTED_OUT, context=('START',)))

        incoming('99912345678', 'start', 'GVI')
        self.assertEqual(PhoneBlacklist.objects.count(), 1)
        phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
        self.assertTrue(phone_number.send_sms)
        self.assertEqual(phone_number.domain, self.domain)
        self.assertIsNotNone(phone_number.last_sms_opt_out_timestamp)
        self.assertIsNotNone(phone_number.last_sms_opt_in_timestamp)

        sms = self.get_last_sms('+99912345678')
        self.assertEqual(sms.direction, 'O')
        self.assertEqual(sms.text, get_message(MSG_OPTED_IN, context=('STOP',)))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:32,代码来源:opt_tests.py

示例2: test_sending_to_opted_out_number

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_sending_to_opted_out_number(self):
        self.assertEqual(PhoneBlacklist.objects.count(), 0)

        incoming('99912345678', 'join opt-test', 'GVI')
        v = PhoneNumber.get_two_way_number('99912345678')
        self.assertIsNotNone(v)

        send_sms_to_verified_number(v, 'hello')
        sms = self.get_last_sms('+99912345678')
        self.assertEqual(sms.direction, 'O')
        self.assertEqual(sms.text, 'hello')

        incoming('99912345678', 'stop', 'GVI')
        self.assertEqual(PhoneBlacklist.objects.count(), 1)
        phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
        self.assertFalse(phone_number.send_sms)

        send_sms_to_verified_number(v, 'hello')
        sms = self.get_last_sms('+99912345678')
        self.assertEqual(sms.direction, 'O')
        self.assertEqual(sms.text, 'hello')
        self.assertTrue(sms.error)
        self.assertEqual(sms.system_error_message, SMS.ERROR_PHONE_NUMBER_OPTED_OUT)

        incoming('99912345678', 'start', 'GVI')
        self.assertEqual(PhoneBlacklist.objects.count(), 1)
        phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
        self.assertTrue(phone_number.send_sms)

        send_sms_to_verified_number(v, 'hello')
        sms = self.get_last_sms('+99912345678')
        self.assertEqual(sms.direction, 'O')
        self.assertEqual(sms.text, 'hello')
        self.assertFalse(sms.error)
        self.assertIsNone(sms.system_error_message)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:37,代码来源:opt_tests.py

示例3: testSync

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def testSync(self):
        extra_number = PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='owner1',
            phone_number='999123',
            verified=True,
            pending_verification=False,
            is_two_way=True
        )

        user = self.mobile_worker1
        self.assertEqual(PhoneNumber.by_domain(self.domain).count(), 1)

        user.phone_numbers = ['9990001']
        user.save()
        self.assertEqual(PhoneNumber.by_domain(self.domain).count(), 2)
        self.assertPhoneEntries(user, ['9990001'])

        before = user.get_phone_entries()['9990001']

        user.phone_numbers = ['9990001', '9990002']
        user.save()
        self.assertEqual(PhoneNumber.by_domain(self.domain).count(), 3)
        self.assertPhoneEntries(user, ['9990001', '9990002'])

        after = user.get_phone_entries()['9990001']
        self.assertEqual(before.pk, after.pk)

        user.phone_numbers = ['9990002']
        user.save()
        self.assertEqual(PhoneNumber.by_domain(self.domain).count(), 2)
        self.assertPhoneEntries(user, ['9990002'])

        self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:37,代码来源:test_phone_numbers.py

示例4: assertMatch

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def assertMatch(self, match, phone_search, suffix_search, owner_id_search):
        lookedup = PhoneNumber.get_two_way_number(phone_search)
        self.assertPhoneNumbersEqual(match, lookedup)

        lookedup = PhoneNumber.get_two_way_number_by_suffix(suffix_search)
        self.assertPhoneNumbersEqual(match, lookedup)

        [lookedup] = PhoneNumber.by_owner_id(owner_id_search)
        self.assertPhoneNumbersEqual(match, lookedup)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:11,代码来源:test_phone_numbers.py

示例5: test_get_number_pending_verification

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_get_number_pending_verification(self):
        number1 = PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='X',
            phone_number='999123',
            verified=False,
            pending_verification=True,
            is_two_way=False
        )

        PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='X',
            phone_number='999123',
            verified=False,
            pending_verification=False,
            is_two_way=False
        )

        self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
        self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
        self.assertEqual(PhoneNumber.get_number_pending_verification('999123'), number1)
        self.assertEqual(PhoneNumber.get_number_pending_verification('+999 123'), number1)
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

        # test cache clear on save
        number1.phone_number = '999124'
        number1.save()
        self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
        self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
        self.assertEqual(PhoneNumber.get_number_pending_verification('999124'), number1)
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

        # test promotion to two-way
        number1.set_two_way()
        number1.set_verified()
        number1.save()
        self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
        self.assertEqual(PhoneNumber.get_two_way_number('999124'), number1)
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

        # test cache clear on delete
        number1.delete()
        self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
        self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
        self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:56,代码来源:test_phone_numbers.py

示例6: test_other_registration_from_invite

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    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,
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:55,代码来源:test_registration.py

示例7: run_script

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
 def run_script(self, script):
     commands = self.parse_script(script)
     for command in commands:
         phone_number = command['phone_number']
         v = PhoneNumber.get_two_way_number(phone_number)
         if command['direction'] == '>':
             incoming(phone_number, command['text'], v.backend_id)
         else:
             msg = self.get_last_outbound_sms(v.owner_doc_type, v.owner_id)
             self.assertEqual(msg.text, six.text_type(command['text']))
             self.assertEqual(strip_plus(msg.phone_number), strip_plus(phone_number))
             msg.delete()
开发者ID:,项目名称:,代码行数:14,代码来源:

示例8: test_android_only_registration_from_invite

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    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': 'new_user',
            'password': 'abc',
            'password2': 'abc',
            'email': '[email protected]',
        })
        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, '[email protected]')
        self.assertEqual(PhoneNumber.get_two_way_number('999123').owner_id, user.get_id)

        self.assertRegistrationInvitation(
            status=SelfRegistrationInvitation.STATUS_REGISTERED,
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:53,代码来源:test_registration.py

示例9: test_case_phone_number_updates

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_case_phone_number_updates(self):
        extra_number = PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='X',
            phone_number='999123',
            verified=True,
            pending_verification=False,
            is_two_way=True
        )
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)

        with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
            self.assertIsNone(self.get_case_phone_number(case))

            case = self.set_case_property(case, 'contact_phone_number', '99987658765')
            self.assertPhoneNumberDetails(case, '99987658765', None, None, False, False, False)
            pk = self.get_case_phone_number(case).pk
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
            self.assertPhoneNumberDetails(case, '99987658765', None, None, True, False, True, pk=pk)
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            case = self.set_case_property(case, 'contact_phone_number', '99987698769')
            self.assertPhoneNumberDetails(case, '99987698769', None, None, True, False, True)
            pk = self.get_case_phone_number(case).pk
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            case = self.set_case_property(case, 'contact_backend_id', 'sms-backend')
            self.assertPhoneNumberDetails(case, '99987698769', 'sms-backend', None, True, False, True, pk=pk)
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            case = self.set_case_property(case, 'contact_ivr_backend_id', 'ivr-backend')
            self.assertPhoneNumberDetails(case, '99987698769', 'sms-backend', 'ivr-backend', True, False, True,
                pk=pk)
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            # If phone entry is ahead of the case in terms of contact_last_modified, no update should happen
            v = self.get_case_phone_number(case)
            v.contact_last_modified += timedelta(days=1)
            v.save()

            with patch('corehq.apps.sms.models.PhoneNumber.save') as mock_save:
                case = self.set_case_property(case, 'contact_phone_number', '99912341234')
                self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
                mock_save.assert_not_called()

        self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:51,代码来源:test_phone_numbers.py

示例10: test_invalid_phone_format

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_invalid_phone_format(self):
        extra_number = PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='X',
            phone_number='999123',
            verified=True,
            pending_verification=False,
            is_two_way=True
        )
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)

        with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
            case = self.set_case_property(case, 'contact_phone_number', '99987658765')
            case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
            self.assertIsNotNone(self.get_case_phone_number(case))
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            case = self.set_case_property(case, 'contact_phone_number', 'xyz')
            self.assertIsNone(self.get_case_phone_number(case))
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)

        self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:25,代码来源:test_phone_numbers.py

示例11: test_case_soft_delete

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
    def test_case_soft_delete(self):
        extra_number = PhoneNumber.objects.create(
            domain=self.domain,
            owner_doc_type='X',
            owner_id='X',
            phone_number='999123',
            verified=True,
            pending_verification=False,
            is_two_way=True
        )
        self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)

        with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
            case = self.set_case_property(case, 'contact_phone_number', '99987658765')
            case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
            self.assertIsNotNone(self.get_case_phone_number(case))
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)

            tag_cases_as_deleted_and_remove_indices(self.domain, [case.case_id], '123', datetime.utcnow())
            self.assertIsNone(self.get_case_phone_number(case))
            self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)

        self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:25,代码来源:test_phone_numbers.py

示例12: verified_number

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
 def verified_number(self):
     return PhoneNumber.get_two_way_number(self.phone_number)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:4,代码来源:models.py

示例13: assertNoMatch

# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import get_two_way_number [as 别名]
 def assertNoMatch(self, phone_search, suffix_search, owner_id_search):
     self.assertIsNone(PhoneNumber.get_two_way_number(phone_search))
     self.assertIsNone(PhoneNumber.get_two_way_number_by_suffix(suffix_search))
     self.assertEqual(PhoneNumber.by_owner_id(owner_id_search), [])
开发者ID:dimagi,项目名称:commcare-hq,代码行数:6,代码来源:test_phone_numbers.py


注:本文中的corehq.apps.sms.models.PhoneNumber.get_two_way_number方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。