コード例 #1
0
ファイル: go_api.py プロジェクト: linkedinyou/vumi-go
        def populate_routing_table(routing_entries):
            routing_table = RoutingTable()
            for entry in routing_entries:
                source, target = entry['source'], entry['target']
                src_conn, src_endp = EndpointType.parse_uuid(
                    source['uuid'])
                dst_conn, dst_endp = EndpointType.parse_uuid(
                    target['uuid'])
                routing_table.add_entry(src_conn, src_endp, dst_conn, dst_endp)

            d = user_api.get_user_account()
            d.addCallback(save_routing_table, routing_table)
            return d
コード例 #2
0
ファイル: test_api.py プロジェクト: linkedinyou/vumi-go
    def test_archive_router(self):
        router = yield self.create_router()
        router_api = yield self.get_router_api(router)
        yield self._add_routing_entries(router)
        self.assertEqual(router.archive_status, 'active')
        self.assertNotEqual(RoutingTable(),
                            (yield self.user_api.get_routing_table()))

        yield router_api.archive_router()
        router = yield router_api.get_router()
        self.assertEqual(router.archive_status, 'archived')
        self.assertEqual(RoutingTable(),
                         (yield self.user_api.get_routing_table()))
コード例 #3
0
ファイル: tests.py プロジェクト: linkedinyou/vumi-go
    def assert_routing_table(self, channel_conv=[], channel_router=[],
                             router_conv=[]):
        """Assert that the routing table has a particular form.

        :param tag_conv: List of (tag, conversation) pairs.
        :param tag_router: List of (tag, router) pairs.
        :param router_conv: List of (router, endpoint, conversation) triples.
        """
        rt = RoutingTable()
        for channel, conv in channel_conv:
            channel_conn = channel.get_connector()
            conv_conn = conv.get_connector()
            rt.add_entry(channel_conn, 'default', conv_conn, 'default')
            rt.add_entry(conv_conn, 'default', channel_conn, 'default')

        for channel, router in channel_router:
            channel_conn = channel.get_connector()
            rin_conn = router.get_inbound_connector()
            rt.add_entry(channel_conn, 'default', rin_conn, 'default')
            rt.add_entry(rin_conn, 'default', channel_conn, 'default')

        for router, endpoint, conv in router_conv:
            rout_conn = router.get_outbound_connector()
            conv_conn = conv.get_connector()
            rt.add_entry(rout_conn, endpoint, conv_conn, 'default')
            rt.add_entry(conv_conn, 'default', rout_conn, endpoint)

        self.assertEqual(self.user_helper.user_api.get_routing_table(), rt)
コード例 #4
0
    def test_setup_routing(self):
        self.command.setup_tagpools(self.tagpool_file.name)
        account_info = self.read_yaml(self.account_1_file)
        user = self.command.setup_account(account_info['account'])

        self.command.setup_routing(user, account_info)

        routing_table = vumi_api_for_user(user).get_routing_table()
        self.assertEqual(
            routing_table,
            RoutingTable({
                u'TRANSPORT_TAG:pool1:default0': {
                    u'default': [u'CONVERSATION:survey:conv1', u'default'],
                },
                u'CONVERSATION:survey:conv1': {
                    u'default': [u'TRANSPORT_TAG:pool1:default0', u'default'],
                },
                u'TRANSPORT_TAG:pool1:default1': {
                    u'default':
                    [u'ROUTER:keyword:router1:INBOUND', u'default'],
                },
                u'ROUTER:keyword:router1:INBOUND': {
                    u'default': [u'TRANSPORT_TAG:pool1:default1', u'default'],
                },
                u'ROUTER:keyword:router1:OUTBOUND': {
                    u'default': [u'CONVERSATION:wikipedia:conv2', u'default'],
                },
                u'CONVERSATION:wikipedia:conv2': {
                    u'default':
                    [u'ROUTER:keyword:router1:OUTBOUND', u'default'],
                },
            }))
コード例 #5
0
ファイル: old_models.py プロジェクト: linkedinyou/vumi-go
class UserAccountV4(Model):
    """A user account."""

    VERSION = 4

    # key is uuid
    username = Unicode(max_length=255)
    # TODO: tagpools can be made OneToMany once vumi.persist.fields
    #       gains a OneToMany field
    tagpools = ManyToMany(UserTagPermissionVNone)
    applications = ManyToMany(UserAppPermissionVNone)
    created_at = Timestamp(default=datetime.utcnow)
    event_handler_config = Json(default=list)
    msisdn = Unicode(max_length=255, null=True)
    confirm_start_conversation = Boolean(default=False)
    can_manage_optouts = Boolean(default=False)
    email_summary = Unicode(max_length=255, null=True)
    tags = Json(default=[])
    routing_table = RoutingTableField(default=RoutingTable({}))

    @Manager.calls_manager
    def has_tagpool_permission(self, tagpool):
        for tp_bunch in self.tagpools.load_all_bunches():
            for tp in (yield tp_bunch):
                if tp.tagpool == tagpool:
                    returnValue(True)
        returnValue(False)
