Skip to content

Commit

Permalink
Drop AccountView
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Apr 16, 2017
1 parent 311268b commit 5412289
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 184 deletions.
100 changes: 0 additions & 100 deletions djstripe/templates/djstripe/account.html

This file was deleted.

12 changes: 0 additions & 12 deletions djstripe/templates/djstripe/cancel_subscription.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
{% block title %}Cancel Subscription{% endblock title %}

{% block content %}
<div class="row">
<div class="col-xs-12">
<ul class="breadcrumb">
<li><a href="{% url 'djstripe:account' %}">Home</a></li>
<li class="active">Cancel Subscription</li>
</ul>
</div>
</div>

<div class="row">
<div class="col-xs-12">
<h2>Cancel Subscription</h2>
{% if not customer.subscription %}
<p>You have no subscription on file.</p>
<p>See your <a href="{% url 'djstripe:account' %}">account status</a> or better yet, <a href="{% url 'djstripe:subscribe' %}">subscribe</a>.</p>
{% elif customer.subscription.status == customer.subscription.STATUS_CANCELED %}
<p>Your subscription has already been canceled.</p>
<p>See your <a href="{% url 'djstripe:account' %}">account status</a> or better yet, get a <a href="{% url 'djstripe:subscribe' %}">fresh subscription</a>.</p>
{% elif customer.subscription.is_status_temporarily_current %}
<p>Your subscription has already been canceled.</p>
<p>However, you can still use the site for another {{ customer.subscription.current_period_end|timeuntil }}.</p>
Expand All @@ -39,7 +28,6 @@ <h3>What you lose by cancelling your subscription:</h3>
<h3>Are you sure you want to cancel?</h3>
<form action="{% url 'djstripe:cancel_subscription' %}" method="post" id="cancel-form">
{% csrf_token %}
<a href="{% url 'djstripe:account' %}" class="btn btn-primary">I change my mind!</a>
<button class="btn btn-danger">Cancel my subscription!</button>
</form>
{% endif %}
Expand Down
4 changes: 0 additions & 4 deletions djstripe/templates/djstripe/subscribe.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

{% block content %}
{{ block.super }}
<ul class="breadcrumb">
<li><a href="{% url 'djstripe:account' %}">Home</a></li>
<li class="active">Subscription</li>
</ul>
<h2>Choose a Subscription</h2>

