Exemplo n.º 1
0
    def test_recursive_delete(self):
        u = meeplib.User('foo', 'bar')
        m = meeplib.Message('the title', 'the content', u, '!')
        n = meeplib.Message('the reply title', 'the reply', u, m.id)
        o = meeplib.Message('the second tier title', 'the second reply', u,
                            n.id)

        meeplib.delete_message(m)

        assert n not in meeplib._messages.values()
        assert o not in meeplib._messages.values()
Exemplo n.º 2
0
    def test_get_root_messages(self):
        user = meeplib.User('admin', 'admin')
        user.insertIntoDB()
        author = meeplib.get_user('admin')
        message1 = meeplib.Message('title1', 'message1', author.id, -1)
        message1.insertIntoDB()
        message2 = meeplib.Message('title2', 'message2', author.id, -1)
        message2.insertIntoDB()
        message3 = meeplib.Message('title3', 'message3', author.id, 0)
        message3.insertIntoDB()

        root_messages = meeplib._get_root_messages()
        assert message1 in root_messages
        assert message2 in root_messages
        assert message3 not in root_messages
Exemplo n.º 3
0
    def test_list_messages(self):
        environ = {}  # make a fake dict
        environ['PATH_INFO'] = '/m/list'

        u = meeplib.User('user', 'name')
        m = meeplib.Message('init title', 'init message', u, '!')

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        for m in data:
            if "Title: init title" in m:
                index += 1
            if 'Message: init message' in m:
                index += 1
            if 'Author: user' in m:
                index += 1
            if 'ID: 0' in m:
                index += 1

            print index
        assert index is 4
Exemplo n.º 4
0
    def add_topic_action(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        msgtitle = form['msgtitle'].value
        message = form['message'].value

        cookie = environ.get('HTTP_COOKIE', '')
        username = meepcookie.load_username(cookie)

        if username == "":
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)

            return ["session ended"]

        user = meeplib.get_user(username)

        new_message = meeplib.Message(msgtitle, message, user)
        new_topic = meeplib.Topic(title, new_message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list_topics'))
        start_response("302 Found", headers)
        return ["topic added"]
Exemplo n.º 5
0
    def test_add_reply(self):
        msg = meeplib.get_message(self.msgId)
        new_message = meeplib.Message('reply', 'reply msg', msg.author, True)
        msg.add_reply(new_message)

        replies = msg.get_replies()
        assert len(replies) == 1
Exemplo n.º 6
0
    def reply_action(self, environ, start_response):

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        post = form['post'].value

        #username = '******'

        cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
        username = cookie["username"].value

        user = meeplib.get_user(username)

        new_message = meeplib.Message(post, user)
        thread_id = int(form['thread_id'].value)

        t = meeplib.get_thread(thread_id)
        t.add_post(new_message)
        meeplib.save()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["reply added"]
Exemplo n.º 7
0
    def add_message_topic_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        topicId = form['topicid'].value
        topic = meeplib.get_topic(int(topicId))

        title = form['title'].value
        message = form['message'].value

        cookie = environ.get('HTTP_COOKIE', '')

        username = meepcookie.load_username(cookie)
        print username
        user = meeplib.get_user(username)
        print user

        if username != "":
            #print title, message, user
            new_message = meeplib.Message(title, message, user)

            topic.add_message(new_message)
            print "Message added to topic" + topicId

            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/m/topics/view?id=%d' % (topic.id)))
            start_response("302 Found", headers)
            return ["message added to topic"]
        else:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)
            return ["session expired"]
Exemplo n.º 8
0
def initialize():
    # create a default user
    u = meeplib.User('test', 'foo')

    # create a single message
    meeplib.Message('my title', 'This is my message!', u)
    meeplib.load()
