Exemplo n.º 1
0
class TestConfig(unittest.TestCase):
    
    def setUp(self):
        ini = tempfile.NamedTemporaryFile()
        ini.write(TEST_INI)
        ini.flush()
        ini.seek(0)
        self.config = Config(ini.name)
        ini.close()

    def test___init__(self):
        pass

    def test_component_section(self):
        s = self.config.app_section("app1")
        self.assertEqual(s, {}, 
            "default (empty) app config incorrect")
        
        s = self.config.app_section("app2")
        self.assertEqual(s, {"beginning": "yes", "end": "no"}, 
            "does not correctly configure component additional vars")
        
        s = self.config.backend_section("backend1")
        self.assertEqual(s, {"type": "testbackend", "beginning": "yes", "end": "no"}, 
            "does not correctly configure component with explicit type var and additional vars")

    def test_parse_rapidsms_section(self):
        rs = self.config.data["rapidsms"]
        self.assertEqual(type(rs), type({}),
            "function does not return correct type")
        self.assertTrue(rs.has_key("apps"),
            "'rapidsms' section does not contain 'apps' key")
        self.assertTrue(rs.has_key("backends"),
            "'rapidsms' section does not contain 'backends' key")

    def test_parse_log_section(self):
        ls = self.config.data["log"]
        self.assertEqual(ls["level"], "critical",
            "config does not update log level correctly")
        self.assertEqual(ls["file"], "/tmp/test.log",
            "config does not update log file correctly")

    def test___getitem__(self):
        self.assertEquals(type(self.config["rapidsms"]), type({}),
            "config does not return the correct type from __getitem__")

    def test_has_key(self):
        self.assertTrue(self.config.has_key("rapidsms"),
            "config does not have a key that it should have")
        self.assertFalse(self.config.has_key("bogus"),
            "config has a key that it should not have")

    def test___contains__(self):
        self.assertTrue("rapidsms" in self.config, 
            "config does not contain a section that it should")
        self.assertFalse("bogus" in self.config, 
            "config contains a section that it should not have")
Exemplo n.º 2
0
 def setUp(self):
     ini = tempfile.NamedTemporaryFile()
     ini.write(TEST_INI)
     ini.flush()
     ini.seek(0)
     self.config = Config(ini.name)
     ini.close()
Exemplo n.º 3
0
class TestConfig(unittest.TestCase):
    def setUp(self):
        fd, path = tempfile.mkstemp()
        ini = os.fdopen(fd, "w")
        ini.write(TEST_INI)
        ini.close()
        self.config = Config(path)

    def test___init__(self):
        pass

    def test_component_section(self):
        cc = self.config.component_section("app1")
        self.assertEqual(cc, {"type": "app1"}, "default component config incorrect")

        cc = self.config.component_section("app2")
        self.assertEqual(
            cc,
            {"type": "app2", "beginning": "yes", "end": "no"},
            "does not correctly configure component with assumed type var and additional vars",
        )

        cc = self.config.component_section("app3")
        self.assertEqual(
            cc,
            {"type": "testapp"},
            "does not correctly configure component with explicit type variable and no additional vars",
        )

        cc = self.config.component_section("backend1")
        self.assertEqual(
            cc,
            {"type": "testbackend", "beginning": "yes", "end": "no"},
            "does not correctly configure component with explicit type var and additional vars",
        )

    def test_parse_rapidsms_section(self):
        rs = self.config.data["rapidsms"]
        self.assertEqual(type(rs), type({}), "function does not return correct type")
        self.assertTrue(rs.has_key("apps"), "'rapidsms' section does not contain 'apps' key")
        self.assertTrue(rs.has_key("backends"), "'rapidsms' section does not contain 'backends' key")

    def test_parse_log_section(self):
        ls = self.config.data["log"]
        self.assertEqual(ls["level"], "critical", "config does not update log level correctly")
        self.assertEqual(ls["file"], "/tmp/test.log", "config does not update log file correctly")

    def test___getitem__(self):
        self.assertEquals(
            type(self.config["rapidsms"]), type({}), "config does not return the correct type from __getitem__"
        )

    def test_has_key(self):
        self.assertTrue(self.config.has_key("rapidsms"), "config does not have a key that it should have")
        self.assertFalse(self.config.has_key("bogus"), "config has a key that it should not have")

    def test___contains__(self):
        self.assertTrue("rapidsms" in self.config, "config does not contain a section that it should")
        self.assertFalse("bogus" in self.config, "config contains a section that it should not have")
