Beispiel #1
0
    def test_get_hot_post(self):
        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post1 = backend.add_post('title01', user['id'], content='content01')
        post2 = backend.add_post('title02', user['id'], content='content02')
        post2 = backend.add_post('title03', user['id'], content='content03')

        posts = backend.get_hot_post()
        assert len(posts) == 3

        count = backend.get_post_count()
        assert count == 3
Beispiel #2
0
    def test_get_hot_post(self):
        user = backend.add_user('user02','*****@*****.**','pass02')
        post1 = backend.add_post('title01',user['id'],content='content01')
        post2 = backend.add_post('title02',user['id'],content='content02')
        post2 = backend.add_post('title03',user['id'],content='content03')

        posts = backend.get_hot_post()
        assert len(posts) == 3

        count = backend.get_post_count()
        assert count == 3
Beispiel #3
0
    def test_add_post(self):
        user = backend.add_user('user02','*****@*****.**','pass02')

        post = backend.add_post('title01',user['id'],content='content01')
        assert post['title'] == 'title01'

        self.assertRaises(BackendError,backend.add_post,'title02','',content='content01')
Beispiel #4
0
    def test_set_item(self):

        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post1 = backend.add_post('title01', user['id'], content='content01')

        item = backend.add_item('item1', user['id'], post1['id'], '')

        item = backend.set_item(item['id'], {'title': 'title3'})
        assert item['title'] == 'title3'
Beispiel #5
0
    def test_set_item(self):

        user = backend.add_user('user02','*****@*****.**','pass02')
        post1 = backend.add_post('title01',user['id'],content='content01')

        item = backend.add_item('item1',user['id'],post1['id'],'')

        item = backend.set_item(item['id'],{'title':'title3'})
        assert item['title'] ==  'title3'
Beispiel #6
0
    def test_get_item(self):
        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post1 = backend.add_post('title01', user['id'], content='content01')

        item1 = Item(post_id=post1['id'], title='title01', content='content01')

        db.session.add(item1)
        db.session.commit()

        item = backend.get_item(item1.id)
        assert item['title'] == item1.title
Beispiel #7
0
    def test_add_post(self):
        user = backend.add_user('user02', '*****@*****.**', 'pass02')

        post = backend.add_post('title01', user['id'], content='content01')
        assert post['title'] == 'title01'

        self.assertRaises(BackendError,
                          backend.add_post,
                          'title02',
                          '',
                          content='content01')
Beispiel #8
0
    def test_get_item(self):
        user = backend.add_user('user02','*****@*****.**','pass02')
        post1 = backend.add_post('title01',user['id'],content='content01')
    
        item1 = Item(post_id=post1['id'],title='title01',content='content01')

        db.session.add(item1)
        db.session.commit()

        item = backend.get_item(item1.id)
        assert item['title'] == item1.title
Beispiel #9
0
    def test_set_post(self):

        user = backend.add_user('user02','*****@*****.**','pass02')
        post = backend.add_post('title01',user['id'],content='content01')

        post = backend.set_post(post['id'],{'title':'title03','date_create':datetime.now()})
        assert post['title'] == 'title03'

        # backendError

        self.assertRaises(BackendError,backend.set_post,post['id'],{'liked_by':'aaaaaa'})
Beispiel #10
0
    def test_set_post(self):

        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post = backend.add_post('title01', user['id'], content='content01')

        post = backend.set_post(post['id'], {
            'title': 'title03',
            'date_create': datetime.now()
        })
        assert post['title'] == 'title03'

        # backendError

        self.assertRaises(BackendError, backend.set_post, post['id'],
                          {'liked_by': 'aaaaaa'})
Beispiel #11
0
    def test_get_post_item(self):
        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post1 = backend.add_post('title01', user['id'], content='content01')

        item1 = Item(post_id=post1['id'], title='title01', content='content01')
        item2 = Item(post_id=post1['id'], title='title02', content='content02')
        item3 = Item(post_id=post1['id'], title='title03', content='content03')

        db.session.add(item1)
        db.session.add(item2)
        db.session.add(item3)
        db.session.commit()

        items = backend.get_post_item(post1['id'])
        assert len(items) == 3

        count = backend.get_post_item_count(post1['id'])
        assert count == 3
Beispiel #12
0
    def test_get_post_item(self):
        user = backend.add_user('user02','*****@*****.**','pass02')
        post1 = backend.add_post('title01',user['id'],content='content01')
    
        item1 = Item(post_id=post1['id'],title='title01',content='content01')
        item2 = Item(post_id=post1['id'],title='title02',content='content02')
        item3 = Item(post_id=post1['id'],title='title03',content='content03')

        db.session.add(item1)
        db.session.add(item2)
        db.session.add(item3)
        db.session.commit()

        items = backend.get_post_item(post1['id'])
        assert len(items) == 3

        count = backend.get_post_item_count(post1['id'])
        assert count == 3
Beispiel #13
0
def post_new():
    
    form = PostForm()

    if form.validate_on_submit():

        title = form.title.data.encode('utf-8')
        content = form.content.data.encode('utf-8')
        author_id = g.user['id']
        
        try:
            post = backend.add_post(title,author_id,content)
        except BackendError,ex:
            flash('新建内容失败请重试','error')
            return render_template('site/post_new.html',form=form)
        else:
            flash('新建列表成功','success')

        return redirect('/post/%d' % post['id'])