Exemplo n.º 9
0
    def add_message_action(self, environ, start_response):
        if self.username is None:
            headers = [('Content-type', 'text/html')]
            start_response("302 Found", headers)
            return [
                "You must be logged in to use this feature <p><a href='/login'>Log in</a><p><a href='/m/list'>Show messages</a>"
            ]

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value
        parent = int(form['parent_id'].value)

        user = meeplib.get_user(self.username)

        new_message = meeplib.Message(title, message, user, parent)

        with con:
            cur.execute(
                "INSERT INTO Messages (ID, Title, Post, Author, Parent) VALUES (?, ?, ?, ?, ?)",
                (new_message.id, title, message, self.username, parent))

        con.commit()
        #meeplib.save()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Exemplo n.º 10
0
 def setUp(self):
     meep_example_app.initialize()
     app = meep_example_app.MeepExampleApp()
     self.app = app
     u = meeplib.User('foo', 'bar', -1)
     v = meeplib.User('foo2', 'bar2', -1)
     m = meeplib.Message('my title', 'lol', u, -1)
Exemplo n.º 11
0
    def test_main_page(self):
        environ = {}  # make a fake dict
        environ['PATH_INFO'] = '/main_page'

        u = meeplib.User('user', 'name')
        meeplib.set_curr_user(u.username)
        m = meeplib.Message('init title', 'init message', u, '!')

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        for m in data:
            if "Add Message" in m:
                index += 1
            if 'Create User' in m:
                index += 1
            if 'Logout' in m:
                index += 1
            if 'Show Messages' in m:
                index += 1

            #print m
        assert index is 4
Exemplo n.º 12
0
 def reply(self, environ, start_response):
     print "enter reply"
     username = check_cookie(environ)
     user = meeplib.get_user(username)
     if user is None:
         headers = [('Content-type', 'text/html')]
         headers.append(('Location', '/'))
         start_response("302 Found", headers)
         return ["log in to use that feature"]
     headers = [('Content-type', 'text/html')]
     form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
     thread_id = int(form['thread_id'].value)
     t = meeplib.get_thread(thread_id)
     s = []
     try:
         post = form['post'].value
     except KeyError:
         post = ''
     if post != '':
         new_message = meeplib.Message(post, user)
         t.add_post(new_message)
         meeplib.save_state()
         headers.append(('Location', '/m/list'))
     start_response("302 Found", headers)
     s.append(render_page("reply.html", thread=t))
     print "exit reply"
     return ["".join(s)]
Exemplo n.º 13
0
def initialize():
    print "enter initialize"
    meeplib.load_state()
    u = meeplib.User('test', 'foo')
    t = meeplib.Thread('Greetings Earthlings')
    m = meeplib.Message('The meep message board is open.', u)
    t.add_post(m)
Exemplo n.º 14
0
 def setUp(self):
     self.ux = 'foo'
     self.px = 'bar'
     self.msgTitle = 'the title'
     self.msgMsg = 'the content'
     u = meeplib.User(self.ux, self.px)
     m = meeplib.Message(self.msgTitle, self.msgMsg, u)
     self.msgId = m.id
Exemplo n.º 15
0
    def test_delete(self):
        u = meeplib.User('foo', 'bar')
        m = meeplib.Message('my title', 'This is my message!', u)

        assert m in meeplib._messages.values()
        meeplib.delete_message(m)

        assert m not in meeplib._messages.values()
