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


Python mixin.BackendMapping类代码示例

本文整理汇总了Python中corehq.apps.sms.mixin.BackendMapping的典型用法代码示例。如果您正苦于以下问题:Python BackendMapping类的具体用法?Python BackendMapping怎么用?Python BackendMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BaseReminderTestCase

class BaseReminderTestCase(BaseAccountingTest):
    def setUp(self):
        super(BaseReminderTestCase, self).setUp()
        self.domain_obj = Domain(name="test")
        self.domain_obj.save()
        # Prevent resource conflict
        self.domain_obj = Domain.get(self.domain_obj._id)

        self.account, _ = BillingAccount.get_or_create_account_by_domain(
            self.domain_obj.name,
            created_by="tests"
        )
        advanced_plan_version = DefaultProductPlan.get_default_plan_by_domain(
            self.domain_obj, edition=SoftwarePlanEdition.ADVANCED)
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain_obj.name,
            advanced_plan_version
        )
        self.subscription.is_active = True
        self.subscription.save()

        self.sms_backend = TestSMSBackend(named="MOBILE_BACKEND_TEST", is_global=True)
        self.sms_backend.save()

        self.sms_backend_mapping = BackendMapping(is_global=True,prefix="*",backend_id=self.sms_backend._id)
        self.sms_backend_mapping.save()

    def tearDown(self):
        self.sms_backend_mapping.delete()
        self.sms_backend.delete()
        SubscriptionAdjustment.objects.all().delete()
        self.subscription.delete()
        self.account.delete()
        self.domain_obj.delete()
开发者ID:puttarajubr,项目名称:commcare-hq,代码行数:35,代码来源:__init__.py

示例2: create_backend

def create_backend():
    backend = TestSMSBackend(domain=None, name=TEST_BACKEND, authorized_domains=[], is_global=True)
    backend._id = backend.name
    backend.save()
    sms_backend_mapping = BackendMapping(is_global=True, prefix="*", backend_id=backend.get_id)
    sms_backend_mapping.save()
    return sms_backend_mapping, backend
开发者ID:johan--,项目名称:commcare-hq,代码行数:7,代码来源:utils.py

