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


Python Flow.copy方法代码示例

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


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

示例1: test_runs

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import copy [as 别名]
    def test_runs(self):
        url = reverse('api.v2.runs')

        self.assertEndpointAccess(url)

        flow1 = self.create_flow(uuid_start=0)
        flow2 = Flow.copy(flow1, self.user)

        joe_run1, = flow1.start([], [self.joe])
        frank_run1, = flow1.start([], [self.frank])
        self.create_msg(direction='I', contact=self.joe, text="it is blue").handle()
        self.create_msg(direction='I', contact=self.frank, text="Indigo").handle()

        joe_run2, = flow1.start([], [self.joe], restart_participants=True)
        frank_run2, = flow1.start([], [self.frank], restart_participants=True)
        joe_run3, = flow2.start([], [self.joe], restart_participants=True)

        # add a test contact run
        Contact.set_simulation(True)
        flow2.start([], [self.test_contact])
        Contact.set_simulation(False)

        # add a run for another org
        flow3 = self.create_flow(org=self.org2, user=self.admin2, uuid_start=10000)
        flow3.start([], [self.hans])

        # refresh runs which will have been modified by being interrupted
        joe_run1.refresh_from_db()
        joe_run2.refresh_from_db()
        frank_run1.refresh_from_db()

        # no filtering
        with self.assertNumQueries(NUM_BASE_REQUEST_QUERIES + 6):
            response = self.fetchJSON(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json['next'], None)
        self.assertResultsById(response, [joe_run3, frank_run2, frank_run1, joe_run2, joe_run1])

        joe_run1_steps = list(joe_run1.steps.order_by('pk'))
        frank_run2_steps = list(frank_run2.steps.order_by('pk'))

        self.assertEqual(response.json['results'][1], {
            'id': frank_run2.pk,
            'flow': {'uuid': flow1.uuid, 'name': "Color Flow"},
            'contact': {'uuid': self.frank.uuid, 'name': self.frank.name},
            'responded': False,
            'steps': [
                {
                    'node': "00000000-00000000-00000000-00000001",
                    'arrived_on': format_datetime(frank_run2_steps[0].arrived_on),
                    'left_on': format_datetime(frank_run2_steps[0].left_on),
                    'text': "What is your favorite color?",
                    'value': None,
                    'category': None,
                    'type': 'actionset'
                },
                {
                    'node': "00000000-00000000-00000000-00000005",
                    'arrived_on': format_datetime(frank_run2_steps[1].arrived_on),
                    'left_on': None,
                    'text': None,
                    'value': None,
                    'category': None,
                    'type': 'ruleset'
                }
            ],
            'created_on': format_datetime(frank_run2.created_on),
            'modified_on': format_datetime(frank_run2.modified_on),
            'exited_on': None,
            'exit_type': None
        })
        self.assertEqual(response.json['results'][4], {
            'id': joe_run1.pk,
            'flow': {'uuid': flow1.uuid, 'name': "Color Flow"},
            'contact': {'uuid': self.joe.uuid, 'name': self.joe.name},
            'responded': True,
            'steps': [
                {
                    'node': "00000000-00000000-00000000-00000001",
                    'arrived_on': format_datetime(joe_run1_steps[0].arrived_on),
                    'left_on': format_datetime(joe_run1_steps[0].left_on),
                    'text': "What is your favorite color?",
                    'value': None,
                    'category': None,
                    'type': 'actionset'
                },
                {
                    'node': "00000000-00000000-00000000-00000005",
                    'arrived_on': format_datetime(joe_run1_steps[1].arrived_on),
                    'left_on': format_datetime(joe_run1_steps[1].left_on),
                    'text': 'it is blue',
                    'value': 'blue',
                    'category': "Blue",
                    'type': 'ruleset'
                },
                {
                    'node': "00000000-00000000-00000000-00000003",
                    'arrived_on': format_datetime(joe_run1_steps[2].arrived_on),
                    'left_on': format_datetime(joe_run1_steps[2].left_on),
#.........这里部分代码省略.........
开发者ID:churcho,项目名称:rapidpro,代码行数:103,代码来源:test_v2.py

示例2: test_missed_call_trigger

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import copy [as 别名]
    def test_missed_call_trigger(self):
        self.login(self.admin)
        missed_call_trigger = Trigger.get_triggers_of_type(self.org, MISSED_CALL_TRIGGER).first()
        flow = self.create_flow()
        contact = self.create_contact("Ali", "250788739305")

        self.assertFalse(missed_call_trigger)

        Call.create_call(self.channel, contact.get_urn(TEL_SCHEME).path, timezone.now(), 0, CALL_IN_MISSED)
        self.assertEquals(1, Call.objects.all().count())
        self.assertEquals(0, flow.runs.all().count())

        trigger_url = reverse("triggers.trigger_missed_call")

        response = self.client.get(trigger_url)
        self.assertEquals(response.status_code, 200)

        post_data = dict(flow=flow.pk)

        response = self.client.post(trigger_url, post_data)
        trigger =  Trigger.objects.all().order_by('-pk')[0]

        self.assertEquals(trigger.trigger_type, MISSED_CALL_TRIGGER)
        self.assertEquals(trigger.flow.pk, flow.pk)

        missed_call_trigger = Trigger.get_triggers_of_type(self.org, MISSED_CALL_TRIGGER).first()

        self.assertEquals(missed_call_trigger.pk, trigger.pk)

        Call.create_call(self.channel, contact.get_urn(TEL_SCHEME).path, timezone.now(), 0, CALL_IN_MISSED)
        self.assertEquals(2, Call.objects.all().count())
        self.assertEquals(1, flow.runs.all().count())
        self.assertEquals(flow.runs.all()[0].contact.pk, contact.pk)

        other_flow = Flow.copy(flow, self.admin)
        post_data = dict(flow=other_flow.pk)

        response = self.client.post(reverse("triggers.trigger_update", args=[trigger.pk]), post_data)
        trigger = Trigger.objects.get(pk=trigger.pk)
        self.assertEquals(trigger.flow.pk, other_flow.pk)

        # create ten missed call triggers
        for i in range(10):
            response = self.client.get(trigger_url)
            self.assertEquals(response.status_code, 200)

            post_data = dict(flow=flow.pk)

            response = self.client.post(trigger_url, post_data)
            self.assertEquals(i+2, Trigger.objects.all().count())
            self.assertEquals(1, Trigger.objects.filter(is_archived=False, trigger_type=MISSED_CALL_TRIGGER).count())

        # even unarchiving we only have one acive trigger at a time
        triggers = Trigger.objects.filter(trigger_type=MISSED_CALL_TRIGGER, is_archived=True)
        active_trigger = Trigger.objects.get(trigger_type=MISSED_CALL_TRIGGER, is_archived=False)

        post_data = dict()
        post_data['action'] = 'restore'
        post_data['objects'] = [_.pk for _ in triggers]

        response = self.client.post(reverse("triggers.trigger_archived"), post_data)
        self.assertEquals(1, Trigger.objects.filter(is_archived=False, trigger_type=MISSED_CALL_TRIGGER).count())
        self.assertFalse(active_trigger.pk == Trigger.objects.filter(is_archived=False, trigger_type=MISSED_CALL_TRIGGER)[0].pk)
开发者ID:austiine04,项目名称:rapidpro,代码行数:65,代码来源:tests.py

示例3: test_catch_all_trigger

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import copy [as 别名]
    def test_catch_all_trigger(self):
        self.login(self.admin)
        catch_all_trigger = Trigger.get_triggers_of_type(self.org, CATCH_ALL_TRIGGER).first()
        flow = self.create_flow()

        contact = self.create_contact("Ali", "250788739305")

        # make our first message echo back the original message
        action_set = ActionSet.objects.get(uuid=flow.entry_uuid)
        actions = action_set.as_json()['actions']
        actions[0]['msg'] = 'Echo: @step.value'
        action_set.set_actions_dict(actions)
        action_set.save()

        self.assertFalse(catch_all_trigger)

        Msg.create_incoming(self.channel, (TEL_SCHEME, contact.get_urn().path), "Hi")
        self.assertEquals(1, Msg.objects.all().count())
        self.assertEquals(0, flow.runs.all().count())

        trigger_url = reverse("triggers.trigger_catchall")

        response = self.client.get(trigger_url)
        self.assertEquals(response.status_code, 200)

        post_data = dict(flow=flow.pk)

        response = self.client.post(trigger_url, post_data)
        trigger = Trigger.objects.all().order_by('-pk')[0]

        self.assertEquals(trigger.trigger_type, CATCH_ALL_TRIGGER)
        self.assertEquals(trigger.flow.pk, flow.pk)

        catch_all_trigger = Trigger.get_triggers_of_type(self.org, CATCH_ALL_TRIGGER).first()

        self.assertEquals(catch_all_trigger.pk, trigger.pk)

        incoming = Msg.create_incoming(self.channel, (TEL_SCHEME, contact.get_urn().path), "Hi")
        self.assertEquals(1, flow.runs.all().count())
        self.assertEquals(flow.runs.all()[0].contact.pk, contact.pk)
        reply = Msg.objects.get(response_to=incoming)
        self.assertEquals('Echo: Hi', reply.text)

        other_flow = Flow.copy(flow, self.admin)
        post_data = dict(flow=other_flow.pk)

        response = self.client.post(reverse("triggers.trigger_update", args=[trigger.pk]), post_data)
        trigger = Trigger.objects.get(pk=trigger.pk)
        self.assertEquals(trigger.flow.pk, other_flow.pk)

        # create a bunch of catch all triggers
        for i in range(3):
            response = self.client.get(trigger_url)
            self.assertEquals(response.status_code, 200)

            post_data = dict(flow=flow.pk)
            response = self.client.post(trigger_url, post_data)
            self.assertEquals(i+2, Trigger.objects.all().count())
            self.assertEquals(1, Trigger.objects.filter(is_archived=False, trigger_type=CATCH_ALL_TRIGGER).count())

        # even unarchiving we only have one acive trigger at a time
        triggers = Trigger.objects.filter(trigger_type=CATCH_ALL_TRIGGER, is_archived=True)
        active_trigger = Trigger.objects.get(trigger_type=CATCH_ALL_TRIGGER, is_archived=False)

        post_data = dict()
        post_data['action'] = 'restore'
        post_data['objects'] = [_.pk for _ in triggers]

        response = self.client.post(reverse("triggers.trigger_archived"), post_data)
        self.assertEquals(1, Trigger.objects.filter(is_archived=False, trigger_type=CATCH_ALL_TRIGGER).count())
        self.assertFalse(active_trigger.pk == Trigger.objects.filter(is_archived=False, trigger_type=CATCH_ALL_TRIGGER)[0].pk)
开发者ID:austiine04,项目名称:rapidpro,代码行数:73,代码来源:tests.py

示例4: test_catch_all_trigger

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import copy [as 别名]
    def test_catch_all_trigger(self):
        self.login(self.admin)
        catch_all_trigger = Trigger.get_triggers_of_type(self.org, Trigger.TYPE_CATCH_ALL).first()
        flow = self.create_flow()

        contact = self.create_contact("Ali", "250788739305")

        # make our first message echo back the original message
        action_set = ActionSet.objects.get(uuid=flow.entry_uuid)
        actions = action_set.as_json()['actions']
        actions[0]['msg']['base'] = 'Echo: @step.value'
        action_set.set_actions_dict(actions)
        action_set.save()

        self.assertFalse(catch_all_trigger)

        Msg.create_incoming(self.channel, (TEL_SCHEME, contact.get_urn().path), "Hi")
        self.assertEquals(1, Msg.all_messages.all().count())
        self.assertEquals(0, flow.runs.all().count())

        trigger_url = reverse("triggers.trigger_catchall")

        response = self.client.get(trigger_url)
        self.assertEquals(response.status_code, 200)

        post_data = dict(flow=flow.pk)

        response = self.client.post(trigger_url, post_data)
        trigger = Trigger.objects.all().order_by('-pk')[0]

        self.assertEquals(trigger.trigger_type, Trigger.TYPE_CATCH_ALL)
        self.assertEquals(trigger.flow.pk, flow.pk)

        catch_all_trigger = Trigger.get_triggers_of_type(self.org, Trigger.TYPE_CATCH_ALL).first()

        self.assertEquals(catch_all_trigger.pk, trigger.pk)

        incoming = Msg.create_incoming(self.channel, (TEL_SCHEME, contact.get_urn().path), "Hi")
        self.assertEquals(1, flow.runs.all().count())
        self.assertEquals(flow.runs.all()[0].contact.pk, contact.pk)
        reply = Msg.all_messages.get(response_to=incoming)
        self.assertEquals('Echo: Hi', reply.text)

        other_flow = Flow.copy(flow, self.admin)
        post_data = dict(flow=other_flow.pk)

        self.client.post(reverse("triggers.trigger_update", args=[trigger.pk]), post_data)
        trigger = Trigger.objects.get(pk=trigger.pk)
        self.assertEquals(trigger.flow.pk, other_flow.pk)

        # try to create another catch all trigger
        response = self.client.post(trigger_url, post_data)

        # shouldn't have succeeded as we already have a catch-all trigger
        self.assertTrue(len(response.context['form'].errors))

        # archive the previous one
        trigger.is_archived = True
        trigger.save()
        old_catch_all = trigger

        # try again
        self.client.post(trigger_url, post_data)

        # this time we are a go
        new_catch_all = Trigger.objects.get(is_archived=False, trigger_type=Trigger.TYPE_CATCH_ALL)

        # now add a new trigger based on a group
        group = self.create_group("Trigger Group", [])
        post_data['groups'] = [group.pk]
        response = self.client.post(trigger_url, post_data)

        # should now have two catch all triggers
        self.assertEquals(2, Trigger.objects.filter(is_archived=False, trigger_type=Trigger.TYPE_CATCH_ALL).count())

        group_catch_all = Trigger.objects.get(is_archived=False, trigger_type=Trigger.TYPE_CATCH_ALL, groups=group)

        # try to add another catchall trigger with a few different groups
        group2 = self.create_group("Trigger Group 2", [])
        post_data['groups'] = [group.pk, group2.pk]
        response = self.client.post(trigger_url, post_data)

        # should have failed
        self.assertTrue(len(response.context['form'].errors))

        post_data = dict()
        post_data['action'] = 'restore'
        post_data['objects'] = [old_catch_all.pk]

        response = self.client.post(reverse("triggers.trigger_archived"), post_data)
        old_catch_all.refresh_from_db()
        new_catch_all.refresh_from_db()

        # our new triggers should have been auto-archived, our old one is now active
        self.assertEquals(2, Trigger.objects.filter(is_archived=False, trigger_type=Trigger.TYPE_CATCH_ALL).count())
        self.assertTrue(new_catch_all.is_archived)
        self.assertFalse(old_catch_all.is_archived)

        # ok, archive our old one too, leaving only our group specific trigger
        old_catch_all.is_archived = True
#.........这里部分代码省略.........
开发者ID:MOconcepts,项目名称:rapidpro,代码行数:103,代码来源:tests.py


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