forked from GithubBackups/healthchecks
Don't use request.project in the pricing page cc: #336
This commit is contained in:
parent
bb808852d9
commit
9c3f7101db
@ -8,18 +8,27 @@ class PricingTestCase(BaseTestCase):
|
|||||||
def test_anonymous(self):
|
def test_anonymous(self):
|
||||||
r = self.client.get("/pricing/")
|
r = self.client.get("/pricing/")
|
||||||
self.assertContains(r, "Unlimited Team Members", status_code=200)
|
self.assertContains(r, "Unlimited Team Members", status_code=200)
|
||||||
|
self.assertNotContains(r, "jumbotron")
|
||||||
|
|
||||||
# A subscription object should have NOT been created
|
# A subscription object should have NOT been created
|
||||||
assert Subscription.objects.count() == 0
|
self.assertFalse(Subscription.objects.exists())
|
||||||
|
|
||||||
def test_authenticated(self):
|
def test_authenticated(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
r = self.client.get("/pricing/")
|
r = self.client.get("/pricing/")
|
||||||
self.assertContains(r, "Unlimited Team Members", status_code=200)
|
self.assertContains(r, "Unlimited Team Members", status_code=200)
|
||||||
|
self.assertContains(r, "jumbotron")
|
||||||
|
|
||||||
# A subscription object still should have NOT been created
|
# 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)
|
@override_settings(USE_PAYMENTS=True)
|
||||||
def test_pricing_is_visible_for_all(self):
|
def test_pricing_is_visible_for_all(self):
|
||||||
@ -32,18 +41,9 @@ class PricingTestCase(BaseTestCase):
|
|||||||
def test_it_offers_to_switch(self):
|
def test_it_offers_to_switch(self):
|
||||||
self.client.login(username="bob@example.org", password="password")
|
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")
|
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):
|
def test_it_shows_active_plan(self):
|
||||||
self.sub = Subscription(user=self.alice)
|
self.sub = Subscription(user=self.alice)
|
||||||
self.sub.subscription_id = "test-id"
|
self.sub.subscription_id = "test-id"
|
||||||
@ -55,3 +55,6 @@ class PricingTestCase(BaseTestCase):
|
|||||||
|
|
||||||
r = self.client.get("/pricing/")
|
r = self.client.get("/pricing/")
|
||||||
self.assertContains(r, "Business ($20 / month)", status_code=200)
|
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)
|
||||||
|
@ -3,6 +3,7 @@ from django.urls import path
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path("projects/<uuid:code>/pricing/", views.pricing, name="hc-p-pricing"),
|
||||||
path("pricing/", views.pricing, name="hc-pricing"),
|
path("pricing/", views.pricing, name="hc-pricing"),
|
||||||
path("accounts/profile/billing/", views.billing, name="hc-billing"),
|
path("accounts/profile/billing/", views.billing, name="hc-billing"),
|
||||||
path(
|
path(
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
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.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
from hc.front.views import _get_project_for_user
|
||||||
from hc.payments.forms import InvoiceEmailingForm
|
from hc.payments.forms import InvoiceEmailingForm
|
||||||
from hc.payments.models import Subscription
|
from hc.payments.models import Subscription
|
||||||
|
|
||||||
@ -15,18 +16,26 @@ def token(request):
|
|||||||
return JsonResponse({"client_token": sub.get_client_token()})
|
return JsonResponse({"client_token": sub.get_client_token()})
|
||||||
|
|
||||||
|
|
||||||
def pricing(request):
|
def pricing(request, code=None):
|
||||||
if request.user.is_authenticated:
|
project = None
|
||||||
if request.project and request.project.owner != request.user:
|
if code:
|
||||||
ctx = {"page": "pricing"}
|
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)
|
return render(request, "payments/pricing_not_owner.html", ctx)
|
||||||
|
|
||||||
# Don't use Subscription.objects.for_user method here, so a
|
sub = None
|
||||||
# subscription object is not created just by viewing a page.
|
if request.user.is_authenticated:
|
||||||
sub = Subscription.objects.filter(user_id=request.user.id).first()
|
# 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 = {
|
ctx = {
|
||||||
"page": "pricing",
|
"page": "pricing",
|
||||||
|
"project": project,
|
||||||
"sub": sub,
|
"sub": sub,
|
||||||
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
|
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,11 @@
|
|||||||
<ul id="global-links" class="nav navbar-nav navbar-right">
|
<ul id="global-links" class="nav navbar-nav navbar-right">
|
||||||
{% if show_pricing %}
|
{% if show_pricing %}
|
||||||
<li {% if page == 'pricing' %} class="active" {% endif %}>
|
<li {% if page == 'pricing' %} class="active" {% endif %}>
|
||||||
|
{% if project %}
|
||||||
|
<a href="{% url 'hc-p-pricing' project.code %}">Pricing</a>
|
||||||
|
{% else %}
|
||||||
<a href="{% url 'hc-pricing' %}">Pricing</a>
|
<a href="{% url 'hc-pricing' %}">Pricing</a>
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<section id="plans">
|
||||||
<!-- Plans -->
|
|
||||||
<section id="plans" {% if request.user.is_authenticated %} data- {% endif %}>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<p>
|
<p>
|
||||||
You are currently viewing project <strong>{{ request.project }}</strong>.
|
You are currently viewing project <strong>{{ project }}</strong>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
To manage billing for this project, please log in as <strong>{{ request.project.owner.email }}</strong>.
|
To manage billing for this project, please log in as <strong>{{ project.owner.email }}</strong>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user