def test_downvote_deleted(self):
     Downvote.delete_upvote_or_downvote(
         self.user, self.picture, Downvote
     )
     self.assertFalse(
         Downvote.objects.filter(
             user = self.user
         )
     )
Exemplo n.º 2
0
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'))
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
 def setUp(self):
     self.new_pitch = Pitch(title= 'password', category= 'businesspitch', pitch='A password managing app')
     self.new_downvote = Downvote(pitch=self.new_pitch)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
 def setUp(self):
     super().setUp()
     Downvote.create_upvote_or_downvote(self.user, self.picture, Downvote)
Exemplo n.º 9
0
 def setUp(self):
     self.downvote=Downvote()
Exemplo n.º 10
0
 def setUp(self):
     super().setUp()
     Downvote.vote(self.user, self.picture, Downvote())
     Downvote.vote(self.user, self.picture, Downvote())
Exemplo n.º 11
0
 def test_downvote_returns_true(self):
     value = Downvote.see_if_upvoted_or_downvoted(self.user, self.picture,
                                                  Downvote)
     self.assertTrue(value)
Exemplo n.º 12
0
 def setUp(self):
     self.new_downvote = Downvote(id=1, user_id=3, pitch_id=10)