コード例 #6
0
ファイル: test_api.py プロジェクト: linkedinyou/vumi-go
    def _set_routing_table(self, user, entries):
        # Each entry is a tuple of (src, dst) where src and dst are
        # conversations, tags or connector strings.
        routing_table = RoutingTable()
        user.routing_table = routing_table

        def mkconn(thing):
            if isinstance(thing, basestring):
                return GoConnector.parse(thing)
            else:
                # Assume it's a conversation/channel/router.
                return thing.get_connector()

        for src, dst in entries:
            routing_table.add_entry(mkconn(src), "default", mkconn(dst),
                                    "default")
コード例 #7
0
ファイル: test_api.py プロジェクト: TouK/vumi-go
    def _set_routing_table(self, user, entries):
        # Each entry is a tuple of (src, dst) where src and dst are
        # conversations, tags or connector strings.
        routing_table = RoutingTable()
        user.routing_table = routing_table

        def mkconn(thing):
            if isinstance(thing, basestring):
                return GoConnector.parse(thing)
            else:
                # Assume it's a conversation/channel/router.
                return thing.get_connector()

        for src, dst in entries:
            routing_table.add_entry(
                mkconn(src), "default", mkconn(dst), "default")
コード例 #8
0
ファイル: test_api.py プロジェクト: linkedinyou/vumi-go
    def test_release_tag_with_routing_entries(self):
        [tag1] = yield self.vumi_helper.setup_tagpool(u"pool1", [u"1234"])
        yield self.user_helper.add_tagpool_permission(u"pool1")
        yield self.assert_account_tags([])
        yield self.user_api.acquire_specific_tag(tag1)
        yield self.assert_account_tags([list(tag1)])

        conv = yield self.user_api.new_conversation(u'bulk_message', u'name',
                                                    u'desc', {})
        channel = yield self.user_api.get_channel(tag1)
        user = yield self.user_api.get_user_account()
        self._set_routing_table(user, [(conv, channel), (channel, conv)])
        yield user.save()

        self.assertNotEqual(RoutingTable(),
                            (yield self.user_api.get_routing_table()))
        yield self.user_api.release_tag(tag1)
        yield self.assert_account_tags([])
        self.assertEqual(RoutingTable(),
                         (yield self.user_api.get_routing_table()))
コード例 #9
0
    def setup_routing(self, user, account_objects):
        connectors = {}
        for conv in account_objects['conversations']:
            connectors[conv['key']] = GoConnector.for_conversation(
                conv['conversation_type'], conv['key'])
        for tag in account_objects['channels']:
            connectors[tag] = GoConnector.for_transport_tag(*(tag.split(':')))
        for router in account_objects['routers']:
            connectors[router['key'] + ':INBOUND'] = GoConnector.for_router(
                router['router_type'], router['key'], GoConnector.INBOUND)
            connectors[router['key'] + ':OUTBOUND'] = GoConnector.for_router(
                router['router_type'], router['key'], GoConnector.OUTBOUND)

        rt = RoutingTable()
        for src, src_ep, dst, dst_ep in account_objects['routing_entries']:
            rt.add_entry(
                str(connectors[src]), src_ep, str(connectors[dst]), dst_ep)

        user_account = vumi_api_for_user(user).get_user_account()
        user_account.routing_table = rt
        user_account.save()

        self.stdout.write('Routing table for %s built\n' % (user.email,))
コード例 #10
0
ファイル: test_api.py プロジェクト: linkedinyou/vumi-go
    def test_get_routing_table(self):
        conv = yield self._setup_routing_table_test_new_conv()
        channel = yield self.user_api.get_channel((u'pool1', u'1234'))
        user = yield self.user_api.get_user_account()
        self._set_routing_table(user, [(conv, channel), (channel, conv)])
        yield user.save()
        routing_table = yield self.user_api.get_routing_table()
        self.assertEqual(
            routing_table,
            RoutingTable({
                u':'.join([u'CONVERSATION:bulk_message', conv.key]): {
                    u'default': [u'TRANSPORT_TAG:pool1:1234', u'default']
                },
                u'TRANSPORT_TAG:pool1:1234': {
                    u'default':
                    [u'CONVERSATION:bulk_message:%s' % conv.key, u'default']
                },
            }))

        # TODO: This belongs in a different test.
        yield conv.archive_conversation()

        routing_table = yield self.user_api.get_routing_table()
        self.assertEqual(routing_table, RoutingTable())
コード例 #11
0
 def make_rt(self, routing_table=None):
     if routing_table is None:
         routing_table = copy.deepcopy(self.DEFAULT_ROUTING)
     return RoutingTable(routing_table)
コード例 #12
0
ファイル: test_api.py プロジェクト: linkedinyou/vumi-go
 def test_get_empty_routing_table(self):
     routing_table = yield self.user_api.get_routing_table()
     self.assertEqual(RoutingTable(), routing_table)
コード例 #13
0
 def handle_clear(self, user_api, options):
     account = user_api.get_user_account()
     account.routing_table = RoutingTable()
     account.save()
     self.stdout.write("Routing table cleared.\n")
コード例 #14
0
ファイル: fields.py プロジェクト: linkedinyou/vumi-go
 def custom_from_riak(self, raw_value):
     return RoutingTable(raw_value)