-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic test for the create_with_products endpoint
needs some additional tests, but need to switch gears for a bit
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""View tests for the v0 API.""" | ||
|
||
import pytest | ||
|
||
from payments.factories import ProductFactory | ||
from payments.models import Basket | ||
from system_meta.factories import ActiveIntegratedSystemFactory | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_create_basket_with_products(mocker, user_client): | ||
"""Test creating a basket with products.""" | ||
|
||
mocker.patch("payments.api.send_pre_sale_webhook") | ||
system = ActiveIntegratedSystemFactory() | ||
products = ProductFactory.create_batch(size=2, system=system) | ||
|
||
url = "/api/v0/payments/baskets/create_with_products/" | ||
response = user_client.post( | ||
url, | ||
data={ | ||
"system_slug": system.slug, | ||
"skus": [{"sku": product.sku, "quantity": 1} for product in products], | ||
}, | ||
) | ||
assert response.status_code in ( | ||
200, | ||
201, | ||
) | ||
|
||
basket_id = response.data["id"] | ||
assert Basket.objects.get(id=basket_id).basket_items.count() == 2 |