예제 #1
0
def test_reviews(empty_database):
    product1 = Product(name="Test product1", description="description")
    review1 = Review(id=b"1", product_id=1, review="Review 1!", rate=1)
    review2 = Review(id=b"2", product_id=1, review="Review 2!", rate=4)
    empty_database.session.add_all([product1, review1, review2])
    empty_database.session.commit()
    reviews = product1.reviews
    assert reviews[0].id == b"1"
    assert reviews[0].review == "Review 1!"
    assert reviews[1].id == b"2"
    assert reviews[1].review == "Review 2!"
    assert product1.rate == 2.5
예제 #2
0
def test_big_rate(empty_database):
    review = Review(id=b"1",
                    product_id=1,
                    review="Review test_create!",
                    rate=10)
    empty_database.session.add(review)
    with pytest.raises(sqlalchemy.exc.IntegrityError):
        empty_database.session.commit()
예제 #3
0
def test_russian_create(empty_database):
    review = Review(id=b"1",
                    product_id=1,
                    review="Комментарий о продукте from Russia",
                    rate=3)
    empty_database.session.add(review)
    empty_database.session.commit()
    assert review.id == b"1"
    assert review.product_id == 1
    assert review.rate == 3
    assert review.review == "Комментарий о продукте from Russia"
    assert isinstance(review.created_time, datetime.datetime)
예제 #4
0
def test_create(empty_database):
    review = Review(id=b"1",
                    product_id=1,
                    review="Review test_create!",
                    rate=1)
    empty_database.session.add(review)
    empty_database.session.commit()
    assert review.id == b"1"
    assert review.product_id == 1
    assert review.rate == 1
    assert review.review == "Review test_create!"
    assert isinstance(review.created_time, datetime.datetime)
예제 #5
0
def test_nullable_review(empty_database):
    review = Review(product_id=1)
    empty_database.session.add(review)
    with pytest.raises(sqlalchemy.exc.IntegrityError):
        empty_database.session.commit()