Changeset - 87e6fa064a11
[Not reviewed]
Merge
1 7 3
Christopher Neugebauer - 8 years ago 2016-04-12 01:39:54
chrisjrn@gmail.com
Merge branch 'master' into admin_models_cleanup
9 files changed with 286 insertions and 143 deletions:
0 comments (0 inline, 0 general)
registrasion/admin.py
Show inline comments
...
 
@@ -101,4 +101,4 @@ class VoucherDiscountInline(nested_admin.NestedStackedInline):
 

	
 
class VoucherEnablingConditionInline(nested_admin.NestedStackedInline):
 
    model = rego.VoucherEnablingCondition
 
class VoucherFlagInline(nested_admin.NestedStackedInline):
 
    model = rego.VoucherFlag
 
    verbose_name = _("Product and category enabled by voucher")
...
 
@@ -124,3 +124,3 @@ class VoucherAdmin(nested_admin.NestedAdmin):
 
        try:
 
            enabling_effects = obj.voucherenablingcondition.effects()
 
            enabling_effects = obj.voucherflag.effects()
 
        except ObjectDoesNotExist:
...
 
@@ -139,3 +139,3 @@ class VoucherAdmin(nested_admin.NestedAdmin):
 
        VoucherDiscountInline,
 
        VoucherEnablingConditionInline,
 
        VoucherFlagInline,
 
    ]
...
 
@@ -144,4 +144,4 @@ class VoucherAdmin(nested_admin.NestedAdmin):
 
# Enabling conditions
 
@admin.register(rego.ProductEnablingCondition)
 