Exemplo n.º 16
0
    def alter_message_action(self, environ, start_response):
        post = (environ.get('REQUEST_METHOD') == 'POST')
        if post:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        else:
            form = parse_qs(environ['QUERY_STRING'])
        """
        try:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
            #params = dict([part.split('=') for part in environ['QUERY_STRING'].split('&')])
            #msgId = int(params['id'])
        except:
            headers = [('Content-type', 'text/html')]
            start_response("200 OK", headers)
            return ["Error Processing provided ID"]

        id = int(form['id'].value)
        
        action = form['bttnSubmit'].value
        """

        print 'post %s' % (post, )
        id = int(self.get_value(form, post, 'id', ''))
        action = self.get_value(form, post, 'bttnSubmit', '')
        msg = meeplib.get_message(id)

        error = False
        errorMsg = ""
        response = "200 OK"

        headers = [('Content-type', 'text/html')]
        u = self.getUser(environ)
        if u == None:
            error = True
            errorMsg = """You must be logged in to proceed."""
        if msg == None:
            error = True
            errorMsg = """Message id: %d could not be found.""" % (id, )
        elif action == "Delete":
            if msg.author.username == u.username:
                meeplib.delete_message(msg)
                response = "302 Found"
                headers.append(('Location', '/'))
                errorMsg = "message removed"
            else:
                errorMsg = "You cannot delete another user's post."
        elif action == "Reply":
            title = ""
            message = form['replyText'].value
            user = meeplib.get_user(u.username)
            new_message = meeplib.Message(title, message, user, True)
            msg.add_reply(new_message)
            response = "302 Found"
            headers.append(('Location', '/'))
            errorMsg = "message replied"

        start_response(response, headers)
        return [errorMsg]
Exemplo n.º 17
0
def add_message(title, message, pid):
    try:
        username = "******"
        user = meeplib.get_user(username)

        new_message = meeplib.Message(title, message, user, pid)
        return new_message.id
    except:
        return -1
Exemplo n.º 18
0
def initialize():
    # create a default user
    u = meeplib.User('test', 'foo')

    # create a thread
    t = meeplib.Thread('Test Thread')
    # create a single message
    m = meeplib.Message('This is my message!', u)
    # save the message in the thread
    t.add_post(m)
Exemplo n.º 19
0
def initialize():
    try:
        meeplib._load_data()
    except IOError:  # file does not exist/cannot be opened
        # initialize data from scratch
        # create a default user with username: test, password: test
        u = meeplib.User('test', 'test')

        # create a single message and topic
        meeplib.Topic('First Topic', meeplib.Message('my title', 'This is my message!', u), u)
Exemplo n.º 20
0
def initialize():
    # create a default user
    u = meeplib.User('aLlama', 'box')

    # create a thread (i.e. title for message)
    t = meeplib.Thread('This Is A Test Thread')
    # create a single message
    m = meeplib.Message('This is a lame test message.', u)
    # save the message in the thread
    t.add_post(m)
Exemplo n.º 21
0
def initialize():
    try:
        meeplib._messages = {}
        meeplib._users = {}
        meeplib._user_ids = {}
        meeplib._openMeep()
    except IOError:
        # create default users
        u = meeplib.User('test', 'foo')
        a = meeplib.User('Anonymous', 'password')
        meeplib.Message('my title', 'This is my message!', u, -1)
