diff options
Diffstat (limited to 'alphabetlearning')
-rw-r--r-- | alphabetlearning/payments/tests/test_views.py | 35 | ||||
-rw-r--r-- | alphabetlearning/resources/factories.py | 2 | ||||
-rw-r--r-- | alphabetlearning/templates/base.html | 2 |
3 files changed, 36 insertions, 3 deletions
diff --git a/alphabetlearning/payments/tests/test_views.py b/alphabetlearning/payments/tests/test_views.py index 24bb19a..aebb040 100644 --- a/alphabetlearning/payments/tests/test_views.py +++ b/alphabetlearning/payments/tests/test_views.py @@ -21,3 +21,38 @@ def test_add_resource_to_cart(client, resource, user): response = client.get(url) # resdirects to the shopping cart assert response.status_code == 302 + + +@pytest.mark.django_db # Marks the test function as utilizing the Django database. +def test_cart_contains_resource_with_correct_price(client, resource, user): + # Create a Price object associated with the given resource, with a specified price and Stripe price ID. + # strip works with cents, so 2000 is 2.00 + price = Price.objects.create(resource=resource, price=2000, stripe_price_id="price_1") + + # Add the created price object to the resource's price objects. + # This is a many-to-many relationship, so we use the add method to add the price object to the resource's price_obj field. + resource.price_obj.add(price) + + # Generate the URL for adding the resource to the shopping basket using a reverse lookup. + addurl = reverse("payments:add_to_basket", kwargs={"resource_id": resource.id}) + + # Generate the URL for viewing the shopping cart. + carturl = reverse("payments:cart_detail") + + # Log in the user for the test client to simulate an authenticated user session. + client.force_login(user) + + # Send a GET request to the addurl to attempt to add the resource to the basket and store the response. + addresponse = client.get(addurl) + + # Check that the response status code indicates a successful redirection (302). + assert addresponse.status_code == 302 + + # Send a GET request to the carturl to retrieve the cart's contents and store the response. + cartresponse = client.get(carturl) + + # Assert that the resource's name is included in the cart response content, confirming it was added. + assert resource.name in str(cartresponse.content) + + # Assert that the correct price (formatted as '2.00') is displayed in the cart response content. + assert "2.00" in str(cartresponse.content) diff --git a/alphabetlearning/resources/factories.py b/alphabetlearning/resources/factories.py index 0f0194b..c8d2df4 100644 --- a/alphabetlearning/resources/factories.py +++ b/alphabetlearning/resources/factories.py @@ -37,11 +37,9 @@ class ResourceModelFactory(factory.django.DjangoModelFactory): model = Resource name = factory.Sequence(lambda n: f"Default Resource {n}") - # price = factory.Faker("pydecimal", left_digits=4, right_digits=2, positive=True) thumbnail_filenames = factory.List( [factory.Faker("file_name", extension="jpg") for _ in range(3)] ) - # price_obj = factory.RelatedFactoryList("alphabetlearning.payments.factories.PriceFactory", size=1) resource_type = factory.SubFactory(ResourceTypeModelFactory) main_resource_category = factory.SubFactory(ResourceCategoryModelFactory) subcategories = factory.RelatedFactoryList(ResourceCategoryModelFactory, size=2) diff --git a/alphabetlearning/templates/base.html b/alphabetlearning/templates/base.html index 2e28333..0fe30c5 100644 --- a/alphabetlearning/templates/base.html +++ b/alphabetlearning/templates/base.html @@ -12,7 +12,7 @@ {% endblock title %} </title> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> - <meta name="description" content="Joanna Lemon Resources"/> + <meta name="description" content="Alphabet Learning Educational Resources"/> <meta name="author" content="Matthew Lemon"/> <link rel="icon" href="{% static 'images/favicons/al.png' %}"/> {% block extra_css %} |