class ProductEnablingConditionAdmin(
 
@admin.register(rego.ProductFlag)
 
class ProductFlagAdmin(
 
        nested_admin.NestedAdmin,
...
 
@@ -152,3 +152,3 @@ class ProductEnablingConditionAdmin(
 

	
 
    model = rego.ProductEnablingCondition
 
    model = rego.ProductFlag
 
    fields = ("description", "enabling_products", "mandatory", "products",
...
 
@@ -160,4 +160,4 @@ class ProductEnablingConditionAdmin(
 
# Enabling conditions
 
@admin.register(rego.CategoryEnablingCondition)
 
class CategoryEnablingConditionAdmin(
 
@admin.register(rego.CategoryFlag)
 
class CategoryFlagAdmin(
 
        nested_admin.NestedAdmin,
...
 
@@ -165,3 +165,3 @@ class CategoryEnablingConditionAdmin(
 

	
 
    model = rego.CategoryEnablingCondition
 
    model = rego.CategoryFlag
 
    fields = ("description", "enabling_category", "mandatory", "products",
...
 
@@ -174,7 +174,7 @@ class CategoryEnablingConditionAdmin(
 
# Enabling conditions
 
@admin.register(rego.TimeOrStockLimitEnablingCondition)
 
class TimeOrStockLimitEnablingConditionAdmin(
 
@admin.register(rego.TimeOrStockLimitFlag)
 
class TimeOrStockLimitFlagAdmin(
 
        nested_admin.NestedAdmin,
 
        EffectsDisplayMixin):
 
    model = rego.TimeOrStockLimitEnablingCondition
 
    model = rego.TimeOrStockLimitFlag
 

	
registrasion/controllers/cart.py
Show inline comments
...
 
@@ -120,3 +120,3 @@ class CartController(object):
 
        ''' Tests that the quantity changes we intend to make do not violate
 
        the limits and enabling conditions imposed on the products. '''
 
        the limits and flag conditions imposed on the products. '''
 

	
...
 
@@ -161,4 +161,4 @@ class CartController(object):
 

	
 
        # Test the enabling conditions
 
        errs = ConditionController.test_enabling_conditions(
 
        # Test the flag conditions
 
        errs = ConditionController.test_flags(
 
            self.cart.user,
registrasion/controllers/conditions.py
Show inline comments
...
 
@@ -22,3 +22,3 @@ ConditionAndRemainder = namedtuple(
 
class ConditionController(object):
 
    ''' Base class for testing conditions that activate EnablingCondition
 
    ''' Base class for testing conditions that activate Flag
 
    or Discount objects. '''
...
 
@@ -31,11 +31,11 @@ class ConditionController(object):
 
        CONTROLLERS = {
 
            rego.CategoryEnablingCondition: CategoryConditionController,
 
            rego.CategoryFlag: CategoryConditionController,
 
            rego.IncludedProductDiscount: ProductConditionController,
 
            rego.ProductEnablingCondition: ProductConditionController,
 
            rego.ProductFlag: ProductConditionController,
 
            rego.TimeOrStockLimitDiscount:
 
                TimeOrStockLimitDiscountController,
 
            rego.TimeOrStockLimitEnablingCondition:
 
                TimeOrStockLimitEnablingConditionController,
 
            rego.TimeOrStockLimitFlag:
 
                TimeOrStockLimitFlagController,
 
            rego.VoucherDiscount: VoucherConditionController,
 
            rego.VoucherEnablingCondition: VoucherConditionController,
 
            rego.VoucherFlag: VoucherConditionController,
 
        }
...
 
@@ -67,5 +67,5 @@ class ConditionController(object):
 
    @classmethod
 
    def test_enabling_conditions(
 
    def test_flags(
 
            cls, user, products=None, product_quantities=None):
 
        ''' Evaluates all of the enabling conditions on the given products.
 
        ''' Evaluates all of the flag conditions on the given products.
 

	
...
 
@@ -76,3 +76,3 @@ class ConditionController(object):
 

	
 
        If all enabling conditions pass, an empty list is returned, otherwise
 
        If all flag conditions pass, an empty list is returned, otherwise
 
        a list is returned containing all of the products that are *not
...
 
@@ -92,5 +92,4 @@ class ConditionController(object):
 
        # Get the conditions covered by the products themselves
 

	
 
        prods = (
 
            product.enablingconditionbase_set.select_subclasses()
 
            product.flagbase_set.select_subclasses()
 
            for product in products
...
 
@@ -99,3 +98,3 @@ class ConditionController(object):
 
        cats = (
 
            category.enablingconditionbase_set.select_subclasses()
 
            category.flagbase_set.select_subclasses()
 
            for category in set(product.category for product in products)
...
 
@@ -109,7 +108,7 @@ class ConditionController(object):
 

	
 
        # All mandatory conditions on a product need to be met
 
        mandatory = defaultdict(lambda: True)
 
        # At least one non-mandatory condition on a product must be met
 
        # if there are no mandatory conditions
 
        non_mandatory = defaultdict(lambda: False)
 
        # All disable-if-false conditions on a product need to be met
 
        do_not_disable = defaultdict(lambda: True)
 
        # At least one enable-if-true condition on a product must be met
 
        do_enable = defaultdict(lambda: False)
 
        # (if either sort of condition is present)
 

	
...
 
@@ -148,6 +147,6 @@ class ConditionController(object):
 
            for product in all_products:
 
                if condition.mandatory:
 
                    mandatory[product] &= met
 
                if condition.is_disable_if_false:
 
                    do_not_disable[product] &= met
 
                else:
 
                    non_mandatory[product] |= met
 
                    do_enable[product] |= met
 

	
...
 
@@ -156,10 +155,11 @@ class ConditionController(object):
 

	
 
        valid = defaultdict(lambda: True)
 
        for product in itertools.chain(mandatory, non_mandatory):
 
            if product in mandatory:
 
                # If there's a mandatory condition, all must be met
 
                valid[product] = mandatory[product]
 
            else:
 
                # Otherwise, we need just one non-mandatory condition met
 
                valid[product] = non_mandatory[product]
 
        valid = {}
 
        for product in itertools.chain(do_not_disable, do_enable):
 
            if product in do_enable:
 
                # If there's an enable-if-true, we need need of those met too.
 
                # (do_not_disable will default to true otherwise)
 
                valid[product] = do_not_disable[product] and do_enable[product]
 
            elif product in do_not_disable:
 
                # If there's a disable-if-false condition, all must be met
 
                valid[product] = do_not_disable[product]
 

	
...
 
@@ -173,3 +173,3 @@ class ConditionController(object):
 
    def user_quantity_remaining(self, user):
 
        ''' Returns the number of items covered by this enabling condition the
 
        ''' Returns the number of items covered by this flag condition the
 
        user can add to the current cart. This default implementation returns
...
 
@@ -183,3 +183,3 @@ class ConditionController(object):
 
    def is_met(self, user):
 
        ''' Returns True if this enabling condition is met, otherwise returns
 
        ''' Returns True if this flag condition is met, otherwise returns
 
        False.
...
 
@@ -213,3 +213,3 @@ class CategoryConditionController(ConditionController):
 
class ProductConditionController(ConditionController):
 
    ''' Condition tests for ProductEnablingCondition and
 
    ''' Condition tests for ProductFlag and
 
    IncludedProductDiscount. '''
...
 
@@ -232,3 +232,3 @@ class ProductConditionController(ConditionController):
 
class TimeOrStockLimitConditionController(ConditionController):
 
    ''' Common condition tests for TimeOrStockLimit EnablingCondition and
 
    ''' Common condition tests for TimeOrStockLimit Flag and
 
    Discount.'''
...
 
@@ -282,3 +282,3 @@ class TimeOrStockLimitConditionController(ConditionController):
 

	
 
class TimeOrStockLimitEnablingConditionController(
 
class TimeOrStockLimitFlagController(
 
        TimeOrStockLimitConditionController):
...
 
@@ -307,3 +307,3 @@ class TimeOrStockLimitDiscountController(TimeOrStockLimitConditionController):
 
class VoucherConditionController(ConditionController):
 
    ''' Condition test for VoucherEnablingCondition and VoucherDiscount.'''
 
    ''' Condition test for VoucherFlag and VoucherDiscount.'''
 

	
registrasion/controllers/product.py
Show inline comments
...
 
@@ -17,5 +17,5 @@ class ProductController(object):
 
        ''' Returns a list of all of the products that are available per
 
        enabling conditions from the given categories.
 
        flag conditions from the given categories.
 
        TODO: refactor so that all conditions are tested here and
 
        can_add_with_enabling_conditions calls this method. '''
 
        can_add_with_flags calls this method. '''
 
        if category is None and products is None:
...
 
@@ -47,3 +47,3 @@ class ProductController(object):
 

	
 
        failed_and_messages = ConditionController.test_enabling_conditions(
 
        failed_and_messages = ConditionController.test_flags(
 
            user, products=passed_limits
registrasion/migrations/0021_auto_20160411_0748_squashed_0024_auto_20160411_2230.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# Generated by Django 1.9.2 on 2016-04-11 22:46
 
from __future__ import unicode_literals
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('registrasion', '0020_auto_20160411_0258'),
 
    ]
 

	
 
    operations = [
 
        migrations.RenameModel(
 
            old_name='CategoryEnablingCondition',
 
            new_name='CategoryFlag',
 
        ),
 
        migrations.RenameModel(
 
            old_name='ProductEnablingCondition',
 
            new_name='ProductFlag',
 
        ),
 
        migrations.RenameModel(
 
            old_name='TimeOrStockLimitEnablingCondition',
 
            new_name='TimeOrStockLimitFlag',
 
        ),
 
        migrations.RenameModel(
 
            old_name='VoucherEnablingCondition',
 
            new_name='VoucherFlag',
 
        ),
 
        migrations.AlterModelOptions(
 
            name='categoryflag',
 
            options={'verbose_name': 'flag (dependency on product from category)', 'verbose_name_plural': 'flags (dependency on product from category)'},
 
        ),
 
        migrations.AlterModelOptions(
 
            name='productflag',
 
            options={'verbose_name': 'flag (dependency on product)', 'verbose_name_plural': 'flags (dependency on product)'},
 
        ),
 
        migrations.AlterModelOptions(
 
            name='timeorstocklimitflag',
 
            options={'verbose_name': 'flag (time/stock limit)', 'verbose_name_plural': 'flags (time/stock limit)'},
 
        ),
 
        migrations.AlterModelOptions(
 
            name='voucherflag',
 
            options={'verbose_name': 'flag (dependency on voucher)', 'verbose_name_plural': 'flags (dependency on voucher)'},
 
        ),
 
        migrations.AlterField(
 
            model_name='enablingconditionbase',
 
            name='categories',
 
            field=models.ManyToManyField(blank=True, help_text="Categories whose products are affected by this flag's condition.", to=b'registrasion.Category'),
 
        ),
 
        migrations.RenameField(
 
            model_name='enablingconditionbase',
 
            old_name='mandatory',
 
            new_name='condition',
 
        ),
 
        migrations.AlterField(
 
            model_name='enablingconditionbase',
 
            name='condition',
 
            field=models.IntegerField(choices=[(1, 'Disable if false'), (2, 'Enable if true')], default=2, help_text="If there is at least one 'disable if false' flag defined on a product or category, all such flag  conditions must be met. If there is at least one 'enable if true' flag, at least one such condition must be met. If both types of conditions exist on a product, both of these rules apply."),
 
        ),
 
        migrations.AlterField(
 
            model_name='enablingconditionbase',
 
            name='products',
 
            field=models.ManyToManyField(blank=True, help_text="Products affected by this flag's condition.", to=b'registrasion.Product'),
 
        ),
 
        migrations.AlterField(
 
            model_name='enablingconditionbase',
 
            name='categories',
 
            field=models.ManyToManyField(blank=True, help_text="Categories whose products are affected by this flag's condition.", related_name='flagbase_set', to=b'registrasion.Category'),
 
        ),
 
        migrations.AlterField(
 
            model_name='enablingconditionbase',
 
            name='products',
 
            field=models.ManyToManyField(blank=True, help_text="Products affected by this flag's condition.", related_name='flagbase_set', to=b'registrasion.Product'),
 
        ),
 
    ]
registrasion/models.py
Show inline comments
...
 
@@ -381,11 +381,23 @@ class RoleDiscount(object):
 
@python_2_unicode_compatible
 
class EnablingConditionBase(models.Model):
 
class FlagBase(models.Model):
 
    ''' This defines a condition which allows products or categories to
 
    be made visible. If there is at least one mandatory enabling condition
 
    defined on a Product or Category, it will only be enabled if *all*
 
    mandatory conditions are met, otherwise, if there is at least one enabling
 
    condition defined on a Product or Category, it will only be enabled if at
 
    least one condition is met. '''
 
    be made visible, or be prevented from being visible.
 

	
 
    objects = InheritanceManager()
 
    The various subclasses of this can define the conditions that enable
 
    or disable products, by the following rules:
 

	
 
    If there is at least one 'disable if false' flag defined on a product or
 
    category, all such flag conditions must be met. If there is at least one
 
    'enable if true' flag, at least one such condition must be met.
 

	
 
    If both types of conditions exist on a product, both of these rules apply.
 
    '''
 

	
 
    class Meta:
 
        # TODO: make concrete once https://code.djangoproject.com/ticket/26488
 
        # is solved.
 
        abstract = True
 

	
 
    DISABLE_IF_FALSE = 1
 
    ENABLE_IF_TRUE = 2
 

	
...
 
@@ -395,12 +407,27 @@ class EnablingConditionBase(models.Model):
 
    def effects(self):
 
        ''' Returns all of the items enabled by this condition. '''
 
        ''' Returns all of the items affected by this condition. '''
 
        return itertools.chain(self.products.all(), self.categories.all())
 

	
 
    @property
 
    def is_disable_if_false(self):
 
        return self.condition == FlagBase.DISABLE_IF_FALSE
 

	
 
    @property
 
    def is_enable_if_true(self):
 
        return self.condition == FlagBase.ENABLE_IF_TRUE
 

	
 
    description = models.CharField(max_length=255)
 
    mandatory = models.BooleanField(
 
        default=False,
 
        help_text=_("If there is at least one mandatory condition defined on "
 
                    "a product or category, all such conditions must be met. "
 
                    "Otherwise, at least one non-mandatory condition must be "
 
                    "met."),
 
    condition = models.IntegerField(
 
        default=ENABLE_IF_TRUE,
 
        choices=(
 
            (DISABLE_IF_FALSE, _("Disable if false")),
 
            (ENABLE_IF_TRUE, _("Enable if true")),
 
        ),
 
        help_text=_("If there is at least one 'disable if false' flag "
 
                    "defined on a product or category, all such flag "
 
                    " conditions must be met. If there is at least one "
 
                    "'enable if true' flag, at least one such condition must "
 
                    "be met. If both types of conditions exist on a product, "
 
                    "both of these rules apply."
 
        ),
 
    )
...
 
@@ -409,3 +436,4 @@ class EnablingConditionBase(models.Model):
 
        blank=True,
 
        help_text=_("Products that are enabled if this condition is met."),
 
        help_text=_("Products affected by this flag's condition."),
 
        related_name="flagbase_set",
 
    )
...
 
@@ -414,4 +442,6 @@ class EnablingConditionBase(models.Model):
 
        blank=True,
 
        help_text=_("Categories whose products are enabled if this condition "
 
                    "is met."),
 
        help_text=_("Categories whose products are affected by this flag's "
 
                    "condition."
 
        ),
 
        related_name="flagbase_set",
 
    )
...
 
@@ -419,3 +449,12 @@ class EnablingConditionBase(models.Model):
 

	
 
class TimeOrStockLimitEnablingCondition(EnablingConditionBase):
 
class EnablingConditionBase(FlagBase):
 
    ''' Reifies the abstract FlagBase. This is necessary because django
 
    prevents renaming base classes in migrations. '''
 
    # TODO: remove this, and make subclasses subclass FlagBase once
 
    # https://code.djangoproject.com/ticket/26488 is solved.
 

	
 
    objects = InheritanceManager()
 

	
 

	
 
class TimeOrStockLimitFlag(EnablingConditionBase):
 
    ''' Registration product ceilings '''
...
 
@@ -423,3 +462,4 @@ class TimeOrStockLimitEnablingCondition(EnablingConditionBase):
 
    class Meta:
 
        verbose_name = _("ceiling")
 
        verbose_name = _("flag (time/stock limit)")
 
        verbose_name_plural = _("flags (time/stock limit)")
 

	
...
 
@@ -446,5 +486,9 @@ class TimeOrStockLimitEnablingCondition(EnablingConditionBase):
 
@python_2_unicode_compatible
 
class ProductEnablingCondition(EnablingConditionBase):
 
class ProductFlag(EnablingConditionBase):
 
    ''' The condition is met because a specific product is purchased. '''
 

	
 
    class Meta:
 
        verbose_name = _("flag (dependency on product)")
 
        verbose_name_plural = _("flags (dependency on product)")
 

	
 
    def __str__(self):
...
 
@@ -460,3 +504,3 @@ class ProductEnablingCondition(EnablingConditionBase):
 
@python_2_unicode_compatible
 
class CategoryEnablingCondition(EnablingConditionBase):
 
class CategoryFlag(EnablingConditionBase):
 
    ''' The condition is met because a product in a particular product is
...
 
@@ -464,2 +508,6 @@ class CategoryEnablingCondition(EnablingConditionBase):
 

	
 
    class Meta:
 
        verbose_name = _("flag (dependency on product from category)")
 
        verbose_name_plural = _("flags (dependency on product from category)")
 

	
 
    def __str__(self):
...
 
@@ -475,3 +523,3 @@ class CategoryEnablingCondition(EnablingConditionBase):
 
@python_2_unicode_compatible
 
class VoucherEnablingCondition(EnablingConditionBase):
 
class VoucherFlag(EnablingConditionBase):
 
    ''' The condition is met because a Voucher is present. This is for e.g.
...
 
@@ -479,2 +527,6 @@ class VoucherEnablingCondition(EnablingConditionBase):
 

	
 
    class Meta:
 
        verbose_name = _("flag (dependency on voucher)")
 
        verbose_name_plural = _("flags (dependency on voucher)")
 

	
 
    def __str__(self):
...
 
@@ -486,6 +538,6 @@ class VoucherEnablingCondition(EnablingConditionBase):
 
# @python_2_unicode_compatible
 
class RoleEnablingCondition(object):
 
class RoleFlag(object):
 
    ''' The condition is met because the active user has a particular Role.
 
    This is for e.g. enabling Team tickets. '''
 
    # TODO: implement RoleEnablingCondition
 
    # TODO: implement RoleFlag
 
    pass
registrasion/tests/test_cart.py
Show inline comments
...
 
@@ -97,5 +97,5 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
    def make_ceiling(cls, name, limit=None, start_time=None, end_time=None):
 
        limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(
 
        limit_ceiling = rego.TimeOrStockLimitFlag.objects.create(
 
            description=name,
 
            mandatory=True,
 
            condition=rego.FlagBase.DISABLE_IF_FALSE,
 
            limit=limit,
...
 
@@ -111,5 +111,5 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
            cls, name, limit=None, start_time=None, end_time=None):
 
        limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(
 
        limit_ceiling = rego.TimeOrStockLimitFlag.objects.create(
 
            description=name,
 
            mandatory=True,
 
            condition=rego.FlagBase.DISABLE_IF_FALSE,
 
            limit=limit,
registrasion/tests/test_flag.py
Show inline comments
 
file renamed from registrasion/tests/test_enabling_condition.py to registrasion/tests/test_flag.py
...
 
@@ -14,44 +14,44 @@ UTC = pytz.timezone('UTC')
 

	
 
class EnablingConditionTestCases(RegistrationCartTestCase):
 
class FlagTestCases(RegistrationCartTestCase):
 

	
 
    @classmethod
 
    def add_product_enabling_condition(cls, mandatory=False):
 
        ''' Adds a product enabling condition: adding PROD_1 to a cart is
 
    def add_product_flag(cls, condition=rego.FlagBase.ENABLE_IF_TRUE):
 
        ''' Adds a product flag condition: adding PROD_1 to a cart is
 
        predicated on adding PROD_2 beforehand. '''
 
        enabling_condition = rego.ProductEnablingCondition.objects.create(
 
        flag = rego.ProductFlag.objects.create(
 
            description="Product condition",
 
            mandatory=mandatory,
 
            condition=condition,
 
        )
 
        enabling_condition.save()
 
        enabling_condition.products.add(cls.PROD_1)
 
        enabling_condition.enabling_products.add(cls.PROD_2)
 
        enabling_condition.save()
 
        flag.save()
 
        flag.products.add(cls.PROD_1)
 
        flag.enabling_products.add(cls.PROD_2)
 
        flag.save()
 

	
 
    @classmethod
 
    def add_product_enabling_condition_on_category(cls, mandatory=False):
 
        ''' Adds a product enabling condition that operates on a category:
 
    def add_product_flag_on_category(cls, condition=rego.FlagBase.ENABLE_IF_TRUE):
 
        ''' Adds a product flag condition that operates on a category:
 
        adding an item from CAT_1 is predicated on adding PROD_3 beforehand '''
 
        enabling_condition = rego.ProductEnablingCondition.objects.create(
 
        flag = rego.ProductFlag.objects.create(
 
            description="Product condition",
 
            mandatory=mandatory,
 
            condition=condition,
 
        )
 
        enabling_condition.save()
 
        enabling_condition.categories.add(cls.CAT_1)
 
        enabling_condition.enabling_products.add(cls.PROD_3)
 
        enabling_condition.save()
 
        flag.save()
 
        flag.categories.add(cls.CAT_1)
 
        flag.enabling_products.add(cls.PROD_3)
 
        flag.save()
 

	
 
    def add_category_enabling_condition(cls, mandatory=False):
 
        ''' Adds a category enabling condition: adding PROD_1 to a cart is
 
    def add_category_flag(cls, condition=rego.FlagBase.ENABLE_IF_TRUE):
 
        ''' Adds a category flag condition: adding PROD_1 to a cart is
 
        predicated on adding an item from CAT_2 beforehand.'''
 
        enabling_condition = rego.CategoryEnablingCondition.objects.create(
 
        flag = rego.CategoryFlag.objects.create(
 
            description="Category condition",
 
            mandatory=mandatory,
 
            condition=condition,
 
            enabling_category=cls.CAT_2,
 
        )
 
        enabling_condition.save()
 
        enabling_condition.products.add(cls.PROD_1)
 
        enabling_condition.save()
 
        flag.save()
 
        flag.products.add(cls.PROD_1)
 
        flag.save()
 

	
 
    def test_product_enabling_condition_enables_product(self):
 
        self.add_product_enabling_condition()
 
    def test_product_flag_enables_product(self):
 
        self.add_product_flag()
 

	
...
 
@@ -66,3 +66,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_product_enabled_by_product_in_previous_cart(self):
 
        self.add_product_enabling_condition()
 
        self.add_product_flag()
 

	
...
 
@@ -77,4 +77,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_product_enabling_condition_enables_category(self):
 
        self.add_product_enabling_condition_on_category()
 
    def test_product_flag_enables_category(self):
 
        self.add_product_flag_on_category()
 

	
...
 
@@ -88,4 +88,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_category_enabling_condition_enables_product(self):
 
        self.add_category_enabling_condition()
 
    def test_category_flag_enables_product(self):
 
        self.add_category_flag()
 

	
...
 
@@ -101,3 +101,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_product_enabled_by_category_in_previous_cart(self):
 
        self.add_category_enabling_condition()
 
        self.add_category_flag()
 

	
...
 
@@ -112,7 +112,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_multiple_non_mandatory_conditions(self):
 
        self.add_product_enabling_condition()
 
        self.add_category_enabling_condition()
 
    def test_multiple_eit_conditions(self):
 
        self.add_product_flag()
 
        self.add_category_flag()
 

	
 
        # User 1 is testing the product enabling condition
 
        # User 1 is testing the product flag condition
 
        cart_1 = TestingCartController.for_user(self.USER_1)
...
 
@@ -124,3 +124,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
        # User 2 is testing the category enabling condition
 
        # User 2 is testing the category flag condition
 
        cart_2 = TestingCartController.for_user(self.USER_2)
...
 
@@ -132,5 +132,5 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_multiple_mandatory_conditions(self):
 
        self.add_product_enabling_condition(mandatory=True)
 
        self.add_category_enabling_condition(mandatory=True)
 
    def test_multiple_dif_conditions(self):
 
        self.add_product_flag(condition=rego.FlagBase.DISABLE_IF_FALSE)
 
        self.add_category_flag(condition=rego.FlagBase.DISABLE_IF_FALSE)
 

	
...
 
@@ -146,5 +146,5 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_mandatory_conditions_are_mandatory(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
        self.add_category_enabling_condition(mandatory=True)
 
    def test_eit_and_dif_conditions_work_together(self):
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 
        self.add_category_flag(condition=rego.FlagBase.DISABLE_IF_FALSE)
 

	
...
 
@@ -154,6 +154,20 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
            cart_1.add_to_cart(self.PROD_1, 1)
 
        cart_1.add_to_cart(self.PROD_2, 1)  # Meets the product condition
 

	
 
        cart_1.add_to_cart(self.PROD_2, 1)  # Meets the EIT condition
 

	
 
        # Need to meet both conditions before you can add
 
        with self.assertRaises(ValidationError):
 
            cart_1.add_to_cart(self.PROD_1, 1)
 
        cart_1.add_to_cart(self.PROD_3, 1)  # Meets the category condition
 

	
 
        cart_1.set_quantity(self.PROD_2, 0)  # Un-meets the EIT condition
 

	
 
        cart_1.add_to_cart(self.PROD_3, 1)  # Meets the DIF condition
 

	
 
        # Need to meet both conditions before you can add
 
        with self.assertRaises(ValidationError):
 
            cart_1.add_to_cart(self.PROD_1, 1)
 

	
 
        cart_1.add_to_cart(self.PROD_2, 1)  # Meets the EIT condition
 

	
 
        # Now that both conditions are met, we can add the product
 
        cart_1.add_to_cart(self.PROD_1, 1)
...
 
@@ -188,3 +202,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_available_products_on_category_works_when_condition_not_met(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -199,3 +213,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_available_products_on_category_works_when_condition_is_met(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -213,3 +227,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_available_products_on_products_works_when_condition_not_met(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -224,3 +238,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_available_products_on_products_works_when_condition_is_met(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -237,4 +251,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_category_enabling_condition_fails_if_cart_refunded(self):
 
        self.add_category_enabling_condition(mandatory=False)
 
    def test_category_flag_fails_if_cart_refunded(self):
 
        self.add_category_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -255,4 +269,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_product_enabling_condition_fails_if_cart_refunded(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
    def test_product_flag_fails_if_cart_refunded(self):
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -274,3 +288,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_available_categories(self):
 
        self.add_product_enabling_condition_on_category(mandatory=False)
 
        self.add_product_flag_on_category(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -294,4 +308,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    def test_validate_cart_when_enabling_conditions_become_unmet(self):
 
        self.add_product_enabling_condition(mandatory=False)
 
    def test_validate_cart_when_flags_become_unmet(self):
 
        self.add_product_flag(condition=rego.FlagBase.ENABLE_IF_TRUE)
 

	
...
 
@@ -311,3 +325,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
    def test_fix_simple_errors_resolves_unavailable_products(self):
 
        self.test_validate_cart_when_enabling_conditions_become_unmet()
 
        self.test_validate_cart_when_flags_become_unmet()
 
        cart = TestingCartController.for_user(self.USER_1)
registrasion/tests/test_voucher.py
Show inline comments
...
 
@@ -60,10 +60,10 @@ class VoucherTestCases(RegistrationCartTestCase):
 

	
 
        enabling_condition = rego.VoucherEnablingCondition.objects.create(
 
        flag = rego.VoucherFlag.objects.create(
 
            description="Voucher condition",
 
            voucher=voucher,
 
            mandatory=False,
 
            condition=rego.FlagBase.ENABLE_IF_TRUE,
 
        )
 
        enabling_condition.save()
 
        enabling_condition.products.add(self.PROD_1)
 
        enabling_condition.save()
 
        flag.save()
 
        flag.products.add(self.PROD_1)
 
        flag.save()
 

	
0 comments (0 inline, 0 general)