<commit_before>from django.test import TestCase

# Create your tests here.<commit_msg>Add first test<commit_after>from django_webtest import WebTest

from django.conf import settings
from django.shortcuts import reverse

from apps.shop.models import Product


class CartWebTests(WebTest):

    fixtures = ['../load_data.json']

    def test_cart_add_product(self):
        product = Product.objects.order_by('?').first()

        # test GET Method (GET is not allowed)
        self.app.get(
            reverse(
                'cart:add_product',
                kwargs={'product_id': product.id}
            ),
            status=405,  # webtest.app.AppError in other case
        )

        # test POST Method
        form = self.app.get(
            reverse(
                'shop:product_detail',
                kwargs={'slug': product.slug},
            ),
        ).form
        qty = product.stock - 1 if product.stock != 1 else 1
        form['quantity'] = qty
        form.submit()

        cart = self.app.session[settings.CART_SESSION_ID]
        product_data = cart[str(product.id)]
        self.assertEqual(product_data['price'], str(product.price))
        self.assertEqual(product_data['quantity'], qty)
{'fraction_non_alphanumeric': 0.10819672131147541, 'fraction_numerical': 0.004918032786885246, 'mean_word_length': 2.1879895561357703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7512949', 'n_tokens_mistral': 352, 'n_tokens_neox': 336, 'n_words': 79}