コード例 #1
0
def new_post():
    db = COMP249Db()
    message = request.forms.get('post')
    interface.post_add(db, users.session_user(db), message)

    response.set_header('Location', '/')
    response.status = 303
    return 'Redirect to /'
コード例 #2
0
ファイル: main.py プロジェクト: kevinpaterson/boot-network
def new_post():
    db = COMP249Db()
    message = request.forms.get('post')
    interface.post_add(db, users.session_user(db), message)

    response.set_header('Location', '/')
    response.status = 303
    return 'Redirect to /'
コード例 #3
0
ファイル: main.py プロジェクト: m8ypie/fpmg-249-2
def post():
    """ Saves provided post to database
    :return: Home page
    """
    content = request.forms.get("post")
    user = users.session_user(db)
    if user is not None:
        interface.post_add(db, user, content)
    redirect('/')
コード例 #4
0
 def test_hashtag_track(self):
     """Test that hashtags are organised and counted correctly after a post that contains hashtags is added"""
     message = """
         #test #test #test #test #test #test #test #test #test #ync #ync #ync #ync 
     """
     interface.post_add(self.db, "Bobalooba", message)
     counted_hashtags = interface.get_counted_hashtags(self.db)
     ordered_hashtags = ['#test', '#ync', '#ax', '#aa', '#gquax', '#nrurcdrbq', '#rucaecv', '#swgsdd', '#zocpybi']
     for counted_hashtag, ordered_hashtag in zip(counted_hashtags, ordered_hashtags):
         self.assertEqual(counted_hashtag[0], ordered_hashtag)
コード例 #5
0
 def test_mentions_track(self):
     """Test that mentions are organised and counted correctly after a post that contains mentions is added"""
     message = """
          @Bean @Bean @Bean @Bean @Bean @Jimbulator @Jimbulator @Jimbulator
     """
     interface.post_add(self.db, "Bobalooba", message)
     counted_mentions = interface.get_counted_mentions(self.db)
     ordered_mentions = ['@Bean', '@Jimbulator', '@Contrary', '@Bobalooba']
     for counted_mention, ordered_mention in zip(counted_mentions, ordered_mentions):
         self.assertEqual(counted_mention[0], ordered_mention)
コード例 #6
0
ファイル: main.py プロジェクト: jasonkwh/prev-assignments
def add_post():
    """Adding post"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    if username:
        content = request.forms['post'] # get user inputs from the input form 'post'
        interface.post_add(db, username, content) # add post by post_add function of interface.py
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
コード例 #7
0
ファイル: main.py プロジェクト: jasonkwh/studiospates-python
def add_post():
    """Adding post"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    if username:
        content = request.forms['post'] # get user inputs from the input form 'post'
        interface.post_add(db, username, content) # add post by post_add function of interface.py
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
コード例 #8
0
    def test_add_post(self):
        """test adding a post to the database"""

        #sucessfull test
        posts = interface.post_add(self.db, "Martin", "test message")
        self.assertEqual(11, posts)


        #Test with big message
        text = """dsklfjlskjfs;sdklfjsdlkjjf;lskadjfsalkdjf;lskadjfsa;lkdjfs;dlkfjsd;lakjf;sldkjfslkdjfsl;ajfl
        ksdjflksdjflksjflksdjfsldkfjsalkfj;salkdjfsa;lkfj;salkdjfsalk;djfs;alkfjslakdjf;salkdjfsa;lkjdf;laskdjfls
        klsafdjasldkfjsdalkfjsldakfjflksjflksdjaf;lksjadflksjdaflksdajskdjfslakjflsakdjf;lskadjflksdajflksdjf;las
        sdkalfj;lsakdjflkdsajflkasdjf;lkasdjf;lksadjflskadjfsal;kdjf;aslkdjf;lsakdjfsa;flakdjf"""

        posts = interface.post_add(self.db, "Martin", text)
        self.assertEqual(None, posts)
コード例 #9
0
ファイル: level2_unit.py プロジェクト: Patane97/pssst
    def test_post_add_length(self):
        """Posting a long message should fail"""

        usernick = 'Bean'
        longmessage = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
        result = interface.post_add(self.db, usernick, longmessage)

        self.assertEqual(None, result)
コード例 #10
0
    def test_post_add_length(self):
        """Posting a long message should fail"""

        usernick = 'Bean'
        longmessage = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
        result = interface.post_add(self.db, usernick, longmessage)

        self.assertEqual(None, result)
コード例 #11
0
ファイル: main.py プロジェクト: jackdvpt/Psst
def post():
    """
    As a registered logged in user i am able to make a new post to PSST!
    Takes the post from the POST request and adds it to teh database.
        Then redirects to the homepage
    :return:
    """
    db = PsstDb()
    post = request.forms.get('post')
    test = interface.post_add(db, users.session_user(db), post)
    redirect('/')
コード例 #12
0
ファイル: level2_unit.py プロジェクト: Patane97/pssst
    def test_post_add(self):
        """Test adding new posts"""

        usernick = 'Bean'
        message = "one two three"

        postid = interface.post_add(self.db, usernick, message)

        # result should be an integer
        self.assertEqual(int, type(postid))

        # get all posts for this user (should be just one)
        posts = interface.post_list(self.db, usernick=usernick)
        self.assertEquals(1, len(posts))

        # check it's the same
        self.assertEquals(postid, posts[0][0])
コード例 #13
0
    def test_post_add(self):
        """Test adding new posts"""

        usernick = 'Bean'
        message = "one two three"

        postid = interface.post_add(self.db, usernick, message)

        # result should be an integer
        self.assertEqual(int, type(postid))

        # get all posts for this user (should be just one)
        posts = interface.post_list(self.db, usernick=usernick)
        self.assertEquals(1, len(posts))

        # check it's the same
        self.assertEquals(postid, posts[0][0])
コード例 #14
0
def post():
    db = COMP249Db()
    usernick = users.session_user(db)
    message = request.forms.get('post')
    interface.post_add(db, usernick, message)
    return redirect('/')
コード例 #15
0
ファイル: main.py プロジェクト: Patane97/pssst
def post():
    user = users.session_user(COMP249Db())
    message = request.forms.get('post')
    if not message.isspace():
        interface.post_add(COMP249Db(), user, message)
    return redirect('/')