Exemplo n.º 4
0
# this module will usually be called up via the django
# reloader, which is (in turn) called up by rapidsms's
# server.py, which adds RAPIDSMS_INI to the environment.
# just in case, though, check that it's defined rather
# than repeating the filename selection logic here
if not "RAPIDSMS_INI" in os.environ:
    raise(
        EnvironmentError,
        "The RAPIDSMS_INI environment variable is not "  +\
        "defined. Without it, settings.py doesn't know " +\
        "which ini file to load settings from")

# load the rapidsms configuration
from rapidsms import Config
RAPIDSMS_CONF = Config(os.environ["RAPIDSMS_INI"])

# since iterating and reading the config of apps is
# common, build a handy dict of apps and their configs
RAPIDSMS_APPS = dict([(app["type"], app)
                      for app in RAPIDSMS_CONF["rapidsms"]["apps"]])

# this code bootstraps the i18n logic configuration, if
# it is in the settings


def _i18n_to_django_setting(language_settings):
    languages = []
    for language in language_settings:
        if len(language) >= 2:
            languages.append((language[0], language[1]))
Exemplo n.º 5
0
 def setUp(self):
     fd, path = tempfile.mkstemp()
     ini = os.fdopen(fd, "w")
     ini.write(TEST_INI)
     ini.close()
     self.config = Config(path)
Exemplo n.º 6
0
 def setUp(self):
     fd, path = tempfile.mkstemp()
     ini = os.fdopen(fd, 'w')
     ini.write(TEST_INI)
     ini.close()
     self.config = Config(path)
Exemplo n.º 7
0
class TestConfig(unittest.TestCase):
    def setUp(self):
        fd, path = tempfile.mkstemp()
        ini = os.fdopen(fd, 'w')
        ini.write(TEST_INI)
        ini.close()
        self.config = Config(path)

    def test___init__(self):
        pass

    def test_component_section(self):
        cc = self.config.component_section("app1")
        self.assertEqual(cc, {"type": "app1"},
                         "default component config incorrect")

        cc = self.config.component_section("app2")
        self.assertEqual(
            cc, {
                "type": "app2",
                "beginning": "yes",
                "end": "no"
            },
            "does not correctly configure component with assumed type var and additional vars"
        )

        cc = self.config.component_section("app3")
        self.assertEqual(
            cc, {"type": "testapp"},
            "does not correctly configure component with explicit type variable and no additional vars"
        )

        cc = self.config.component_section("backend1")
        self.assertEqual(
            cc, {
                "type": "testbackend",
                "beginning": "yes",
                "end": "no"
            },
            "does not correctly configure component with explicit type var and additional vars"
        )

    def test_parse_rapidsms_section(self):
        rs = self.config.data["rapidsms"]
        self.assertEqual(type(rs), type({}),
                         "function does not return correct type")
        self.assertTrue(rs.has_key("apps"),
                        "'rapidsms' section does not contain 'apps' key")
        self.assertTrue(rs.has_key("backends"),
                        "'rapidsms' section does not contain 'backends' key")

    def test_parse_log_section(self):
        ls = self.config.data["log"]
        self.assertEqual(ls["level"], "critical",
                         "config does not update log level correctly")
        self.assertEqual(ls["file"], "/tmp/test.log",
                         "config does not update log file correctly")

    def test___getitem__(self):
        self.assertEquals(
            type(self.config["rapidsms"]), type({}),
            "config does not return the correct type from __getitem__")

    def test_has_key(self):
        self.assertTrue(self.config.has_key("rapidsms"),
                        "config does not have a key that it should have")
        self.assertFalse(self.config.has_key("bogus"),
                         "config has a key that it should not have")

    def test___contains__(self):
        self.assertTrue("rapidsms" in self.config,
                        "config does not contain a section that it should")
        self.assertFalse("bogus" in self.config,
                         "config contains a section that it should not have")