Ejemplo n.º 1
0
    def test_index(data, self):
        from invenio_accounts.models import User
        from invenio.modules.messages.models import MsgMESSAGE, UserMsgMESSAGE

        users = data.UserData
        admin = User.query.filter(User.nickname.like('admin')).one()
        romeo = User.query.filter(User.nickname.like('romeo')).one()
        juliet = User.query.filter(User.nickname.like('juliet')).one()

        m = MsgMESSAGE()
        m.subject = 'Message 1 Subject'
        m.body = 'body'
        try:
            m.sent_to_user_nicks = 'admin, NOTEXISTS'
        except:
            assert m.sent_to_user_nicks is None
        m.sent_to_user_nicks = ', '.join([users.admin.nickname,
                                          users.romeo.nickname])

        try:
            m.sent_to_user_nicks = 'admin, NOTEXISTS'
        except:
            # Remove unnecessary space
            assert m.sent_to_user_nicks == ','.join([users.admin.nickname,
                                                     users.romeo.nickname])

        m.sent_to_group_names = ''
        m.id_user_from = users.admin.id

        db.session.add(m)
        db.session.commit()

        m = MsgMESSAGE.query.first()
        assert admin in m.recipients
        assert romeo in m.recipients
        assert juliet not in m.recipients

        response = self.login(users.admin.nickname, users.admin.password)
        assert users.admin.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' in response.data
        self.logout()

        response = self.login(users.romeo.nickname, users.romeo.password)
        assert users.romeo.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' in response.data
        self.logout()

        response = self.login(users.juliet.nickname, users.juliet.password)
        assert users.juliet.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' not in response.data
        self.logout()

        # Avoid problems with foreign keys.
        UserMsgMESSAGE.query.delete()
        MsgMESSAGE.query.delete()
        db.session.commit()
Ejemplo n.º 2
0
    def test_index(data, self):
        from invenio.modules.accounts.models import User
        from invenio.modules.messages.models import MsgMESSAGE, UserMsgMESSAGE

        users = data.UserData
        admin = User.query.filter(User.nickname.like('admin')).one()
        romeo = User.query.filter(User.nickname.like('romeo')).one()
        juliet = User.query.filter(User.nickname.like('juliet')).one()

        m = MsgMESSAGE()
        m.subject = 'Message 1 Subject'
        m.body = 'body'
        try:
            m.sent_to_user_nicks = 'admin, NOTEXISTS'
        except:
            assert m.sent_to_user_nicks is None
        m.sent_to_user_nicks = ', '.join([users.admin.nickname,
                                          users.romeo.nickname])

        try:
            m.sent_to_user_nicks = 'admin, NOTEXISTS'
        except:
            # Remove unnecessary space
            assert m.sent_to_user_nicks == ','.join([users.admin.nickname,
                                                     users.romeo.nickname])

        m.sent_to_group_names = ''
        m.id_user_from = users.admin.id

        db.session.add(m)
        db.session.commit()

        m = MsgMESSAGE.query.first()
        assert admin in m.recipients
        assert romeo in m.recipients
        assert juliet not in m.recipients

        response = self.login(users.admin.nickname, users.admin.password)
        assert users.admin.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' in response.data
        self.logout()

        response = self.login(users.romeo.nickname, users.romeo.password)
        assert users.romeo.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' in response.data
        self.logout()

        response = self.login(users.juliet.nickname, users.juliet.password)
        assert users.juliet.nickname in response.data
        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'Message 1 Subject' not in response.data
        self.logout()

        # Avoid problems with foreign keys.
        UserMsgMESSAGE.query.delete()
        MsgMESSAGE.query.delete()
        db.session.commit()