{% if error %}
Expand Down
5 changes: 0 additions & 5 deletions djstripe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
urlpatterns = [

# HTML views
url(
r"^$",
views.AccountView.as_view(),
name="account"
),
url(
r"^subscribe/$",
views.SubscribeView.as_view(),
Expand Down
14 changes: 2 additions & 12 deletions djstripe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,12 @@

from . import settings as djstripe_settings
from .forms import CancelSubscriptionForm
from .mixins import PaymentsContextMixin, SubscriptionMixin
from .mixins import SubscriptionMixin
from .models import Customer, Event, EventProcessingException
from .webhooks import TEST_EVENT_ID

logger = logging.getLogger(__name__)

# ============================================================================ #
# Account Views #
# ============================================================================ #


class AccountView(LoginRequiredMixin, SubscriptionMixin, PaymentsContextMixin, TemplateView):
"""Shows account details including customer and subscription details."""

template_name = "djstripe/account.html"


# ============================================================================ #
# Subscription Views #
Expand All @@ -57,7 +47,7 @@ class CancelSubscriptionView(LoginRequiredMixin, SubscriptionMixin, FormView):

template_name = "djstripe/cancel_subscription.html"
form_class = CancelSubscriptionForm
success_url = reverse_lazy("djstripe:account")
success_url = reverse_lazy("home")
redirect_url = reverse_lazy("home")

# messages
Expand Down
8 changes: 4 additions & 4 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_appname(self):
self.assertEqual(response, None)

def test_namespace(self):
request = self.factory.get("/djstripe/")
request = self.factory.get("/djstripe/webhook/")
request.user = self.user
request.urlconf = self.urlconf

Expand Down Expand Up @@ -88,7 +88,7 @@ def setUp(self):
self.middleware = SubscriptionPaymentMiddleware()

def test_anonymous(self):
request = self.factory.get("/djstripe/")
request = self.factory.get("/djstripe/webhook/")
request.user = AnonymousUser()
request.urlconf = self.urlconf

Expand All @@ -99,7 +99,7 @@ def test_is_staff(self):
self.user.is_staff = True
self.user.save()

request = self.factory.get("/djstripe/")
request = self.factory.get("/djstripe/webhook/")
request.user = self.user
request.urlconf = self.urlconf

Expand All @@ -110,7 +110,7 @@ def test_is_superuser(self):
self.user.is_superuser = True
self.user.save()

request = self.factory.get("/djstripe/")
request = self.factory.get("/djstripe/webhook/")
request.user = self.user
request.urlconf = self.urlconf

Expand Down
49 changes: 2 additions & 47 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,18 @@

from copy import deepcopy

from django.conf import settings
from django.contrib.auth import get_user, get_user_model
from django.core.urlresolvers import reverse
from django.test.testcases import TestCase
from mock import patch

from djstripe.models import Customer, Subscription, Plan
from tests import (
FAKE_CUSTOMER, FAKE_PLAN, FAKE_PLAN_II, FAKE_SUBSCRIPTION,
FAKE_CUSTOMER, FAKE_PLAN, FAKE_SUBSCRIPTION,
FAKE_SUBSCRIPTION_CANCELED, FAKE_SUBSCRIPTION_CANCELED_AT_PERIOD_END
)


class AccountViewTest(TestCase):

def setUp(self):
self.url = reverse("djstripe:account")
self.user = get_user_model().objects.create_user(
username="pydanny",
email="[email protected]",
password="password"
)
self.assertTrue(self.client.login(username="pydanny", password="password"))

Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN))
Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II))

@patch("stripe.Customer.create", return_value=deepcopy(FAKE_CUSTOMER))
@patch("djstripe.models.djstripe_settings.get_idempotency_key", return_value="foo")
def test_autocreate_customer(self, idempotency_key_mock, stripe_create_customer_mock):
self.assertEqual(Customer.objects.count(), 0)

response = self.client.get(self.url)

# simply visiting the page should generate a new customer record.
stripe_create_customer_mock.assert_called_once_with(
api_key=settings.STRIPE_SECRET_KEY, email=self.user.email, idempotency_key="foo",
metadata={"djstripe_subscriber": self.user.id}
)

self.assertEqual(FAKE_CUSTOMER["id"], response.context["customer"].stripe_id)
self.assertEqual(self.user, response.context["customer"].subscriber)
self.assertEqual(Customer.objects.count(), 1)

@patch("stripe.Customer.create", return_value=deepcopy(FAKE_CUSTOMER))
def test_plans_context(self, stripe_create_customer_mock):
response = self.client.get(self.url)
self.assertEqual(list(Plan.objects.all()), list(response.context["plans"]))

def test_subscription_context_with_plan(self):
Customer.objects.create(subscriber=self.user, stripe_id=FAKE_CUSTOMER["id"], livemode=False)
Subscription.sync_from_stripe_data(deepcopy(FAKE_SUBSCRIPTION))

response = self.client.get(self.url)
self.assertEqual(FAKE_SUBSCRIPTION["plan"]["id"], response.context["customer"].subscription.plan.stripe_id)


class CancelSubscriptionViewTest(TestCase):
def setUp(self):
self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN))
Expand Down Expand Up @@ -96,7 +51,7 @@ def test_cancel_at_period_end(self, cancel_subscription_mock):
response = self.client.post(self.url)

cancel_subscription_mock.assert_called_once_with(at_period_end=True)
self.assertRedirects(response, reverse("djstripe:account"))
self.assertRedirects(response, reverse("home"))
self.assertTrue(self.user.is_authenticated())

@patch("djstripe.stripe_objects.StripeSubscription.cancel", return_value=FAKE_SUBSCRIPTION_CANCELED)
Expand Down

0 comments on commit 5412289

Please sign in to comment.