def test_upvote_deleted(self): Upvote.delete_upvote_or_downvote( self.user, self.picture, Upvote ) self.assertFalse( Upvote.objects.filter( user = self.user ) )
def upvote(pitch_id): pitch = Pitch.query.get(pitch_id) user = current_user pitch_upvotes = Upvote.query.filter_by(pitch_id=pitch_id) if Upvote.query.filter(Upvote.user_id == user.id, Upvote.pitch_id == pitch_id).first(): return redirect(url_for('main.index')) new_upvote = Upvote(pitch_id=pitch_id, author=current_user) new_upvote.save_upvotes() return redirect(url_for('main.index'))
def upvote(blog_id): upvote = Upvote.query.filter_by(user_id=user.id, blog_id=blog_id).first() if upvote != None: upvote.delete() return jsonify({'remove': True}) else: upvote = Upvote(vote=True, user_id=user.id, blog_id=blog_id) try: upvote.save() return jsonify({'success': True}) except Exception: return jsonify({'success': False})
class TestUpvote(unittest.TestCase): def setUp(self): self.new_pitch = Pitch(title='password', category='businesspitch', pitch='A password managing app') self.new_upvote = Upvote(pitch=self.new_pitch) def test_check_instance_variables(self): self.assertEquals(self.new_upvote.pitch, self.new_pitch) def test_save_upvote(self): self.new_upvote.save_upvotes() self.assertTrue(len(Upvote.query.all()) > 0) def test_get_upvote_by_pitch_id(self): self.new_upvote.save_upvotes() got_upvotes = Upvote.get_upvotes(self.new_pitch.id) self.assertTrue(len(got_upvotes) == 1)
def upvote(quesid, id): if current_user.is_anony(): return render_template('403.html') ans = Items.query.get(id) if ans.author_id == current_user.id: return render_template('not.html', text=u'您不能对自己的回答点赞') u = Upvote.query.filter(Upvote.upvoter == current_user.id).filter( Upvote.answerid == id).first() if u is None: ans = Items.query.filter_by(id=id).first().answer it = Items.query.filter_by(id=id).first() ans.upvote = ans.upvote + 1 us = User.query.filter_by(id=it.author_id).first() us.ups = us.ups + 1 up = Upvote(upvoter=current_user.id, answerid=id, descr=2) db.session.add(ans) db.session.add(us) db.session.add(up) db.session.commit() return redirect(url_for('question', id=quesid)) else: ans = Items.query.filter_by(id=id).first().answer it = Items.query.filter_by(id=id).first() if u.descr == 2: ans.upvote = ans.upvote - 1 us = User.query.get(it.author_id) us.ups = us.ups - 1 up = Upvote.query.filter(Upvote.upvoter == current_user.id).filter( Upvote.answerid == id).filter(Upvote.descr == 2).first() db.session.delete(up) elif u.descr == 0: ans.upvote = ans.upvote + 1 ans.downvote = ans.downvote - 1 us = User.query.filter_by(id=it.author_id).first() us.ups = us.ups + 1 up = Upvote.query.filter(Upvote.upvoter == current_user.id).filter( Upvote.answerid == id).filter(Upvote.descr == 0).first() up.descr = 2 db.session.add(up) db.session.add(ans) db.session.add(us) db.session.commit() return redirect(url_for('question', id=quesid))
def upvote(post_id): form = EmptyForm() if form.validate_on_submit(): post = Post.query.filter_by(id=post_id).first_or_404() upvote = Upvote(upvoter_id=current_user.id, post=post) db.session.add(upvote) #Assigning badge post.author.upvotes += 1 post.votes += 1 assign_badge(post.author) db.session.commit() flash('Upvoted! :)') return redirect(request.referrer)
def upvote(pitch_id): upvote_=Upvote.query.filter_by(user_id=current_user.id,post_id=pitch_id).first() if not upvote_: upvote_=Upvote(user_id=current_user.id,post_id=pitch_id) upvote_.save() else: upvote_.delete_() return redirect(url_for("main.pitch",pitch_id=pitch_id))
def test_create_upvote_returns_true(self): value = Upvote.create_upvote_or_downvote(self.user, self.picture, Upvote) self.assertTrue(value) self.assertTrue(Upvote.objects.filter(user=self.user))
def setUp(self): super().setUp() Upvote.create_upvote_or_downvote(self.user, self.picture, Upvote)
def setUp(self): self.new_pitch = Pitch(title='password', category='businesspitch', pitch='A password managing app') self.new_upvote = Upvote(pitch=self.new_pitch)
def test_get_upvote_by_pitch_id(self): self.new_upvote.save_upvotes() got_upvotes = Upvote.get_upvotes(self.new_pitch.id) self.assertTrue(len(got_upvotes) == 1)
def setUp(self): super().setUp() Upvote.vote(self.user, self.picture, Upvote()) Upvote.vote(self.user, self.picture, Upvote())
def test_upvote_returns_false(self): value = Upvote.see_if_upvoted_or_downvoted(self.user, self.picture, Upvote) self.assertFalse(value)
def setUp(self): self.new_upvote = Upvote(id=1, user_id=3, pitch_id=10)
def setUp(self): self.upvote = Upvote()