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')
def signup(): if authutil.is_logined(request): return redirect('/') form = SignupForm(next=request.values.get('next')) if form.validate_on_submit(): username = form.username.data.encode('utf-8') password = form.password.data.encode('utf-8') email = form.email.data.encode('utf-8') try: user = backend.add_user(username,email,password) except BackendError,ex: logging.info(traceback.format_exc()) flash('用户注册失败,请稍后再试','error') return render_template('signup.html',form=form) next_url = form.next.data if not next_url or next_url == request.path: next_url = '/' return redirect(next_url)
def signup(): if authutil.is_logined(request): return redirect('/') form = SignupForm(next=request.values.get('next')) if form.validate_on_submit(): username = form.username.data.encode('utf-8') password = form.password.data.encode('utf-8') email = form.email.data.encode('utf-8') try: user = backend.add_user(username, email, password) except BackendError, ex: logging.info(traceback.format_exc()) flash('用户注册失败,请稍后再试', 'error') return render_template('signup.html', form=form) next_url = form.next.data if not next_url or next_url == request.path: next_url = '/' return redirect(next_url)
def test_get_post(self): user = backend.add_user('user02','*****@*****.**','pass02') post = Post(title='post01',author_id=user['id'],content='content01',pic_small='pic_small') db.session.add(post) db.session.commit() _post = backend.get_post(post.id) assert _post['title'] == 'post01'
def test_auth_user(self): user = backend.add_user('user02', '*****@*****.**', 'pass02') ret, _user = backend.auth_user('*****@*****.**', 'pass02') print ret assert ret == True ret, _user = backend.auth_user('*****@*****.**', 'pass02') assert ret == False
def test_auth_user(self): user = backend.add_user('user02','*****@*****.**','pass02') ret,_user = backend.auth_user('*****@*****.**','pass02') print ret assert ret == True ret,_user = backend.auth_user('*****@*****.**','pass02') assert ret == False
def test_add_user(self): user1 = User(username='******',email='*****@*****.**',password='******') db.session.add(user1) db.session.commit() user = backend.add_user('user02','*****@*****.**','pass02') assert user['username'] == 'user02' self.assertRaises(BackendError,backend.add_user,'user02','*****@*****.**','pass02')
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'
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'
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
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
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')
def test_get_post(self): user = backend.add_user('user02', '*****@*****.**', 'pass02') post = Post(title='post01', author_id=user['id'], content='content01', pic_small='pic_small') db.session.add(post) db.session.commit() _post = backend.get_post(post.id) assert _post['title'] == 'post01'
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
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'})
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
def test_add_user(self): user1 = User(username='******', email='*****@*****.**', password='******') db.session.add(user1) db.session.commit() user = backend.add_user('user02', '*****@*****.**', 'pass02') assert user['username'] == 'user02' self.assertRaises(BackendError, backend.add_user, 'user02', '*****@*****.**', 'pass02')
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'})
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
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