コード例 #1
0
ファイル: test_back_end.py プロジェクト: devops-cohort/amogh
    def test_review(self):
        """
        Test number of reviews in review table
        """

        # create test review
        review = Reviews(title="example",
                         author="anon",
                         rating="5",
                         review="Mediocre",
                         user_id="2")

        #save review to database
        db.session.add(review)
        db.session.commit

        self.assertEqual(Reviews.query.count(), 1)

        #update information
        review.author = "Anonymous"
        db.session.commit

        self.assertEqual(
            Reviews.query.filter_by(title='example').first().author,
            "Anonymous")

        #delete record
        db.session.delete(review)
        db.session.commit

        self.assertEqual(Reviews.query.count(), 0)
コード例 #2
0
ファイル: test_back_end.py プロジェクト: devops-cohort/Shaybs
 def test_reviews_model(self):
     dmytroReview = Reviews(review_author="Dmytro",
                            review="Interesting book",
                            rating="5",
                            book_id="1")
     db.session.add(dmytroReview)
     db.session.commit()
     self.assertEqual(Reviews.query.count(), 3)
コード例 #3
0
ファイル: test_back_end.py プロジェクト: devops-cohort/Shaybs
    def setUp(self):

        #Called before every test
        db.session.commit()
        db.drop_all()
        db.create_all()

        #Create test admin user
        admin = Users(first_name="admin",
                      last_name="admin",
                      email="*****@*****.**",
                      password="******")
        employee = Users(first_name="test",
                         last_name="user",
                         email="*****@*****.**",
                         password="******")
        BenjaminFranklin = Books(
            book="An American Life: Benjamin Franklin",
            author="Walter Isaacson",
            description="It is a biography of Benjamin Franklin",
            rating="5")
        ZeroToOne = Books(book="Zero To One",
                          author="Peter Thiel",
                          description="It stipulates business theory",
                          rating="5")
        ShuaibReview = Reviews(review_author="Shuaib",
                               review="Best book ever",
                               rating="5",
                               book_id="2")
        ThomasReview = Reviews(review_author="Thomas",
                               review="Interesting book",
                               rating="5",
                               book_id="2")

        #Save/Add users to the databse
        db.session.add(admin)
        db.session.add(employee)

        #Save/Add book to database
        db.session.add(BenjaminFranklin)
        db.session.add(ZeroToOne)

        #Save/Add reviews to database
        db.session.add(ShuaibReview)
        db.session.add(ThomasReview)
        db.session.commit()
コード例 #4
0
 def test_repr(self):
     game = Games(game_title='GTA V',
                  description='Gangs',
                  category='Action',
                  age_rating='18')
     print(repr(game))
     review = Reviews(first_name='oskar',
                      last_name='ceremnovas',
                      rating='5',
                      title='review',
                      review='good')
     print(repr(review))
コード例 #5
0
ファイル: test_app.py プロジェクト: kunalsxngh/CRUD_project
    def setUp(self):
        db.create_all()
        test_review = Reviews(author="Test author",
                              body="Test body",
                              rating=5,
                              game=1)
        db.session.add(test_review)
        db.session.commit()
        test_game = Games(name="Test game", genre="Test genre")

        db.session.add(test_game)
        db.session.commit()
        app.config['WTF_CSRF_ENABLED'] = False
コード例 #6
0
ファイル: routes.py プロジェクト: devops-cohort/amogh
def post():
    form = ReviewsForm()
    if form.validate_on_submit():
        postData = Reviews(title=form.title.data,
                           author=form.author.data,
                           rating=form.rating.data,
                           review=form.review.data,
                           user=current_user)

        db.session.add(postData)
        db.session.commit()
        return redirect(url_for('reviews'))

    else:
        print(form.errors)
    return render_template('post.html', title='Post', form=form)
コード例 #7
0
def review():
    form = ReviewForm()
    reviews = Reviews.query.all()
    if form.validate_on_submit():
        reviewData = Reviews(title=form.title.data,
                             content=form.content.data,
                             author=current_user)
        db.session.add(reviewData)
        db.session.commit()
        return redirect(url_for('review'))
    else:
        print(form.errors)
    return render_template('review.html',
                           title='Review',
                           form=form,
                           reviews=reviews)
コード例 #8
0
def review(car_id):
    form = ReviewForm()
    car = Cars.query.filter_by(car_id=car_id).first()
    if request.method == "POST":
        if form.validate_on_submit():
            new_review = Reviews(name=form.name.data,
                                 review=form.review.data,
                                 raiting=form.raiting.data,
                                 car_id=car_id)
            db.session.add(new_review)
            db.session.commit()
            return redirect(url_for("home"))
    return render_template("review.html",
                           form=form,
                           title="Add a Review",
                           review=review)