Exemplo n.º 22
0
    def test_add_reply(self):
        environ = {}  # make a fake dict
        environ['PATH_INFO'] = '/m/list'
        u = meeplib.User('foo', 'bar')
        m = meeplib.Message('the title', 'the content', u, '!')
        n = meeplib.Message('the reply title', 'the reply', u, m.id)
        o = meeplib.Message('the 2nd title', 'the 2nd reply', u, n.id)

        assert n.id in m.replies
        assert o.id in n.replies

        meeplib.set_curr_user(u.username)

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        '''print data[0]
Exemplo n.º 23
0
    def test_get_next_message_id(self):
        #there should be 1 message initially created
        assert meeplib._get_next_message_id() == 1
        user = meeplib.User('admin', 'admin')
        user.insertIntoDB()
        author = meeplib.get_user('admin')
        message = meeplib.Message('title', 'message', author.id, -1)
        message.insertIntoDB()

        #there should not be two messages
        assert meeplib._get_next_message_id() == 2
Exemplo n.º 24
0
    def setUp(self):

        x = meeplib.get_all_messages()
        print "Messages",x
        for message in x:
            meeplib.delete_message(message)
            
        x = meeplib.get_all_messages()
        print "Messages",x
        u = meeplib.User('foo', 'bar',-1)
        v = meeplib.User('foo2', 'bar2',-1)
        m = meeplib.Message('the title', 'the content', u,-1)
Exemplo n.º 25
0
    def add_thread(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''
        
        user = meeplib.get_user(username)
        if user is None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged in to use that feature."]

        headers = [('Content-type', 'text/html')]

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        try:
            title = form['title'].value
        except KeyError:
            title = ''
        try:
            message = form ['message'].value
        except KeyError:
            message = ''

        s = []

        # title and message are non-empty
        if title == '' and message == '':
            pass
        elif title == '' and message != '':
            s.append("Title was empty.<p>")
        elif title != '' and message == '':
            s.append("Message was empty. <p>")
        elif title != '' and message != '':
            new_message = meeplib.Message(message, user)
            t = meeplib.Thread(title)
            t.add_post(new_message)
            meeplib.save_state()
            headers.append(('Location','/m/list'))
            
        start_response("302 Found", headers)

        # doesn't get executed if we had valid input and created a thread
        s.append(render_page("add_thread.html", title=title, message=message))

        return ["".join(s)]
Exemplo n.º 26
0
    def add_message(self, environ, start_response):
        #get cookie
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            print "Username is %s" % username
        except:
            username = ''
        
        user = meeplib.get_user(username)
        if user is None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["Dude, login first if you want to use this feature."]
        headers = [('Content-type', 'text/html')]

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        try:
            title = form['title'].value
        except KeyError:
            title = ''
        try:
            message = form ['message'].value
        except KeyError:
            message = ''

        s = []

        #check to see if title and message are not empty
        if title == '' and message == '':
            pass
			
        elif title == '' and message != '':
            s.append("The title is empty.<p>")
			
        elif title != '' and message == '':
            s.append("The message is empty. <p>")
			
        elif title != '' and message != '':
            new_message = meeplib.Message(message, user)
            t = meeplib.Thread(title)
            t.add_post(new_message)
            meeplib.save()
            headers.append(('Location','/m/list'))
            
        start_response("302 Found", headers)
        s.append(render_page("add_message.html", title=title, message=message))

        return ["".join(s)]
Exemplo n.º 27
0
    def setUp(self):
        #the backup data causes some of the tests to fail - not sure why
        #remove the backup data before every test
        cur.execute("DELETE FROM MESSAGE")
        cur.execute("DELETE FROM SESSION")
        cur.execute("DELETE FROM USER")
        meeplib._reset()
        con.commit()

        u = meeplib.User('foo', 'bar')
        u.insertIntoDB()
        m = meeplib.Message('the title', 'the content', u.id, -1)
        m.insertIntoDB()
Exemplo n.º 28
0
    def add_message_action(self, environ, start_response):
        user = self.authHandler(environ)
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value
        parentPostID = int(form['parentPostID'].value)

        new_message = meeplib.Message(title, message, user.id, parentPostID)
        new_message.insertIntoDB()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Exemplo n.º 29
0
    def add_message_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value

        username = '******'
        user = meeplib.get_user(username)

        new_message = meeplib.Message(title, message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Exemplo n.º 30
0
def initialize():
    # create a default user
    #u = meeplib.User('test', 'foo')

    # create a single message
    #meeplib.Message('my title', 'This is my message!', u, "!")

    try:
        fp = open('users.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                #print obj
                (a, b) = obj

                u = meeplib.User(a, b)
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        fp = open('users.pickle', "w")
        fp.close()

    try:
        fp = open('messages.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                (a, b, c, d, e) = obj
                #print obj
                m = meeplib.Message(a, b, meeplib.get_user(c), d)
                m.id = e
                #print m.post + " is " + str(m.id)
                #obj = pickle.load(fp)
                #m.replies = obj
                #print obj
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        p = open('messages.pickle', "w")
        fp.close()