Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add helpers for accessing entire config.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Nov 21, 2013
1 parent 4c46464 commit 243967b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions go/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
sort.
"""

import copy

from go.errors import UnknownConversationType, UnknownRouterType


Expand All @@ -16,6 +18,10 @@ def configured_conversation_types():
for a in _VUMI_INSTALLED_APPS.itervalues())


def configured_conversations():
return copy.deepcopy(_VUMI_INSTALLED_APPS)


def obsolete_conversation_types():
return set(_VUMI_OBSOLETE_APPS)

Expand All @@ -25,6 +31,10 @@ def configured_router_types():
for a in _VUMI_INSTALLED_ROUTERS.itervalues())


def configured_routers():
return copy.deepcopy(_VUMI_INSTALLED_ROUTERS)


def obsolete_router_types():
return set(_VUMI_OBSOLETE_ROUTERS)

Expand Down
15 changes: 15 additions & 0 deletions go/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_conversation_pkg, get_router_pkg,
get_conversation_definition, get_router_definition,
configured_conversation_types, configured_router_types,
configured_conversations, configured_routers,
obsolete_conversation_types, obsolete_router_types)
from go.errors import UnknownConversationType, UnknownRouterType

Expand All @@ -15,6 +16,13 @@ def test_configured_conversation_types(self):
conv_types = configured_conversation_types()
self.assertEqual(conv_types['bulk_message'], 'Group Message')

def test_configured_conversations(self):
convs = configured_conversations()
self.assertEqual(convs['go.apps.bulk_message'], {
'namespace': 'bulk_message',
'display_name': 'Group Message',
})

def test_obsolete_conversation_types(self):
obsolete_types = obsolete_conversation_types()
self.assertEqual(obsolete_types, set([
Expand Down Expand Up @@ -46,6 +54,13 @@ def test_configured_router_types(self):
conv_types = configured_router_types()
self.assertEqual(conv_types['keyword'], 'Keyword')

def test_configured_routers(self):
routers = configured_routers()
self.assertEqual(routers['go.routers.keyword'], {
'namespace': 'keyword',
'display_name': 'Keyword',
})

def test_obsolete_router_types(self):
obsolete_types = obsolete_router_types()
self.assertEqual(obsolete_types, set([
Expand Down
8 changes: 5 additions & 3 deletions go/vumitools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from vumi.persist.txredis_manager import TxRedisManager
from vumi import log

from go.config import (
configured_conversations,
configured_routers)
from go.vumitools.account import AccountStore
from go.vumitools.channel import ChannelStore
from go.vumitools.contact import ContactStore
Expand All @@ -29,7 +32,6 @@
from go.vumitools.credit import CreditManager
from go.vumitools.token_manager import TokenManager

from django.conf import settings
from django.utils.datastructures import SortedDict

from vumi.message import TransportUserMessage
Expand Down Expand Up @@ -230,7 +232,7 @@ def applications(self):
app_permissions.extend((yield permissions))
applications = [permission.application for permission
in app_permissions]
app_settings = settings.VUMI_INSTALLED_APPS
app_settings = configured_conversations()
returnValue(SortedDict([(application,
app_settings[application])
for application in sorted(applications)
Expand All @@ -240,7 +242,7 @@ def applications(self):
def router_types(self):
# TODO: Permissions.
yield None
router_settings = settings.VUMI_INSTALLED_ROUTERS
router_settings = configured_routers()
returnValue(SortedDict([(router_type, router_settings[router_type])
for router_type in sorted(router_settings)]))

Expand Down

0 comments on commit 243967b

Please sign in to comment.