コード例 #9
0
def create():
    form = ReviewForm()
    if request.method == "POST":
        if form.validate_on_submit():

            game_name = form.recommendations.data.name
            game = Games.query.filter_by(name=game_name).first()
            new_review = Reviews(author=form.author.data,
                                 body=form.body.data,
                                 rating=form.rating.data,
                                 game=game.id)
            db.session.add(new_review)
            db.session.commit()
            return redirect(url_for("home"))

    return render_template('add.html', title="Create a task", form=form)
コード例 #10
0
 def setUp(self):
     db.create_all()
     test_game = Games(Title="test flask app",
                       Release_date="2020-12-18",
                       Genre="Horror",
                       Age_rating="26",
                       Description="All pain")
     db.session.add(test_game)
     db.session.commit()
     test_review = Reviews(Games_title="test flask app",
                           Review_title="test review table",
                           Reviewer_name="pytest",
                           Review_password="******",
                           Review="I hope I can see this",
                           Rating=10)
     db.session.add(test_review)
     db.session.commit()
コード例 #11
0
def review():
    form = ReviewForm()
    if form.validate_on_submit():
        game = Games.query.filter_by(game_title=form.game_title.data).first()
        reviewData = Reviews(game_id=game.id,
                             first_name=form.first_name.data,
                             last_name=form.last_name.data,
                             rating=form.rating.data,
                             title=form.title.data,
                             review=form.review.data)
        db.session.add(reviewData)
        db.session.commit()

        return redirect(url_for('home'))
    else:
        print(form.errors)

    return render_template('reviews.html', title="Game Reviews", form=form)
コード例 #12
0
def review(Title):
    form = Review()
    if request.method == 'POST':
        new_review = Reviews(Games_title=Title,
                             Review_title=form.Review_title.data,
                             Reviewer_name=form.Reviewer_name.data,
                             Review_password=form.Review_password.data,
                             Review=form.Review.data,
                             Rating=form.Rating.data)
        if not form.validate_on_submit(
        ):  #len(new_review.Review_title)>300 or len(new_review.Reviewer_name)>30 or len(new_review.Review_password)>30 or len(new_review.Review)>3000 or new_review.Rating is None or new_review.Rating<1 or new_review.Rating>10:
            return render_template('reviewerror.html',
                                   form=form,
                                   title="New review: " + Title)
        else:
            db.session.add(new_review)
            db.session.commit()
            return redirect(url_for("game", Title=new_review.Games_title))
    return render_template('review.html',
                           form=form,
                           title="New review: " + Title)
コード例 #13
0
ファイル: routes.py プロジェクト: devops-cohort/Shaybs
def add_review():

    add_review = True

    form = ReviewForm()
    if form.validate_on_submit():
        review = Reviews(review_author=form.review_author.data,
                         review=form.review.data,
                         rating=form.rating.data,
                         book_ref=form.book.data)
        try:
            db.session.add(review)
            db.session.commit()
            flash('You have successfully added a new Review')
        except:
            flash('Error: The review already exists')
        return redirect(url_for('reviews'))

    return render_template('review.html',
                           action="Add",
                           title='Add Review',
                           form=form,
                           add_review=add_review)
コード例 #14
0
    def setUp(self):
        """
        Will be called before every test
        """
        # ensure there is no data in the test database when the test starts
        db.session.commit()
        db.drop_all()
        db.create_all()

        game = Games(game_title='GTA V',
                     description='Gangs',
                     category='Action',
                     age_rating='18')
        # save data to database
        db.session.add(game)
        db.session.commit()
        review = Reviews(first_name='oskar',
                         last_name='ceremnovas',
                         rating='5',
                         title='review',
                         review='good')
        db.session.add(review)
        db.session.commit()
コード例 #15
0
    def setUp(self):

        #Set up the test driver
        print(
            "--------------------------NEXT-TEST----------------------------------------------"
        )
        chrome_options = Options()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        self.driver = webdriver.Chrome(chrome_options=chrome_options)
        db.drop_all()
        db.create_all()

        test_game = Games(name="Test game", genre="Test genre")
        test_review = Reviews(author="Test author",
                              body="Test body",
                              rating=5,
                              game=1)
        db.session.add(test_review)
        db.session.add(test_game)
        db.session.commit()
        self.driver.get("http://localhost:5000")

        #Turn off validation
        app.config['WTF_CSRF_ENABLED'] = False

        def tearDown(self):
            self.driver.quit()
            print(
                "--------------------------END-OF-TEST----------------------------------------------\n\n\n-------------------------UNIT-AND-SELENIUM-TESTS----------------------------------------------"
            )

        def test_server_is_up_and_running(self):
            response = urlopen("http://localhost:5000")
            self.assertEqual(response.code, 200)