Ejemplo n.º 3
0
    def test_send_later(data, self):
        from invenio_accounts.models import User
        from invenio.modules.messages.models import MsgMESSAGE, UserMsgMESSAGE

        users = data.UserData
        romeo = User.query.filter(User.nickname.like('romeo')).one()

        #response = self.login('romeo', '')

        import time
        from datetime import datetime, timedelta

        sent = datetime.now()
        received = sent + timedelta(seconds=5)

        m = MsgMESSAGE()
        m.subject = 'sent_now'
        m.body = 'body'
        m.sent_to_user_nicks = 'admin'
        m.sent_to_group_names = ''
        m.id_user_from = users.romeo.id
        m.sent_date = sent
        db.session.add(m)
        #db.session.commit()

        m = MsgMESSAGE()
        m.subject = 'sent_later'
        m.body = 'body'
        m.sent_to_user_nicks = 'admin'
        m.sent_to_group_names = ''
        m.id_user_from = romeo.id
        m.sent_date = sent
        m.received_date=received#.strftime('%Y-%m-%d %H:%M:%S')
        for um in m.sent_to_users:
            um.status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
        db.session.add(m)
        db.session.commit()

        #response = self.client.post('/yourmessages/add',
        #        #base_url=request.base_url.replace('http:','https:'),
        #        data=dict(
        #        sent_to_user_nicks='admin',
        #        sent_to_group_names=' ',
        #        subject='sent_later',
        #        body='test',
        #        received_date=received.strftime('%Y-%m-%d %H:%M:%S')
        #       ), follow_redirects=True,
        #       headers=[('X-Requested-With', 'XMLHttpRequest')])

        #self.logout()
        response = self.login(users.admin.nickname, users.admin.password)

        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'sent_now' in response.data
        assert 'sent_later' not in response.data

        while datetime.now() <= received:
            time.sleep(1)

        time.sleep(1)

        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'sent_now' in response.data
        assert 'sent_later' in response.data

        # Avoid problems with foreign keys.
        UserMsgMESSAGE.query.delete(synchronize_session='fetch')
        MsgMESSAGE.query.delete(synchronize_session='fetch')
        db.session.commit()
Ejemplo n.º 4
0
    def test_send_later(data, self):
        from invenio.modules.accounts.models import User
        from invenio.modules.messages.models import MsgMESSAGE, UserMsgMESSAGE

        users = data.UserData
        romeo = User.query.filter(User.nickname.like('romeo')).one()

        #response = self.login('romeo', '')

        import time
        from datetime import datetime, timedelta

        sent = datetime.now()
        received = sent + timedelta(seconds=5)

        m = MsgMESSAGE()
        m.subject = 'sent_now'
        m.body = 'body'
        m.sent_to_user_nicks = 'admin'
        m.sent_to_group_names = ''
        m.id_user_from = users.romeo.id
        m.sent_date = sent
        db.session.add(m)
        #db.session.commit()

        m = MsgMESSAGE()
        m.subject = 'sent_later'
        m.body = 'body'
        m.sent_to_user_nicks = 'admin'
        m.sent_to_group_names = ''
        m.id_user_from = romeo.id
        m.sent_date = sent
        m.received_date=received#.strftime('%Y-%m-%d %H:%M:%S')
        for um in m.sent_to_users:
            um.status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
        db.session.add(m)
        db.session.commit()

        #response = self.client.post('/yourmessages/add',
        #        #base_url=request.base_url.replace('http:','https:'),
        #        data=dict(
        #        sent_to_user_nicks='admin',
        #        sent_to_group_names=' ',
        #        subject='sent_later',
        #        body='test',
        #        received_date=received.strftime('%Y-%m-%d %H:%M:%S')
        #       ), follow_redirects=True,
        #       headers=[('X-Requested-With', 'XMLHttpRequest')])

        #self.logout()
        response = self.login(users.admin.nickname, users.admin.password)

        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'sent_now' in response.data
        assert 'sent_later' not in response.data

        while datetime.now() <= received:
            time.sleep(1)

        time.sleep(1)

        response = self.client.get("/yourmessages/", follow_redirects=True)
        assert 'sent_now' in response.data
        assert 'sent_later' in response.data

        # Avoid problems with foreign keys.
        UserMsgMESSAGE.query.delete(synchronize_session='fetch')
        MsgMESSAGE.query.delete(synchronize_session='fetch')
        db.session.commit()