Example #1
0
    def test_connect_disconnect_connected(self):
        collection = AdapterCollection(DummyAdapter("foo", running=False),
                                       DummyAdapter("bar", running=False))

        # no arguments connects everything
        collection.connect()

        self.assertDictEqual(collection.is_connected(), {
            "bar": True,
            "foo": True
        })
        self.assertTrue(collection.is_connected("bar"))
        self.assertTrue(collection.is_connected("foo"))

        collection.disconnect()

        self.assertDictEqual(collection.is_connected(), {
            "bar": False,
            "foo": False
        })
        self.assertFalse(collection.is_connected("bar"))
        self.assertFalse(collection.is_connected("foo"))

        collection.connect("foo")
        self.assertDictEqual(collection.is_connected(), {
            "bar": False,
            "foo": True
        })
        self.assertFalse(collection.is_connected("bar"))
        self.assertTrue(collection.is_connected("foo"))

        self.assertRaises(RuntimeError, collection.connect, "baz")
        self.assertRaises(RuntimeError, collection.disconnect, "baz")

        collection.disconnect()  # Clean up so that the test does not hang
Example #2
0
    def test_connect_disconnect_connected(self):
        collection = AdapterCollection(
            DummyAdapter('foo', running=False), DummyAdapter('bar', running=False))

        # no arguments connects everything
        collection.connect()

        self.assertDictEqual(collection.is_connected(), {'bar': True, 'foo': True})
        self.assertTrue(collection.is_connected('bar'))
        self.assertTrue(collection.is_connected('foo'))

        collection.disconnect()

        self.assertDictEqual(collection.is_connected(), {'bar': False, 'foo': False})
        self.assertFalse(collection.is_connected('bar'))
        self.assertFalse(collection.is_connected('foo'))

        collection.connect('foo')
        self.assertDictEqual(collection.is_connected(), {'bar': False, 'foo': True})
        self.assertFalse(collection.is_connected('bar'))
        self.assertTrue(collection.is_connected('foo'))

        self.assertRaises(RuntimeError, collection.connect, 'baz')
        self.assertRaises(RuntimeError, collection.disconnect, 'baz')

        collection.disconnect()  # Clean up so that the test does not hang