def add_server(self, profile_name, display_name, host=None, addr=None, port=6600, timeout=2.0, music_directory=None, password=None):
        info = {
            key: value for key, value in dict(
                host=host or addr,
                addr=addr or host,
                port=port,
                display_name=display_name,
                timeout=timeout,
                music_directory=music_directory
            ).items() if value is not None
        }

        Profile.add_profile(self, profile_name, overwrite=True, initial_value=info)
    def __init__(self, config):
        config.add_defaults({
            'server_profile_active': 'default',
            'server_profile': {}
        })
        Profile.__init__(
                self, config,
                root='server_profile',
                current_profile_key=config.get('server_profile_active')
        )

        # Fill the properties by some meta-programming
        self._create_properties()
Example #3
0
 def setUp(self):
     self.cfg = Config()
     #self.cfg.load(TEST_CONFIG)
     self.cfg.add_defaults({
         'root': {},
         'current_profile': 'default'
     })
     self.profile = Profile(self.cfg, 'root', 'current_profile')
Example #4
0
class TestProfile(unittest.TestCase):
    def setUp(self):
        self.cfg = Config()
        #self.cfg.load(TEST_CONFIG)
        self.cfg.add_defaults({
            'root': {},
            'current_profile': 'default'
        })
        self.profile = Profile(self.cfg, 'root', 'current_profile')

    def test_basic(self):
        # just to check if everthing still works if all profiles were deleted
        for i in range(1):
            # Test the basic functions
            value = {'value': 42}
            self.profile.set('value', 21)
            self.assertEqual(self.profile.get('value'), 21)
            self.profile.add_profile('hello_world', initial_value=value)
            self.profile.current_profile = 'hello_world'
            self.assertEqual(self.profile.current_profile, 'hello_world')
            self.assertEqual(self.profile.get('value'), 42)

            # This should switch to the default profile automaticallyy6
            self.profile.delete_profile('hello_world')
            self.assertEqual(self.profile.current_profile, 'default')
            self.assertEqual(self.profile.get('value'), 21)
            self.profile.delete_profile('default')
            self.assertEqual(self.profile.get('value'), None)

            # Now hijack the system a bit, change the config setting
            # directly and see if the profile reacts accordingly
            self.profile.add_profile('default', initial_value=value)
            self.profile.set('value', 21)
            self.profile.add_profile('another_one', initial_value={'ancient_gods': 3})
            self.cfg.set('current_profile', 'another_one')
            self.assertEqual(self.profile.get('ancient_gods'), 3)