示例3: setUp

    def setUp(self):
        self.domain = "test-domain"
        self.domain2 = "test-domain2"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()
        self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict

        self.backend1 = TestCaseBackend(name="BACKEND1",is_global=True)
        self.backend1.save()

        self.backend2 = TestCaseBackend(name="BACKEND2",is_global=True)
        self.backend2.save()

        self.backend3 = TestCaseBackend(name="BACKEND3",is_global=True)
        self.backend3.save()

        self.backend4 = TestCaseBackend(name="BACKEND4",is_global=True)
        self.backend4.save()

        self.backend5 = TestCaseBackend(name="BACKEND5",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend5.save()

        self.backend6 = TestCaseBackend(name="BACKEND6",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend6.save()

        self.backend7 = TestCaseBackend(name="BACKEND7",domain=self.domain2,is_global=False,authorized_domains=[])
        self.backend7.save()
        
        self.backend8 = TestCaseBackend(name="BACKEND",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend8.save()

        self.backend9 = TestCaseBackend(name="BACKEND",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend9.save()

        self.backend10 = TestCaseBackend(name="BACKEND",is_global=True)
        self.backend10.save()

        self.backend_mapping1 = BackendMapping(is_global=True,prefix="*",backend_id=self.backend1._id)
        self.backend_mapping1.save()

        self.backend_mapping2 = BackendMapping(is_global=True,prefix="1",backend_id=self.backend2._id)
        self.backend_mapping2.save()

        self.backend_mapping3 = BackendMapping(is_global=True,prefix="91",backend_id=self.backend3._id)
        self.backend_mapping3.save()

        self.backend_mapping4 = BackendMapping(is_global=True,prefix="265",backend_id=self.backend4._id)
        self.backend_mapping4.save()

        self.case = CommCareCase(domain=self.domain)
        self.case.set_case_property("contact_phone_number","15551234567")
        self.case.set_case_property("contact_phone_number_is_verified", "1")
        self.case.save()

        self.contact = CommConnectCase.wrap(self.case.to_json())

        settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:58,代码来源:__init__.py

示例4: OptTestCase

class OptTestCase(BaseAccountingTest):
    def setUp(self):
        super(OptTestCase, self).setUp()
        self.domain = "opt-test"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        generator.instantiate_accounting_for_tests()
        self.account = BillingAccount.get_or_create_account_by_domain(
            self.domain_obj.name, created_by="automated-test"
        )[0]
        plan = DefaultProductPlan.get_default_plan_by_domain(self.domain_obj, edition=SoftwarePlanEdition.ADVANCED)
        self.subscription = Subscription.new_domain_subscription(self.account, self.domain_obj.name, plan)
        self.subscription.is_active = True
        self.subscription.save()

        self.backend = TestSMSBackend(is_global=True)
        self.backend.save()

        self.backend_mapping = BackendMapping(is_global=True, prefix="*", backend_id=self.backend._id)
        self.backend_mapping.save()

    def test_opt_out_and_opt_in(self):
        self.assertEqual(PhoneNumber.objects.count(), 0)

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

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

    def test_sending_to_opted_out_number(self):
        self.assertEqual(PhoneNumber.objects.count(), 0)
        self.assertTrue(send_sms(self.domain, None, "999123456789", "hello"))

        incoming("999123456789", "stop", "GVI")
        self.assertEqual(PhoneNumber.objects.count(), 1)
        phone_number = PhoneNumber.objects.get(phone_number="999123456789")
        self.assertFalse(phone_number.send_sms)

        self.assertFalse(send_sms(self.domain, None, "999123456789", "hello"))

    def tearDown(self):
        self.backend_mapping.delete()
        self.backend.delete()
        self.domain_obj.delete()

        SubscriptionAdjustment.objects.all().delete()
        self.subscription.delete()
        self.account.delete()
开发者ID:johan--,项目名称:commcare-hq,代码行数:55,代码来源:opt_tests.py

示例5: global_backend_map

def global_backend_map(request):
    backend_classes = get_available_backends()
    global_backends = SMSBackend.view(
        "sms/global_backends",
        classes=backend_classes,
        include_docs=True,
        reduce=False
    ).all()
    current_map = {}
    catchall_entry = None
    for entry in BackendMapping.view("sms/backend_map", startkey=["*"], endkey=["*", {}], include_docs=True).all():
        if entry.prefix == "*":
            catchall_entry = entry
        else:
            current_map[entry.prefix] = entry
    if request.method == "POST":
        form = BackendMapForm(request.POST)
        if form.is_valid():
            new_backend_map = form.cleaned_data.get("backend_map")
            new_catchall_backend_id = form.cleaned_data.get("catchall_backend_id")
            for prefix, entry in current_map.items():
                if prefix not in new_backend_map:
                    current_map[prefix].delete()
                    del current_map[prefix]
            for prefix, backend_id in new_backend_map.items():
                if prefix in current_map:
                    current_map[prefix].backend_id = backend_id
                    current_map[prefix].save()
                else:
                    current_map[prefix] = BackendMapping(is_global=True, prefix=prefix, backend_id=backend_id)
                    current_map[prefix].save()
            if new_catchall_backend_id is None:
                if catchall_entry is not None:
                    catchall_entry.delete()
                    catchall_entry = None
            else:
                if catchall_entry is None:
                    catchall_entry = BackendMapping(is_global=True, prefix="*", backend_id=new_catchall_backend_id)
                else:
                    catchall_entry.backend_id = new_catchall_backend_id
                catchall_entry.save()
            messages.success(request, _("Changes Saved."))
    else:
        initial = {
            "catchall_backend_id" : catchall_entry.backend_id if catchall_entry is not None else None,
            "backend_map" : [{"prefix" : prefix, "backend_id" : entry.backend_id} for prefix, entry in current_map.items()],
        }
        form = BackendMapForm(initial=initial)
    context = {
        "backends" : global_backends,
        "form" : form,
    }
    return render(request, "sms/backend_map.html", context)
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:53,代码来源:views.py

示例6: setUp

    def setUp(self):
        super(OptTestCase, self).setUp()
        self.domain = "opt-test"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        generator.instantiate_accounting_for_tests()
        self.account = BillingAccount.get_or_create_account_by_domain(
            self.domain_obj.name,
            created_by="automated-test",
        )[0]
        plan = DefaultProductPlan.get_default_plan_by_domain(
            self.domain_obj, edition=SoftwarePlanEdition.ADVANCED
        )
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain_obj.name,
            plan
        )
        self.subscription.is_active = True
        self.subscription.save()

        self.backend = TestSMSBackend(is_global=True)
        self.backend.save()

        self.backend_mapping = BackendMapping(
            is_global=True,
            prefix="*",
            backend_id=self.backend._id,
        )
        self.backend_mapping.save()
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:32,代码来源:opt_tests.py

示例7: BaseReminderTestCase

class BaseReminderTestCase(TestCase):
    def setUp(self):
        self.domain_obj = Domain(name="test")
        self.domain_obj.save()
        # Prevent resource conflict
        self.domain_obj = Domain.get(self.domain_obj._id)

        self.sms_backend = TestSMSBackend(named="MOBILE_BACKEND_TEST", is_global=True)
        self.sms_backend.save()

        self.sms_backend_mapping = BackendMapping(is_global=True,prefix="*",backend_id=self.sms_backend._id)
        self.sms_backend_mapping.save()

    def tearDown(self):
        self.sms_backend_mapping.delete()
        self.sms_backend.delete()
        self.domain_obj.delete()
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:17,代码来源:__init__.py

示例8: OptTestCase

class OptTestCase(TestCase):
    def setUp(self):
        self.domain = "opt-test"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        self.backend = TestSMSBackend(is_global=True)
        self.backend.save()

        self.backend_mapping = BackendMapping(
            is_global=True,
            prefix="*",
            backend_id=self.backend._id,
        )
        self.backend_mapping.save()

    def test_opt_out_and_opt_in(self):
        self.assertEqual(PhoneNumber.objects.count(), 0)

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

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

    def test_sending_to_opted_out_number(self):
        self.assertEqual(PhoneNumber.objects.count(), 0)
        self.assertTrue(send_sms(self.domain, None, "999123456789", "hello"))

        incoming("999123456789", "stop", "GVI")
        self.assertEqual(PhoneNumber.objects.count(), 1)
        phone_number = PhoneNumber.objects.get(phone_number="999123456789")
        self.assertFalse(phone_number.send_sms)

        self.assertFalse(send_sms(self.domain, None, "999123456789", "hello"))

    def tearDown(self):
        self.backend_mapping.delete()
        self.backend.delete()
        self.domain_obj.delete()
开发者ID:aristide,项目名称:commcare-hq,代码行数:45,代码来源:opt_tests.py

示例9: setUp

    def setUp(self):
        self.domain = "opt-test"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        self.backend = TestSMSBackend(is_global=True)
        self.backend.save()

        self.backend_mapping = BackendMapping(
            is_global=True,
            prefix="*",
            backend_id=self.backend._id,
        )
        self.backend_mapping.save()
开发者ID:aristide,项目名称:commcare-hq,代码行数:15,代码来源:opt_tests.py

示例10: setUp

    def setUp(self):
        self.users = []
        self.apps = []
        self.keywords = []
        self.groups = []
        self.site = self.create_site()
        self.domain = "test-domain"
        self.domain_obj = self.create_domain(self.domain)
        self.create_web_user("touchforms_user", "123")

        self.backend = TestSMSBackend(name="TEST", is_global=True)
        self.backend.save()
        self.backend_mapping = BackendMapping(is_global=True, prefix="*",
            backend_id=self.backend._id)
        self.backend_mapping.save()

        settings.DEBUG = True
开发者ID:sheelio,项目名称:commcare-hq,代码行数:17,代码来源:util.py

示例11: TouchformsTestCase


#.........这里部分代码省略.........
        return site

    def get_case(self, external_id):
        return get_one_case_in_domain_by_external_id(self.domain, external_id)

    def assertCasePropertyEquals(self, case, prop, value):
        self.assertEquals(case.get_case_property(prop), value)

    def get_last_form_submission(self):
        result = get_forms_by_type(self.domain, 'XFormInstance',
                                   recent_first=True, limit=1)
        return result[0] if len(result) > 0 else None

    def assertNoNewSubmission(self, last_submission):
        new_submission = self.get_last_form_submission()
        self.assertEquals(last_submission._id, new_submission._id)

    def assertFormQuestionEquals(self, form, question, value, cast=None):
        self.assertIn(question, form.form)
        form_value = form.form[question]
        if cast:
            form_value = cast(form_value)
        self.assertEquals(form_value, value)

    def get_last_outbound_sms(self, contact):
        # Not clear why this should be necessary, but without it the latest
        # sms may not be returned
        sleep(0.25)
        sms = SMSLog.view("sms/by_recipient",
            startkey=[contact.doc_type, contact._id, "SMSLog", "O", {}],
            endkey=[contact.doc_type, contact._id, "SMSLog", "O"],
            descending=True,
            include_docs=True,
            reduce=False,
        ).first()
        return sms

    def get_last_outbound_call(self, contact):
        # Not clear why this should be necessary, but without it the latest
        # call may not be returned
        sleep(0.25)
        call = CallLog.view("sms/by_recipient",
            startkey=[contact.doc_type, contact._id, "CallLog", "O", {}],
            endkey=[contact.doc_type, contact._id, "CallLog", "O"],
            descending=True,
            include_docs=True,
            reduce=False,
        ).first()
        return call

    def get_open_session(self, contact):
        return SQLXFormsSession.get_open_sms_session(self.domain, contact._id)

    def assertLastOutboundSMSEquals(self, contact, message):
        sms = self.get_last_outbound_sms(contact)
        self.assertIsNotNone(sms)
        self.assertEqual(sms.text, message)
        return sms

    def assertMetadataEqual(self, sms, xforms_session_couch_id=None, workflow=None):
        if xforms_session_couch_id:
            self.assertEqual(sms.xforms_session_couch_id, xforms_session_couch_id)
        if workflow:
            self.assertEqual(sms.workflow, workflow)

    def setUp(self):
        self.users = []
        self.apps = []
        self.keywords = []
        self.groups = []
        self.site = self.create_site()
        self.domain = "test-domain"
        self.domain_obj = self.create_domain(self.domain)
        self.create_web_user("touchforms_user", "123")

        self.backend = TestSMSBackend(name="TEST", is_global=True)
        self.backend.save()
        self.backend_mapping = BackendMapping(is_global=True, prefix="*",
            backend_id=self.backend._id)
        self.backend_mapping.save()

        settings.DEBUG = True

    def tearDown(self):
        for user in self.users:
            user.delete_verified_number()
            user.delete()
        for app in self.apps:
            app.delete()
        for keyword in self.keywords:
            keyword.delete()
        for group in self.groups:
            group.delete()
        self.domain_obj.delete()
        self.site.delete()
        self.backend.delete()
        self.backend_mapping.delete()
        SubscriptionAdjustment.objects.all().delete()
        self.subscription.delete()
        self.account.delete()
开发者ID:sheelio,项目名称:commcare-hq,代码行数:101,代码来源:util.py

示例12: BackendTestCase

class BackendTestCase(TestCase):
    def setUp(self):
        self.domain = "test-domain"
        self.domain2 = "test-domain2"

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()
        self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict

        self.backend1 = TestCaseBackend(name="BACKEND1",is_global=True)
        self.backend1.save()

        self.backend2 = TestCaseBackend(name="BACKEND2",is_global=True)
        self.backend2.save()

        self.backend3 = TestCaseBackend(name="BACKEND3",is_global=True)
        self.backend3.save()

        self.backend4 = TestCaseBackend(name="BACKEND4",is_global=True)
        self.backend4.save()

        self.backend5 = TestCaseBackend(name="BACKEND5",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend5.save()

        self.backend6 = TestCaseBackend(name="BACKEND6",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend6.save()

        self.backend7 = TestCaseBackend(name="BACKEND7",domain=self.domain2,is_global=False,authorized_domains=[])
        self.backend7.save()
        
        self.backend8 = TestCaseBackend(name="BACKEND",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend8.save()

        self.backend9 = TestCaseBackend(name="BACKEND",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend9.save()

        self.backend10 = TestCaseBackend(name="BACKEND",is_global=True)
        self.backend10.save()

        self.backend_mapping1 = BackendMapping(is_global=True,prefix="*",backend_id=self.backend1._id)
        self.backend_mapping1.save()

        self.backend_mapping2 = BackendMapping(is_global=True,prefix="1",backend_id=self.backend2._id)
        self.backend_mapping2.save()

        self.backend_mapping3 = BackendMapping(is_global=True,prefix="91",backend_id=self.backend3._id)
        self.backend_mapping3.save()

        self.backend_mapping4 = BackendMapping(is_global=True,prefix="265",backend_id=self.backend4._id)
        self.backend_mapping4.save()

        self.case = CommCareCase(domain=self.domain)
        self.case.set_case_property("contact_phone_number","15551234567")
        self.case.set_case_property("contact_phone_number_is_verified", "1")
        self.case.save()

        self.contact = CommConnectCase.wrap(self.case.to_json())

        settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")

    def tearDown(self):
        self.backend1.delete_invoke_doc()
        self.backend1.delete()
        self.backend_mapping1.delete()

        self.backend2.delete_invoke_doc()
        self.backend2.delete()
        self.backend_mapping2.delete()

        self.backend3.delete_invoke_doc()
        self.backend3.delete()
        self.backend_mapping3.delete()

        self.backend4.delete_invoke_doc()
        self.backend4.delete()
        self.backend_mapping4.delete()

        self.backend5.delete_invoke_doc()
        self.backend5.delete()

        self.backend6.delete_invoke_doc()
        self.backend6.delete()

        self.backend7.delete_invoke_doc()
        self.backend7.delete()

        self.contact.delete_verified_number()
        self.case.delete()

        self.domain_obj.delete()

        settings.SMS_LOADED_BACKENDS.pop()

    def test_backend(self):
        # Test the backend map

        self.assertTrue(send_sms(self.domain, None, "15551234567", "Test for BACKEND2"))
        self.assertFalse(self.backend1.invoke_doc_exists())
        self.assertTrue(self.backend2.invoke_doc_exists())
        self.assertFalse(self.backend3.invoke_doc_exists())
#.........这里部分代码省略.........
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:101,代码来源:__init__.py

示例13: setUp

    def setUp(self):
        self.domain = "test-domain"
        self.domain2 = "test-domain2"

        self.site, self.site_created = self.get_or_create_site()

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        generator.instantiate_accounting_for_tests()
        self.account = BillingAccount.get_or_create_account_by_domain(
            self.domain_obj.name,
            created_by="automated-test",
        )[0]
        plan = DefaultProductPlan.get_default_plan_by_domain(
            self.domain_obj, edition=SoftwarePlanEdition.ADVANCED
        )
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain_obj.name,
            plan
        )
        self.subscription.is_active = True
        self.subscription.save()
        self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict


        self.backend1 = TestCaseBackend(name="BACKEND1",is_global=True)
        self.backend1.save()

        self.backend2 = TestCaseBackend(name="BACKEND2",is_global=True)
        self.backend2.save()

        self.backend3 = TestCaseBackend(name="BACKEND3",is_global=True)
        self.backend3.save()

        self.backend4 = TestCaseBackend(name="BACKEND4",is_global=True)
        self.backend4.save()

        self.backend5 = TestCaseBackend(name="BACKEND5",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend5.save()

        self.backend6 = TestCaseBackend(name="BACKEND6",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend6.save()

        self.backend7 = TestCaseBackend(name="BACKEND7",domain=self.domain2,is_global=False,authorized_domains=[])
        self.backend7.save()
        
        self.backend8 = TestCaseBackend(name="BACKEND",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend8.save()

        self.backend9 = TestCaseBackend(name="BACKEND",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend9.save()

        self.backend10 = TestCaseBackend(name="BACKEND",is_global=True)
        self.backend10.save()

        self.backend_mapping1 = BackendMapping(is_global=True,prefix="*",backend_id=self.backend1._id)
        self.backend_mapping1.save()

        self.backend_mapping2 = BackendMapping(is_global=True,prefix="1",backend_id=self.backend2._id)
        self.backend_mapping2.save()

        self.backend_mapping3 = BackendMapping(is_global=True,prefix="91",backend_id=self.backend3._id)
        self.backend_mapping3.save()

        self.backend_mapping4 = BackendMapping(is_global=True,prefix="265",backend_id=self.backend4._id)
        self.backend_mapping4.save()

        self.case = CommCareCase(domain=self.domain)
        self.case.set_case_property("contact_phone_number","15551234567")
        self.case.set_case_property("contact_phone_number_is_verified", "1")
        self.case.save()

        self.contact = CommConnectCase.wrap(self.case.to_json())

        settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")
开发者ID:aristide,项目名称:commcare-hq,代码行数:77,代码来源:__init__.py

示例14: BackendTestCase

class BackendTestCase(TestCase):
    def get_or_create_site(self):
        site, created = Site.objects.get_or_create(id=settings.SITE_ID)
        if created:
            site.domain = 'localhost'
            site.name = 'localhost'
            site.save()
        return (site, created)

    def setUp(self):
        self.domain = "test-domain"
        self.domain2 = "test-domain2"

        self.site, self.site_created = self.get_or_create_site()

        self.domain_obj = Domain(name=self.domain)
        self.domain_obj.save()

        generator.instantiate_accounting_for_tests()
        self.account = BillingAccount.get_or_create_account_by_domain(
            self.domain_obj.name,
            created_by="automated-test",
        )[0]
        plan = DefaultProductPlan.get_default_plan_by_domain(
            self.domain_obj, edition=SoftwarePlanEdition.ADVANCED
        )
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain_obj.name,
            plan
        )
        self.subscription.is_active = True
        self.subscription.save()
        self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict


        self.backend1 = TestCaseBackend(name="BACKEND1",is_global=True)
        self.backend1.save()

        self.backend2 = TestCaseBackend(name="BACKEND2",is_global=True)
        self.backend2.save()

        self.backend3 = TestCaseBackend(name="BACKEND3",is_global=True)
        self.backend3.save()

        self.backend4 = TestCaseBackend(name="BACKEND4",is_global=True)
        self.backend4.save()

        self.backend5 = TestCaseBackend(name="BACKEND5",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend5.save()

        self.backend6 = TestCaseBackend(name="BACKEND6",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend6.save()

        self.backend7 = TestCaseBackend(name="BACKEND7",domain=self.domain2,is_global=False,authorized_domains=[])
        self.backend7.save()
        
        self.backend8 = TestCaseBackend(name="BACKEND",domain=self.domain,is_global=False,authorized_domains=[])
        self.backend8.save()

        self.backend9 = TestCaseBackend(name="BACKEND",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
        self.backend9.save()

        self.backend10 = TestCaseBackend(name="BACKEND",is_global=True)
        self.backend10.save()

        self.backend_mapping1 = BackendMapping(is_global=True,prefix="*",backend_id=self.backend1._id)
        self.backend_mapping1.save()

        self.backend_mapping2 = BackendMapping(is_global=True,prefix="1",backend_id=self.backend2._id)
        self.backend_mapping2.save()

        self.backend_mapping3 = BackendMapping(is_global=True,prefix="91",backend_id=self.backend3._id)
        self.backend_mapping3.save()

        self.backend_mapping4 = BackendMapping(is_global=True,prefix="265",backend_id=self.backend4._id)
        self.backend_mapping4.save()

        self.case = CommCareCase(domain=self.domain)
        self.case.set_case_property("contact_phone_number","15551234567")
        self.case.set_case_property("contact_phone_number_is_verified", "1")
        self.case.save()

        self.contact = CommConnectCase.wrap(self.case.to_json())

        settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")

    def tearDown(self):
        self.backend1.delete_invoke_doc()
        self.backend1.delete()
        self.backend_mapping1.delete()

        self.backend2.delete_invoke_doc()
        self.backend2.delete()
        self.backend_mapping2.delete()

        self.backend3.delete_invoke_doc()
        self.backend3.delete()
        self.backend_mapping3.delete()

#.........这里部分代码省略.........
开发者ID:aristide,项目名称:commcare-hq,代码行数:101,代码来源:__init__.py


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