Example #1
0
class TestConfigObject(unittest.TestCase):
    def setUp(self):
        self.config = Config(the_reactor)
    
    # TODO: In type error tests, also check message once we've cleaned them up.
    
    # --- General functionality ---
    
    def test_reactor(self):
        self.assertEqual(self.config.reactor, the_reactor)
    
    # TODO def test_wait_for(self):
    
    @defer.inlineCallbacks
    def test_validate_succeed(self):
        self.config.devices.add(u'foo', StubDevice())
        d = self.config._wait_and_validate()
        self.assertIsInstance(d, defer.Deferred)  # don't succeed trivially
        yield d
    
    # TODO: Test "No network service defined"; is a warning not an error

    # --- Persistence ---
    
    @defer.inlineCallbacks
    def test_persist_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.persist_to_file('foo'))
        self.assertEqual({}, self.config.devices._values)
    
    def test_persist_none(self):
        self.assertEqual(None, self.config._state_filename)

    def test_persist_ok(self):
        self.config.persist_to_file('foo')
        self.assertEqual('foo', self.config._state_filename)

    def test_persist_duplication(self):
        self.config.persist_to_file('foo')
        self.assertRaises(ValueError, lambda: self.config.persist_to_file('bar'))
        self.assertEqual('foo', self.config._state_filename)

    # --- Devices ---
    
    @defer.inlineCallbacks
    def test_device_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({}, self.config.devices._values)
    
    def test_device_key_ok(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))
    
    def test_device_key_string_ok(self):
        dev = StubDevice()
        self.config.devices.add('foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))
    
    def test_device_key_type(self):
        self.assertRaises(TypeError, lambda:
            self.config.devices.add(StubDevice(), StubDevice()))
        self.assertEqual({}, self.config.devices._values)
    
    def test_device_key_duplication(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertRaises(KeyError, lambda:
            self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({u'foo': dev}, self.config.devices._values)
    
    def test_device_empty(self):
        self.assertRaises(ValueError, lambda:
            self.config.devices.add(u'foo'))
        self.assertEqual({}, self.config.devices._values)
    
    # --- serve_web ---
    
    @defer.inlineCallbacks
    def test_web_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101'))
        self.assertEqual({}, self.config.devices._values)
    
    def test_web_ok(self):
        self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101')
        self.assertEqual(1, len(self.config._service_makers))
    
    def test_web_root_cap_empty(self):
        self.assertRaises(ValueError, lambda:
            self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101', root_cap=''))
        self.assertEqual([], self.config._service_makers)
    
    # --- serve_ghpsdr ---
    
    @defer.inlineCallbacks
    def test_ghpsdr_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.serve_ghpsdr())
        self.assertEqual({}, self.config.devices._values)
    
    def test_ghpsdr_ok(self):
        self.config.serve_ghpsdr()
        self.assertEqual(1, len(self.config._service_makers))
    
    # --- Misc options ---
    
    @defer.inlineCallbacks
    def test_server_audio_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.set_server_audio_allowed(True))
        self.assertEqual({}, self.config.devices._values)
    
    # TODO test rest of config.set_server_audio_allowed

    @defer.inlineCallbacks
    def test_stereo_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda:
            self.config.set_stereo(True))
        self.assertEqual({}, self.config.devices._values)
Example #2
0
class TestConfigObject(unittest.TestCase):
    def setUp(self):
        self.config = Config(the_reactor)
    
    # TODO: In type error tests, also check message once we've cleaned them up.
    
    # --- General functionality ---
    
    def test_reactor(self):
        self.assertEqual(self.config.reactor, the_reactor)
    
    # TODO def test_wait_for(self):
    
    @defer.inlineCallbacks
    def test_validate_succeed(self):
        self.config.devices.add(u'foo', StubDevice())
        d = self.config._wait_and_validate()
        self.assertIsInstance(d, defer.Deferred)  # don't succeed trivially
        yield d
    
    # TODO: Test "No network service defined"; is a warning not an error

    # --- Persistence ---
    
    @defer.inlineCallbacks
    def test_persist_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.persist_to_file('foo'))
        self.assertEqual({}, self.config.devices._values)
    
    def test_persist_none(self):
        self.assertEqual(None, self.config._state_filename)

    def test_persist_ok(self):
        self.config.persist_to_file('foo')
        self.assertEqual('foo', self.config._state_filename)

    def test_persist_duplication(self):
        self.config.persist_to_file('foo')
        self.assertRaises(ConfigException, lambda: self.config.persist_to_file('bar'))
        self.assertEqual('foo', self.config._state_filename)

    # --- Devices ---
    
    @defer.inlineCallbacks
    def test_device_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({}, self.config.devices._values)
    
    def test_device_key_ok(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))
    
    def test_device_key_string_ok(self):
        dev = StubDevice()
        self.config.devices.add('foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))
    
    def test_device_key_type(self):
        self.assertRaises(ConfigException, lambda:
            self.config.devices.add(StubDevice(), StubDevice()))
        self.assertEqual({}, self.config.devices._values)
    
    def test_device_key_duplication(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertRaises(ConfigException, lambda:
            self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({u'foo': dev}, self.config.devices._values)
    
    def test_device_empty(self):
        self.assertRaises(ConfigException, lambda:
            self.config.devices.add(u'foo'))
        self.assertEqual({}, self.config.devices._values)
    
    # --- serve_web ---
    
    @defer.inlineCallbacks
    def test_web_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101'))
        self.assertEqual({}, self.config.devices._values)
    
    def test_web_ok(self):
        self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101')
        self.assertEqual(1, len(self.config._service_makers))
    
    def test_web_root_cap_empty(self):
        self.assertRaises(ConfigException, lambda:
            self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101', root_cap=''))
        self.assertEqual([], self.config._service_makers)
    
    def test_web_root_cap_none(self):
        self.config.serve_web(http_endpoint='tcp:0', ws_endpoint='tcp:0')
        self.assertEqual(1, len(self.config._service_makers))
        # Actually instantiating the service. We need to do this to check if the root_cap value was processed correctly.
        service = self.config._service_makers[0](DummyAppRoot())
        self.assertEqual('/public/', service.get_host_relative_url())
    
    # --- serve_ghpsdr ---
    
    @defer.inlineCallbacks
    def test_ghpsdr_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.serve_ghpsdr())
        self.assertEqual({}, self.config.devices._values)
    
    def test_ghpsdr_ok(self):
        self.config.serve_ghpsdr()
        self.assertEqual(1, len(self.config._service_makers))
    
    # --- Misc options ---
    
    @defer.inlineCallbacks
    def test_server_audio_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.set_server_audio_allowed(True))
        self.assertEqual({}, self.config.devices._values)
    
    # TODO test rest of config.set_server_audio_allowed

    @defer.inlineCallbacks
    def test_stereo_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.set_stereo(True))
        self.assertEqual({}, self.config.devices._values)
    
    # TODO test rest of config.set_stereo
    
    # --- Features ---
    
    def test_features_unknown(self):
        self.assertRaises(ConfigException, lambda:
            self.config.features.enable('bogus'))
        self.assertFalse('bogus' in self.config.features._state)
    
    @defer.inlineCallbacks
    def test_features_enable_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.features.enable('_test_disabled_feature'))
        self.assertFalse(self.config.features._get('_test_disabled_feature'))
    
    @defer.inlineCallbacks
    def test_features_disable_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException, lambda:
            self.config.features.enable('_test_enabled_feature'))
        self.assertTrue(self.config.features._get('_test_enabled_feature'))
