def test_delete(self):
     self.test_new()
     e = ZVent(ztype=events.MESG_DELETE, data={"id": TestMessage.id, "user": TestMessage.user_id})
     ZVent.publish(e)
     m = Message()
     m.load(TestMessage.id)
     assert m.deleted == True
    def test_new_user(self):

        e = ZVent(ztype=events.NEW_USER, data={"id": TestUser.id, "name": TestUser.name})
        ZVent.publish(e)
        u = User()
        u.load(TestUser.id)
        assert u.id == TestUser.id, "expect id to be %s but it was %s" % (TestUser.id, u.id)
        assert u.name == TestUser.name
 def test_delete(self):
     self.test_new()
     e = ZVent(ztype=events.MESG_DELETE, data={'id':TestMessage.id,
         'user':TestMessage.user_id})
     ZVent.publish(e)
     m = Message()
     m.load(TestMessage.id)
     assert m.deleted == True
 def test_change_name(self):
     self.test_new_user()
     new_name = "bar"
     e = ZVent(ztype=events.CHANGE_USER_NAME, data={"id": TestUser.id, "new_name": new_name})
     ZVent.publish(e)
     u = User()
     u.load(TestUser.id)
     assert u.name == new_name
 def test_register(self):
     def t(e):
         pass
     k = 'test:1'
     ZVent.register(k, t)
     assert ZVent.MAP.has_key(k)
     assert len(ZVent.MAP[k]) == 1
     assert ZVent.MAP[k][0] == t
 def test_change_name(self):
     self.test_new_user()
     new_name = 'bar'
     e = ZVent(ztype=events.CHANGE_USER_NAME, data={'id':TestUser.id, 
         'new_name':new_name})
     ZVent.publish(e)
     u = User()
     u.load(TestUser.id)
     assert u.name == new_name
 def test_update(self):
     self.test_new()
     new_text = "foo the bar out of here"
     e = ZVent(ztype=events.MESG_NEW, data={"id": TestMessage.id, "text": new_text, "user": TestMessage.user_id})
     ZVent.publish(e)
     m = Message()
     m.load(TestMessage.id)
     assert m.id == TestMessage.id, "expect id to be %s but it was %s" % (TestMessage.id, u.id)
     assert m.text == new_text
    def test_register(self):
        def t(e):
            pass

        k = 'test:1'
        ZVent.register(k, t)
        assert ZVent.MAP.has_key(k)
        assert len(ZVent.MAP[k]) == 1
        assert ZVent.MAP[k][0] == t
    def test_new(self):

        e = ZVent(ztype=events.MESG_NEW, data={'id':TestMessage.id, 
            'text':TestMessage.text, 'user':TestMessage.user_id})
        ZVent.publish(e)
        m = Message()
        m.load(TestMessage.id)
        assert m.id == TestMessage.id, 'expect id to be %s but it was %s' % (
                TestMessage.id, u.id)
        assert m.text == TestMessage.text
    def test_new_user(self):

        e = ZVent(ztype=events.NEW_USER, data={'id':TestUser.id, 
            'name':TestUser.name})
        ZVent.publish(e)
        u = User()
        u.load(TestUser.id)
        assert u.id == TestUser.id, 'expect id to be %s but it was %s' % (
                TestUser.id, u.id)
        assert u.name == TestUser.name
    def test_publish(self):
        def t(e):
            data['foo'] = 'bar'

        data = {'foo':'foo'}
        k = 'test:2'
        ZVent.register(k, t)
        ze = ZVent(ztype=k, data=data)
        ZVent.publish(ze)
        assert data['foo'] == 'bar'
    def test_new(self):

        e = ZVent(
            ztype=events.MESG_NEW, data={"id": TestMessage.id, "text": TestMessage.text, "user": TestMessage.user_id}
        )
        ZVent.publish(e)
        m = Message()
        m.load(TestMessage.id)
        assert m.id == TestMessage.id, "expect id to be %s but it was %s" % (TestMessage.id, u.id)
        assert m.text == TestMessage.text
    def test_publish(self):
        def t(e):
            data['foo'] = 'bar'

        data = {'foo': 'foo'}
        k = 'test:2'
        ZVent.register(k, t)
        ze = ZVent(ztype=k, data=data)
        ZVent.publish(ze)
        assert data['foo'] == 'bar'
 def test_update(self):
     self.test_new()
     new_text = 'foo the bar out of here'
     e = ZVent(ztype=events.MESG_NEW, data={'id':TestMessage.id, 
         'text':new_text, 'user':TestMessage.user_id})
     ZVent.publish(e)
     m = Message()
     m.load(TestMessage.id)
     assert m.id == TestMessage.id, 'expect id to be %s but it was %s' % (
             TestMessage.id, u.id)
     assert m.text == new_text
Ejemplo n.º 15
0
    def get_events(self, id):
        path = self.path(id)
        l = []
        if os.path.exists(path):
            re = loads(open(path).read())
            for e in re:

                e = loads(e)  # String to dict conversion
                # Create a proper event object from the dictionary
                l.append(ZVent(ztype=e['ztype'], data=e['data']))
        return l
Ejemplo n.º 16
0
    """
    The user event handlers are implemented on the class so 
    we don't really need much to see here. Basically we need to 
    do 3 steps:
        * First load the User object so that it is the current state
        * Save the event to the datastore
        * Apply it to update the current state
    """
    u = User()
    u.load(e.data['id'])
    u.save(e)
    u.apply(e)

# Maps the all events that the User class is handling
for k in User.apply_map.keys():
    ZVent.register(k, handle_user_event)




class Message(Storage):
    namespace = 'message' # Base directory could be bucket or table name
    
    def __init__(self):
        Storage.__init__(self)

        self.id = None
        self.user_id = None
        self.text = None
        self.deleted = None
Ejemplo n.º 17
0
    The user event handlers are implemented on the class so 
    we don't really need much to see here. Basically we need to 
    do 3 steps:
        * First load the User object so that it is the current state
        * Save the event to the datastore
        * Apply it to update the current state
    """
    u = User()
    u.load(e.data['id'])
    u.save(e)
    u.apply(e)


# Maps the all events that the User class is handling
for k in User.apply_map.keys():
    ZVent.register(k, handle_user_event)


class Message(Storage):
    namespace = 'message'  # Base directory could be bucket or table name

    def __init__(self):
        Storage.__init__(self)

        self.id = None
        self.user_id = None
        self.text = None
        self.deleted = None

    def new(self, e):
        self.id = e.data['id']
 def set_up(self):
     """
     Make sure there is nothing in the even system before running tests.
     """
     ZVent.clear()
 def set_up(self): 
     """
     Make sure there is nothing in the even system before running tests.
     """
     ZVent.clear()