diff --git a/hc/payments/tests/test_pricing.py b/hc/payments/tests/test_pricing.py index 815e1ddd..047cd984 100644 --- a/hc/payments/tests/test_pricing.py +++ b/hc/payments/tests/test_pricing.py @@ -8,18 +8,27 @@ class PricingTestCase(BaseTestCase): def test_anonymous(self): r = self.client.get("/pricing/") self.assertContains(r, "Unlimited Team Members", status_code=200) + self.assertNotContains(r, "jumbotron") # A subscription object should have NOT been created - assert Subscription.objects.count() == 0 + self.assertFalse(Subscription.objects.exists()) def test_authenticated(self): self.client.login(username="alice@example.org", password="password") r = self.client.get("/pricing/") self.assertContains(r, "Unlimited Team Members", status_code=200) + self.assertContains(r, "jumbotron") # A subscription object still should have NOT been created - assert Subscription.objects.count() == 0 + self.assertFalse(Subscription.objects.exists()) + + def test_authenticated_for_project(self): + self.client.login(username="alice@example.org", password="password") + + r = self.client.get("/projects/%s/pricing/" % self.project.code) + self.assertContains(r, "Unlimited Team Members", status_code=200) + self.assertContains(r, "jumbotron") @override_settings(USE_PAYMENTS=True) def test_pricing_is_visible_for_all(self): @@ -32,18 +41,9 @@ class PricingTestCase(BaseTestCase): def test_it_offers_to_switch(self): self.client.login(username="bob@example.org", password="password") - r = self.client.get("/pricing/") + r = self.client.get("/projects/%s/pricing/" % self.project.code) self.assertContains(r, "To manage billing for this project") - def test_it_handles_null_project(self): - self.profile.current_project = None - self.profile.save() - - self.client.login(username="alice@example.org", password="password") - - r = self.client.get("/pricing/") - self.assertContains(r, "Unlimited Team Members") - def test_it_shows_active_plan(self): self.sub = Subscription(user=self.alice) self.sub.subscription_id = "test-id" @@ -55,3 +55,6 @@ class PricingTestCase(BaseTestCase): r = self.client.get("/pricing/") self.assertContains(r, "Business ($20 / month)", status_code=200) + + r = self.client.get("/projects/%s/pricing/" % self.project.code) + self.assertContains(r, "Business ($20 / month)", status_code=200) diff --git a/hc/payments/urls.py b/hc/payments/urls.py index 1f72a055..e76af75b 100644 --- a/hc/payments/urls.py +++ b/hc/payments/urls.py @@ -3,6 +3,7 @@ from django.urls import path from . import views urlpatterns = [ + path("projects//pricing/", views.pricing, name="hc-p-pricing"), path("pricing/", views.pricing, name="hc-pricing"), path("accounts/profile/billing/", views.billing, name="hc-billing"), path( diff --git a/hc/payments/views.py b/hc/payments/views.py index 86d9c8d3..74481be3 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -1,10 +1,11 @@ from django.conf import settings from django.contrib import messages from django.contrib.auth.decorators import login_required -from django.http import HttpResponseBadRequest, JsonResponse +from django.http import Http404, HttpResponseBadRequest, JsonResponse from django.shortcuts import get_object_or_404, redirect, render from django.views.decorators.http import require_POST from hc.api.models import Check +from hc.front.views import _get_project_for_user from hc.payments.forms import InvoiceEmailingForm from hc.payments.models import Subscription @@ -15,18 +16,26 @@ def token(request): return JsonResponse({"client_token": sub.get_client_token()}) -def pricing(request): - if request.user.is_authenticated: - if request.project and request.project.owner != request.user: - ctx = {"page": "pricing"} +def pricing(request, code=None): + project = None + if code: + if not request.user.is_authenticated: + raise Http404() + + project = _get_project_for_user(request, code) + if project.owner != request.user: + ctx = {"page": "pricing", "project": project} return render(request, "payments/pricing_not_owner.html", ctx) - # Don't use Subscription.objects.for_user method here, so a - # subscription object is not created just by viewing a page. - sub = Subscription.objects.filter(user_id=request.user.id).first() + sub = None + if request.user.is_authenticated: + # Don't use Subscription.objects.for_user method here, so a + # subscription object is not created just by viewing a page. + sub = Subscription.objects.filter(user_id=request.user.id).first() ctx = { "page": "pricing", + "project": project, "sub": sub, "enable_whatsapp": settings.TWILIO_USE_WHATSAPP, } diff --git a/templates/base.html b/templates/base.html index 132b56b6..fee98e81 100644 --- a/templates/base.html +++ b/templates/base.html @@ -119,7 +119,11 @@