コード例 #1
0
class BlogModelTest(unittest.TestCase):
    def setUp(self):
        self.user_rose = User(username='******',
                              password='******',
                              email='*****@*****.**')
        self.new_pitch = Pitch(id=1,
                               title='Test',
                               content='This is a test pitchapp',
                               user_id=self.user_rose.id)

    def tearDown(self):
        Pitch.query.delete()
        User.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_pitch.title, 'Test')
        self.assertEquals(self.new_pitch.content, 'This is a test pitch')
        self.assertEquals(self.new_pitch.user_id, self.user_rose.id)

    def test_save_pitch(self):
        self.new_pitch.save()
        self.assertTrue(len(Pitch.query.all()) > 0)

    def test_get_pitch(self):
        self.new_pitch.save()
        got_pitch = Pitch.get_pitch(1)
        self.assertTrue(get_piotch is not None)
コード例 #2
0
def new_pitch():
    form = PitchForm()
    if form.validate_on_submit():
        user_id = current_user._get_current_object().id
        pitch = Pitch(category=form.category.data,
                      title=form.title.data,
                      description=form.description.data,
                      user_id=user_id)
        pitch.save()
        return redirect(url_for('main.index'))
    return render_template('pitch.html', form=form)
コード例 #3
0
ファイル: test_pitch.py プロジェクト: VictorKMaina/pitch-app
    def test_save(self):
        """
        Test if save method commits new pitch to database
        """
        test_pitch = Pitch(
            pitch="Are you the wind? Because you're blowing me away.",
            likes=34,
            dislikes=43,
            user_id=1,
            time_posted="2020-11-17 03:30",
            category=Category.pickup_lines)

        # db.create_all()
        test_pitch.save()

        pitch = Pitch.query.filter_by(id=test_pitch.id).first()

        self.assertEqual(pitch.pitch,
                         "Are you the wind? Because you're blowing me away.")
        self.assertIsNotNone(pitch.user_id)
コード例 #4
0
class TestCommentClass(unittest.TestCase):
    """
    Test class to check Comment class methods

    Args:
        unittest.TestCase: Inherit from unittest.TestCase
    """

    def setUp(self):
        """
        Runs before each test case
        """
        db.create_all()

        self.user = User(user_name = "testing", email = "*****@*****.**", password = "******", first_name = "Victor", last_name = "Maina", bio = "Student at Moringa", profile_pic_path = "/static/app-resources/pp.jpg")

        self.user.save()

        self.pitch = Pitch(pitch = "Are you the wind? Because you're blowing me away.", likes = 0, dislikes = 3, user_id = self.user.id, time_posted = "2020-11-17 03:30", category = Category.pickup_lines)

        self.pitch.save()

        self.comment = Comment(comment="I love this idea!", pitch_id= self.pitch.id, user_id= self.user.id)

    def tearDown(self):
        """
        Runs after each test case
        """
        db.session.commit()
        db.drop_all()

    def test_comment_instance(self):
        """
        Test class to check Comment class methods
        
        Args:
            unittest.TestCase: Inherit from unittest.TestCase
        """
        db.session.add(self.comment)
        db.session.commit()

        self.assertIsNotNone(self.comment.id)
        self.assertEqual(self.comment.comment,"I love this idea!")
        self.assertEqual(self.comment.pitch_id, self.pitch.id)
        self.assertEqual(self.comment.user_id, self.user.id)

    def test_get_username(self):
        """
        Test case to see if get_username method returns username associated with comment
        """
        db.session.add(self.comment)
        db.session.commit()

        username = self.comment.get_username()

        self.assertEqual(User.query.filter_by(id = self.user.id).first().user_name, username)
    
    def test_get_profile_pic(self):
        """
        Test case to see if get_profile_pic method returns profile pic of user associated with comment
        """
        db.session.add(self.comment)
        db.session.commit()

        profile_pic_path = self.comment.get_profile_pic()

        self.assertEqual(User.query.filter_by(id = self.user.id).first().profile_pic_path, profile_pic_path)
コード例 #5
0
ファイル: test_pitch.py プロジェクト: VictorKMaina/pitch-app
class TestPitchClass(unittest.TestCase):
    """
    Test class for checking Pitch class methods
    """
    def setUp(self):
        """
        Runs before each test case
        """
        db.create_all()

        self.user = User(user_name="testing",
                         email="*****@*****.**",
                         password="******",
                         first_name="Victor",
                         last_name="Maina",
                         bio="Student at Moringa",
                         profile_pic_path="/static/app-resources/pp.jpg")

        self.user.save()

        self.pitch = Pitch(
            pitch="Are you the wind? Because you're blowing me away.",
            likes=0,
            dislikes=3,
            user_id=self.user.id,
            time_posted="2020-11-17 03:30",
            category=Category.pickup_lines)

    def tearDown(self):
        """
        Runs after each test case
        """
        db.session.commit()
        db.drop_all()

    def test_pitch_instance(self):
        """
        Test case to check if User is instance is created
        """
        db.session.add(self.pitch)
        db.session.commit()

        self.assertIsNotNone(self.pitch.id)
        self.assertEqual(self.pitch.pitch,
                         "Are you the wind? Because you're blowing me away.")
        self.assertEqual(self.pitch.likes, 0)
        self.assertEqual(self.pitch.dislikes, 3)
        self.assertEqual(self.pitch.time_posted,
                         datetime.datetime(2020, 11, 17, 3, 30))

    def test_save(self):
        """
        Test if save method commits new pitch to database
        """
        test_pitch = Pitch(
            pitch="Are you the wind? Because you're blowing me away.",
            likes=34,
            dislikes=43,
            user_id=1,
            time_posted="2020-11-17 03:30",
            category=Category.pickup_lines)

        # db.create_all()
        test_pitch.save()

        pitch = Pitch.query.filter_by(id=test_pitch.id).first()

        self.assertEqual(pitch.pitch,
                         "Are you the wind? Because you're blowing me away.")
        self.assertIsNotNone(pitch.user_id)

    def test_get_username(self):
        """
        Test case to see if get_username method returns username associated with pitch
        """
        self.pitch.save()

        username = self.pitch.get_username()

        self.assertEqual(
            User.query.filter_by(id=self.user.id).first().user_name, username)

    def test_get_profile_pic(self):
        """
        Test case to see if get_profile_pic method returns profile pic of user associated with pitch
        """
        self.pitch.save()

        profile_pic_path = self.pitch.get_profile_pic()

        self.assertEqual(
            User.query.filter_by(id=self.user.id).first().profile_pic_path,
            profile_pic_path)