def __addPeer(self, room, name, config):
        if self._state not in ("Edit", "New", "Dirty"):
            from wallaby.qt_combat import QtGui
            import wallaby.FX as FX
            reply = QtGui.QMessageBox.question(FX.mainWindow, 'Edit configuration',
                "You must edit the configuration to add peers. Do you want to edit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

            if reply == QtGui.QMessageBox.Yes:
                from wallaby.pf.peer.editDocument import EditDocument
                self.throw(EditDocument.In.Edit, None)
            else:
                return

        from wallaby.pf.peer.documentChanger import DocumentChanger
        self.throw(DocumentChanger.In.InsertRow, ("rooms.*.Peers", {"name": name, "config": config}))

        from wallaby.pf.room import House

        observer = House.observer()
        cls = observer.peerClass(name)

        try:
            for dep in cls.Dependencies:
                observer = House.observer()
                cls2 = observer.peerClass(dep)

                config = {}
                try:
                    description = cls2.Description
                    if isinstance(description, (list, tuple)):
                        description, config = description
                except: pass

                print "Looking for", dep, "in", House.get(room).allPeers()
                if dep in House.get(room).allPeers():
                    continue

                found = False

                for peer in House.get(room).allPeers():
                    if dep == peer.__class__.__name__: 
                        found = True
                        break

                if found: continue

                self.__addPeer(room, dep, config)
        except: pass
    def initialize(self):
        from wallaby.pf.room import House
        observer = House.observer()

        from wallaby.common.document import Document
        doc = Document()

        peerNames = sorted(observer.allPeers().keys())

        peers = []

        for peer in peerNames:
            ibp = observer.inBoundPillows(peer)
            obp = observer.outBoundPillows(peer)

            peers.append({
                "name": peer,
                "inBound": ibp,
                "outBound": obp
            })

        doc.set("peers", peers)
        self._throw(Viewer.In.Document, doc)
        
        # Wildcard credentials
        from credentials import Credentials
        self._throw(Credentials.Out.Credential, Document())
# Copyright (c) by it's authors.
# Some rights reserved. See LICENSE, AUTHORS.

from twisted.internet import defer, reactor
from twisted.trial import unittest

from wallaby.pf.room import House
from wallaby.pf.peer.peer import Peer
from wallaby.pf.peer.credentialsParty import CredentialsParty

factory = House.observer()


def sleep(time):
    d = defer.Deferred()
    reactor.callLater(time, d.callback, None)
    return d


class WallabyCouchDBTest(unittest.TestCase):
    def setUp(self):
        self._dbName = "wallaby_test"
        self._docId = "testdoc"
        self.timeout = 1

        self._designDoc = {
            "_id": "_design/wallaby_test",
            "language": "javascript",
            "views": {"text": {"map": "function(doc) { if(doc.text)\n   emit(doc.text, null);\n}"}},
            "filters": {
                "typeB": 'function(doc, req) { if((doc.type && doc.type == "typeB") || doc.deleted) { return true; } return false;}'