|
| 1 | +from datetime import datetime |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | from requests.exceptions import HTTPError |
3 | 5 |
|
@@ -90,3 +92,49 @@ def test_cart_discount_update(old_client): |
90 | 92 | ) |
91 | 93 |
|
92 | 94 | assert cart_discount.is_active is False |
| 95 | + |
| 96 | + |
| 97 | +@pytest.mark.freeze_time("2021-03-01 12:34:56") |
| 98 | +def test_cart_discount_set_valid_from(old_client): |
| 99 | + cart_discount = old_client.cart_discounts.create( |
| 100 | + models.CartDiscountDraft( |
| 101 | + name=models.LocalizedString(en="en-cart_discount"), |
| 102 | + value=models.CartDiscountValueRelative(permyriad=10), |
| 103 | + is_active=True, |
| 104 | + cart_predicate="", |
| 105 | + sort_order="", |
| 106 | + requires_discount_code=False, |
| 107 | + ) |
| 108 | + ) |
| 109 | + assert cart_discount.id |
| 110 | + |
| 111 | + cart_discount = old_client.cart_discounts.update_by_id( |
| 112 | + id=cart_discount.id, |
| 113 | + version=cart_discount.version, |
| 114 | + actions=[models.CartDiscountSetValidFromAction(valid_from=datetime.now())], |
| 115 | + ) |
| 116 | + |
| 117 | + assert cart_discount.valid_from == datetime.now() |
| 118 | + |
| 119 | + |
| 120 | +@pytest.mark.freeze_time("2021-03-01 12:34:56") |
| 121 | +def test_cart_discount_set_valid_until(old_client): |
| 122 | + cart_discount = old_client.cart_discounts.create( |
| 123 | + models.CartDiscountDraft( |
| 124 | + name=models.LocalizedString(en="en-cart_discount"), |
| 125 | + value=models.CartDiscountValueRelative(permyriad=10), |
| 126 | + is_active=True, |
| 127 | + cart_predicate="", |
| 128 | + sort_order="", |
| 129 | + requires_discount_code=False, |
| 130 | + ) |
| 131 | + ) |
| 132 | + assert cart_discount.id |
| 133 | + |
| 134 | + cart_discount = old_client.cart_discounts.update_by_id( |
| 135 | + id=cart_discount.id, |
| 136 | + version=cart_discount.version, |
| 137 | + actions=[models.CartDiscountSetValidUntilAction(valid_until=datetime.now())], |
| 138 | + ) |
| 139 | + |
| 140 | + assert cart_discount.valid_until == datetime.now() |
0 commit comments