Example #3
0
class TestConfigObject(unittest.TestCase):
    def setUp(self):
        self.config = Config(the_reactor)

    # TODO: In type error tests, also check message once we've cleaned them up.

    # --- General functionality ---

    def test_reactor(self):
        self.assertEqual(self.config.reactor, the_reactor)

    # TODO def test_wait_for(self):

    @defer.inlineCallbacks
    def test_validate_succeed(self):
        self.config.devices.add(u'foo', StubDevice())
        d = self.config._wait_and_validate()
        self.assertIsInstance(d, defer.Deferred)  # don't succeed trivially
        yield d

    # TODO: Test "No network service defined"; is a warning not an error

    # --- Persistence ---

    @defer.inlineCallbacks
    def test_persist_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException,
                          lambda: self.config.persist_to_file('foo'))
        self.assertEqual({}, self.config.devices._values)

    def test_persist_none(self):
        self.assertEqual(None, self.config._state_filename)

    def test_persist_ok(self):
        self.config.persist_to_file('foo')
        self.assertEqual('foo', self.config._state_filename)

    def test_persist_duplication(self):
        self.config.persist_to_file('foo')
        self.assertRaises(ConfigException,
                          lambda: self.config.persist_to_file('bar'))
        self.assertEqual('foo', self.config._state_filename)

    # --- Devices ---

    @defer.inlineCallbacks
    def test_device_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            ConfigTooLateException,
            lambda: self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({}, self.config.devices._values)

    def test_device_key_ok(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))

    def test_device_key_string_ok(self):
        dev = StubDevice()
        self.config.devices.add('foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))

    def test_device_key_type(self):
        self.assertRaises(
            ConfigException,
            lambda: self.config.devices.add(StubDevice(), StubDevice()))
        self.assertEqual({}, self.config.devices._values)

    def test_device_key_duplication(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertRaises(
            ConfigException,
            lambda: self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({u'foo': dev}, self.config.devices._values)

    def test_device_empty(self):
        self.assertRaises(ConfigException,
                          lambda: self.config.devices.add(u'foo'))
        self.assertEqual({}, self.config.devices._values)

    # --- serve_web ---

    @defer.inlineCallbacks
    def test_web_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            ConfigTooLateException,
            lambda: self.config.serve_web(http_endpoint='tcp:8100',
                                          ws_endpoint='tcp:8101'))
        self.assertEqual({}, self.config.devices._values)

    def test_web_ok(self):
        self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101')
        self.assertEqual(1, len(self.config._service_makers))

    def test_web_root_cap_empty(self):
        self.assertRaises(
            ConfigException, lambda: self.config.serve_web(
                http_endpoint='tcp:8100', ws_endpoint='tcp:8101', root_cap=''))
        self.assertEqual([], self.config._service_makers)

    def test_web_root_cap_none(self):
        self.config.serve_web(http_endpoint='tcp:0', ws_endpoint='tcp:0')
        self.assertEqual(1, len(self.config._service_makers))
        # Actually instantiating the service. We need to do this to check if the root_cap value was processed correctly.
        service = self.config._service_makers[0](DummyAppRoot())
        self.assertEqual('/', service.get_host_relative_url())

    # --- serve_ghpsdr ---

    @defer.inlineCallbacks
    def test_ghpsdr_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException,
                          lambda: self.config.serve_ghpsdr())
        self.assertEqual({}, self.config.devices._values)

    def test_ghpsdr_ok(self):
        self.config.serve_ghpsdr()
        self.assertEqual(1, len(self.config._service_makers))

    # --- Misc options ---

    @defer.inlineCallbacks
    def test_server_audio_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException,
                          lambda: self.config.set_server_audio_allowed(True))
        self.assertEqual({}, self.config.devices._values)

    # TODO test rest of config.set_server_audio_allowed

    @defer.inlineCallbacks
    def test_stereo_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(ConfigTooLateException,
                          lambda: self.config.set_stereo(True))
        self.assertEqual({}, self.config.devices._values)

    # TODO test rest of config.set_stereo

    # --- Features ---

    def test_features_unknown(self):
        self.assertRaises(ConfigException,
                          lambda: self.config.features.enable('bogus'))
        self.assertFalse('bogus' in self.config.features._state)

    @defer.inlineCallbacks
    def test_features_enable_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            ConfigTooLateException,
            lambda: self.config.features.enable('_test_disabled_feature'))
        self.assertFalse(self.config.features._get('_test_disabled_feature'))

    @defer.inlineCallbacks
    def test_features_disable_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            ConfigTooLateException,
            lambda: self.config.features.enable('_test_enabled_feature'))
        self.assertTrue(self.config.features._get('_test_enabled_feature'))
