Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources: add default_min_price/default_max_price check to free filt… #172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion resources/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def free_of_charge(self, is_free):
queryset = self.annotate(
has_pricing=models.Exists(
self.filter(
Q(
Q(default_min_price__gt=0)
| Q(default_max_price__gt=0)
| Q(
products__pricedproduct__price_list__usergroup_prices__price__gt=0,
)
| Q(
Expand Down
72 changes: 72 additions & 0 deletions resources/tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,78 @@ def test_free_of_charge_free_to_use_true_no_pricing_info(space_resource):
assert Resource.objects.free_of_charge(False).count() == 0


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_has_default_min_price(space_resource):
space_resource.free_to_use = False
space_resource.default_min_price = Decimal("10.00")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 0
assert Resource.objects.free_of_charge(False).count() == 1


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_has_default_max_price(space_resource):
space_resource.free_to_use = False
space_resource.default_min_price = Decimal("0")
space_resource.default_max_price = Decimal("10.00")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 0
assert Resource.objects.free_of_charge(False).count() == 1


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_has_default_min_max_price(space_resource):
space_resource.free_to_use = False
space_resource.default_min_price = Decimal("10.00")
space_resource.default_max_price = Decimal("20.00")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 0
assert Resource.objects.free_of_charge(False).count() == 1


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_has_default_min_price_zero(space_resource):
space_resource.free_to_use = False
space_resource.default_min_price = Decimal("0")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 1
assert Resource.objects.free_of_charge(False).count() == 0


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_has_default_min_price_null(space_resource):
space_resource.free_to_use = False
space_resource.default_min_price = None
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 1
assert Resource.objects.free_of_charge(False).count() == 0


@pytest.mark.django_db
def test_free_of_charge_free_to_use_true_has_default_min_price_gt_zero(space_resource):
space_resource.free_to_use = True
space_resource.default_min_price = Decimal("10.00")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 1
assert Resource.objects.free_of_charge(False).count() == 0


@pytest.mark.django_db
def test_free_of_charge_free_to_use_true_has_default_max_price_gt_zero(space_resource):
space_resource.free_to_use = True
space_resource.default_max_price = Decimal("10.00")
space_resource.save()

assert Resource.objects.free_of_charge(True).count() == 1
assert Resource.objects.free_of_charge(False).count() == 0


@pytest.mark.django_db
def test_free_of_charge_free_to_use_false_no_pricing_info(space_resource):
"""Even if free_to_use is False, is still free of charge as there is
Expand Down
Loading