app-MAIL-temp/tests/dashboard/test_coupon.py

21 lines
517 B
Python
Raw Normal View History

2023-05-03 16:01:21 +02:00
from flask import url_for
from app.models import Coupon
from app.utils import random_string
from tests.utils import login
def test_use_coupon(flask_client):
2023-05-03 16:11:59 +02:00
user = login(flask_client)
2023-05-03 16:01:21 +02:00
code = random_string(10)
Coupon.create(code=code, nb_year=1, commit=True)
r = flask_client.post(
url_for("dashboard.coupon_route"),
data={"code": code},
)
2023-05-03 16:11:59 +02:00
assert r.status_code == 302
coupon = Coupon.get_by(code=code)
assert coupon.used
assert coupon.used_by_user_id == user.id