Example #4
0
class TestConfigObject(unittest.TestCase):
    def setUp(self):
        self.config = Config(the_reactor)

    # TODO: In type error tests, also check message once we've cleaned them up.

    # --- General functionality ---

    def test_reactor(self):
        self.assertEqual(self.config.reactor, the_reactor)

    # TODO def test_wait_for(self):

    @defer.inlineCallbacks
    def test_validate_succeed(self):
        self.config.devices.add(u'foo', StubDevice())
        d = self.config._wait_and_validate()
        self.assertIsInstance(d, defer.Deferred)  # don't succeed trivially
        yield d

    # TODO: Test "No network service defined"; is a warning not an error

    # --- Persistence ---

    @defer.inlineCallbacks
    def test_persist_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception,
                          lambda: self.config.persist_to_file('foo'))
        self.assertEqual({}, self.config.devices._values)

    def test_persist_none(self):
        self.assertEqual(None, self.config._state_filename)

    def test_persist_ok(self):
        self.config.persist_to_file('foo')
        self.assertEqual('foo', self.config._state_filename)

    def test_persist_duplication(self):
        self.config.persist_to_file('foo')
        self.assertRaises(ValueError,
                          lambda: self.config.persist_to_file('bar'))
        self.assertEqual('foo', self.config._state_filename)

    # --- Devices ---

    @defer.inlineCallbacks
    def test_device_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            Exception, lambda: self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({}, self.config.devices._values)

    def test_device_key_ok(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))

    def test_device_key_string_ok(self):
        dev = StubDevice()
        self.config.devices.add('foo', dev)
        self.assertEqual({u'foo': dev}, self.config.devices._values)
        self.assertEqual(unicode, type(self.config.devices._values.keys()[0]))

    def test_device_key_type(self):
        self.assertRaises(
            TypeError,
            lambda: self.config.devices.add(StubDevice(), StubDevice()))
        self.assertEqual({}, self.config.devices._values)

    def test_device_key_duplication(self):
        dev = StubDevice()
        self.config.devices.add(u'foo', dev)
        self.assertRaises(
            KeyError, lambda: self.config.devices.add(u'foo', StubDevice()))
        self.assertEqual({u'foo': dev}, self.config.devices._values)

    def test_device_empty(self):
        self.assertRaises(ValueError, lambda: self.config.devices.add(u'foo'))
        self.assertEqual({}, self.config.devices._values)

    # --- serve_web ---

    @defer.inlineCallbacks
    def test_web_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(
            Exception, lambda: self.config.serve_web(http_endpoint='tcp:8100',
                                                     ws_endpoint='tcp:8101'))
        self.assertEqual({}, self.config.devices._values)

    def test_web_ok(self):
        self.config.serve_web(http_endpoint='tcp:8100', ws_endpoint='tcp:8101')
        self.assertEqual(1, len(self.config._service_makers))

    def test_web_root_cap_empty(self):
        self.assertRaises(
            ValueError, lambda: self.config.serve_web(
                http_endpoint='tcp:8100', ws_endpoint='tcp:8101', root_cap=''))
        self.assertEqual([], self.config._service_makers)

    # --- serve_ghpsdr ---

    @defer.inlineCallbacks
    def test_ghpsdr_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda: self.config.serve_ghpsdr())
        self.assertEqual({}, self.config.devices._values)

    def test_ghpsdr_ok(self):
        self.config.serve_ghpsdr()
        self.assertEqual(1, len(self.config._service_makers))

    # --- Misc options ---

    @defer.inlineCallbacks
    def test_server_audio_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception,
                          lambda: self.config.set_server_audio_allowed(True))
        self.assertEqual({}, self.config.devices._values)

    # TODO test rest of config.set_server_audio_allowed

    @defer.inlineCallbacks
    def test_stereo_too_late(self):
        yield self.config._wait_and_validate()
        self.assertRaises(Exception, lambda: self.config.set_stereo(True))
        self.assertEqual({}, self.config.devices._values)