def test_has_subscription(self): user = self.user subscription = Subscription() subscription.name = 'name' subscription.start_date = datetime.datetime(2010, 10, 04) subscription.end_date = datetime.datetime(2010, 10, 13) user.subscriptions.add(subscription) self.assertTrue(user.has_subscription())
def test_will_have_subscription(self): # subscription is on a future period user = self.user subscription = Subscription() subscription.name = 'name' subscription.start_date = datetime.datetime(2010, 10, 15) subscription.end_date = datetime.datetime(2010, 10, 20) user.subscriptions.add(subscription) self.assertFalse(user.has_subscription())
def test_had_subscription(self): # subscription is out of date user = self.user subscription = Subscription() subscription.name = 'name' subscription.start_date = datetime.datetime(2010, 10, 01) subscription.end_date = datetime.datetime(2010, 10, 04) user.subscriptions.add(subscription) self.assertFalse(user.has_subscription())
def test_has_two_subscriptions(self): # not an ideal scenario, but oh well, shit happens user = self.user subscription = Subscription() subscription.name = 'name' subscription.start_date = datetime.datetime(2010, 10, 04) subscription.end_date = datetime.datetime(2010, 10, 13) user.subscriptions.add(subscription) subscription = Subscription() subscription.name = 'name1' subscription.start_date = datetime.datetime(2010, 10, 01) subscription.end_date = datetime.datetime(2010, 10, 20) user.subscriptions.add(subscription) self.assertTrue(user.has_subscription())
def beginsubscription(request): if request.user.is_authenticated() and request.user.is_superuser: email = request.POST.get("email", None) plan = request.POST.get("plan", None) callback_token = request.POST.get("callback_token", None) callback_url = request.POST.get("callback_url", None) if not plan or not email or not callback_token or not callback_url: return HttpResponseBadRequest(json.dumps({"error": True})) request.session['callback'] = { 'token': callback_token, 'url': callback_url } request.session['subscription'] = Subscription( email=email, created_at=timezone.now()) request.session['user_mail'] = email request.session['invoice'] = request.session[ 'subscription'].create_new_invoice( plan=Plan.objects.get(id=int(plan)), commit=False) if 'promo_code' in request.session: del request.session['promo_code'] request.session.save() request.session.set_expiry(0) return HttpResponse( json.dumps({ "success": True, "label": request.session["invoice"].plan.label, "token": request.session.session_key, "active_invoice_payment_url": request.session['invoice'].payment_url })) raise PermissionDenied()