import unittest
import os
from janrain.capture import Api, config, JanrainConfigError

class TestConfig(unittest.TestCase):
    def setUp(self):
        # use the config file in this directory for config tests
        this_dir = os.path.dirname(os.path.abspath(__file__))
        config_file = os.path.join(this_dir, "janrain-config")
        self.old_env = None
        if 'JANRAIN_CONFIG' in os.environ:
            self.old_env = os.environ['JANRAIN_CONFIG']
        os.environ['JANRAIN_CONFIG'] = config_file

    def test_clusters(self):
        # test referencing clusters
        cluster = config.get_cluster("dev")
        self.assertIn('client_id', cluster)

        # get_client() should merge the cluster if it is referenced instead of
        # an explicit client_id and client_secret
        client = config.get_client("cluster-client")
        self.assertEqual(client['client_id'], cluster['client_id'])

    def test_defaults(self):
        # test convenience funcitons for getting defaults
        clients = []
        clients.append(config.default_client())
        for client in clients:
            self.assertIn('client_id', client)
            self.assertIn('client_secret', client)
            self.assertIn('apid_uri', client)

    def test_resolving_keys(self):
        # test resolving keys using dot-notation
        client = config.get_settings_at_path("some.arbitrary.path")
        self.assertEqual(client['foo'], "bar")

        with self.assertRaises(JanrainConfigError):
            config.get_settings_at_path("foo.bar")

    def tearDown(self):
        # restore environment vars for remaining tests
        del os.environ['JANRAIN_CONFIG']
        if self.old_env:
            os.environ['JANRAIN_CONFIG'] = self.old_env

@@ -1244,16 +1244,228 @@
 lient)%0A%0A
+    def test_settings(self):%0A        # test looking up clusters or clients without specifying which%0A        settings = config.get_settings('dev')%0A        self.assertEqual(settings%5B'client_id'%5D, %22dev client_id%22)%0A%0A
     def 

test get_settings()