Esempio n. 1
0
    def test_02_view(self):
        global factory
        peers = ["ViewDocument", "DocumentCache", "DocumentDatabase", "CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        CredentialsParty()

        d = defer.Deferred()

        def callback(value):
            if value:
                d.callback(value)

        from wallaby.pf.peer.viewer import Viewer

        Viewer("room01", callback, "text")

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        from wallaby.pf.peer.editDocument import EditDocument

        room = House.get("room01")
        room.throw(EditDocument.In.Load, self._docId)

        value = yield d
        self.assertEqual(value, "Hello World!")

        House.destroyRoom("room01")
        House.destroyRoom("__CREDENTIALS__")
Esempio n. 2
0
    def test_03_edit(self):
        global factory
        peers = ["EditDocument", "DocumentCache", "DocumentDatabase", "CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        CredentialsParty()

        valueDeferred = defer.Deferred()

        def valueCallback(value):
            if value == "Hello Jan":
                try:
                    valueDeferred.callback(value)
                except:
                    pass

        setRODeferred = defer.Deferred()

        def roCallback(readOnly):
            if not readOnly:
                try:
                    setRODeferred.callback(readOnly)
                except:
                    pass

        from wallaby.pf.peer.viewer import Viewer
        from wallaby.pf.peer.editor import Editor

        Viewer("room01", valueCallback, "text")
        editor = Editor("room01", path="text", setReadOnlyCallback=roCallback)

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        from wallaby.pf.peer.editDocument import EditDocument

        room = House.get("room01")
        room.throw(EditDocument.In.LoadAndEdit, self._docId)

        yield setRODeferred
        editor.changeValue("Hello Jan")

        value = yield valueDeferred
        self.assertEqual(value, "Hello Jan")

        room.throw(EditDocument.In.Save, self._docId)

        from wallaby.pf.peer.database import Database

        docId = yield room.catchNow(Database.Out.DocumentSaved)
        self.assertEqual(docId, self._docId)

        doc = yield self._db.get(self._docId)
        self.assertEqual(doc["text"], "Hello Jan")

        House.destroyRoom("room01")
        House.destroyRoom("__CREDENTIALS__")
Esempio n. 3
0
    def test_01_database(self):
        global factory
        peers = ["CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        d = defer.Deferred()

        room = House.get("room01")

        from wallaby.pf.peer.database import Database

        room.catch(Database.Out.RequestedDocument, lambda *args: d.callback(args))
        room.throw(Database.In.RequestDocument, self._docId)

        pillow, doc = yield d
        self.assertEqual(doc.documentID, self._docId)

        House.destroyRoom("room01")