<commit_before>from datetime import timedelta
import re

from django.utils import timezone
from django.test import TestCase

from coupons.models import Coupon
from coupons.settings import CODE_LENGTH, CODE_CHARS


class CouponTestCase(TestCase):
    def test_generate_code(self):
        self.assertIsNotNone(re.match("^[%s]{%d}" % (CODE_CHARS, CODE_LENGTH,), Coupon.generate_code()))

    def test_save(self):
        coupon = Coupon(type='monetary', value=100)
        coupon.save()
        self.assertTrue(coupon.pk)

    def test_create_coupon(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        self.assertTrue(coupon.pk)

    def test_create_coupons(self):
        coupons = Coupon.objects.create_coupons(50, 'monetary', 100)
        for coupon in coupons:
            self.assertTrue(coupon.pk)

    def test_redeem(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        coupon.redeem()
        self.assertIsNotNone(coupon.redeemed_at)

    def test_expired(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        self.assertFalse(coupon.expired())
        coupon.valid_until = timezone.now()-timedelta(1)
        self.assertTrue(coupon.expired())<commit_msg>add test case for coupon str repr<commit_after>from datetime import timedelta
import re

from django.utils import timezone
from django.test import TestCase

from coupons.models import Coupon
from coupons.settings import CODE_LENGTH, CODE_CHARS


class CouponTestCase(TestCase):
    def test_generate_code(self):
        self.assertIsNotNone(re.match("^[%s]{%d}" % (CODE_CHARS, CODE_LENGTH,), Coupon.generate_code()))

    def test_save(self):
        coupon = Coupon(type='monetary', value=100)
        coupon.save()
        self.assertTrue(coupon.pk)

    def test_create_coupon(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        self.assertTrue(coupon.pk)

    def test_create_coupons(self):
        coupons = Coupon.objects.create_coupons(50, 'monetary', 100)
        for coupon in coupons:
            self.assertTrue(coupon.pk)

    def test_redeem(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        coupon.redeem()
        self.assertIsNotNone(coupon.redeemed_at)

    def test_expired(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        self.assertFalse(coupon.expired())
        coupon.valid_until = timezone.now()-timedelta(1)
        self.assertTrue(coupon.expired())

    def test_str(self):
        coupon = Coupon.objects.create_coupon('monetary', 100)
        self.assertEqual(coupon.code, str(coupon))
{'fraction_non_alphanumeric': 0.11090011393847322, 'fraction_numerical': 0.014812001519179644, 'mean_word_length': 3.479591836734694, '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': '1180316', 'n_tokens_mistral': 896, 'n_tokens_neox': 892, 'n_words': 154}