def test_downvote_deleted(self): Downvote.delete_upvote_or_downvote( self.user, self.picture, Downvote ) self.assertFalse( Downvote.objects.filter( user = self.user ) )
def downvote(pitch_id): pitch = Pitch.query.get(pitch_id) user = current_user pitch_upvotes = Downvote.query.filter_by(pitch_id=pitch_id) if Downvote.query.filter(Downvote.user_id == user.id, Downvote.pitch_id == pitch_id).first(): return redirect(url_for('main.index')) new_downvote = Downvote(pitch_id=pitch_id, author=current_user) new_downvote.save_downvotes() return redirect(url_for('main.index'))
class TestDownvote(unittest.TestCase): def setUp(self): self.new_pitch = Pitch(title= 'password', category= 'businesspitch', pitch='A password managing app') self.new_downvote = Downvote(pitch=self.new_pitch) def test_check_instance_variables(self): self.assertEquals(self.new_downvote.pitch, self.new_pitch) def test_save_downvote(self): self.new_downvote.save_downvotes() self.assertTrue(len(Downvote.query.all())>0) def test_get_downvote_by_pitch_id(self): self.new_downvote.save_downvotes() got_downvotes = Downvote.get_downvotes(self.new_pitch.id) self.assertTrue(len(got_downvotes)==1)
def downvote(pitch_id): downvote_=Downvote.query.filter_by(user_id=current_user.id,post_id=pitch_id).first() if not downvote_: downvote_=Downvote(user_id=current_user.id,post_id=pitch_id) downvote_.save() else: downvote_.delete_() return redirect(url_for("main.pitch",pitch_id=pitch_id))
def setUp(self): self.new_pitch = Pitch(title= 'password', category= 'businesspitch', pitch='A password managing app') self.new_downvote = Downvote(pitch=self.new_pitch)
def test_get_downvote_by_pitch_id(self): self.new_downvote.save_downvotes() got_downvotes = Downvote.get_downvotes(self.new_pitch.id) self.assertTrue(len(got_downvotes)==1)
def test_create_downvote_returns_true(self): value = Downvote.create_upvote_or_downvote(self.user, self.picture, Downvote) self.assertTrue(value) self.assertTrue(Downvote.objects.filter(user=self.user))
def setUp(self): super().setUp() Downvote.create_upvote_or_downvote(self.user, self.picture, Downvote)
def setUp(self): self.downvote=Downvote()
def setUp(self): super().setUp() Downvote.vote(self.user, self.picture, Downvote()) Downvote.vote(self.user, self.picture, Downvote())
def test_downvote_returns_true(self): value = Downvote.see_if_upvoted_or_downvoted(self.user, self.picture, Downvote) self.assertTrue(value)
def setUp(self): self.new_downvote = Downvote(id=1, user_id=3, pitch_id=10)