Added DjangoHostingView test, Added RailsHostingView test, Added, NodeJSHostingView test, Changed VMPlan model, Fixed templates to support new relationship between orders and VMplans, Merged Calendar feature with Booking
This commit is contained in:
parent
bf0e152789
commit
14f78893d5
9 changed files with 106 additions and 15 deletions
|
@ -446,8 +446,8 @@ AUTH_USER_MODEL = 'membership.CustomUser'
|
|||
|
||||
# PAYMENT
|
||||
|
||||
STRIPE_API_PUBLIC_KEY = 'pk_test_ZRg6P8g5ybiHE6l2RW5pSaYV' # used in frontend to call from user browser
|
||||
STRIPE_API_PRIVATE_KEY = 'sk_test_uIPMdgXoRGydrcD7fkwcn7dj' # used in backend payment
|
||||
STRIPE_API_PUBLIC_KEY = 'pk_test_QqBZ50Am8KOxaAlOxbcm9Psl' # used in frontend to call from user browser
|
||||
STRIPE_API_PRIVATE_KEY = 'sk_test_dqAmbKAij12QCGfkYZ3poGt2' # used in backend payment
|
||||
STRIPE_DESCRIPTION_ON_PAYMENT = "Payment for ungleich GmbH services"
|
||||
|
||||
# EMAIL MESSAGES
|
||||
|
|
|
@ -4,5 +4,6 @@ from django.db import models
|
|||
class VMPlansManager(models.Manager):
|
||||
|
||||
def active(self, user, **kwargs):
|
||||
return self.select_related('hostingorder__customer__user').\
|
||||
filter(hostingorder__customer__user=user, hostingorder__approved=True, **kwargs)
|
||||
return self.prefetch_related('hosting_orders__customer__user').\
|
||||
filter(hosting_orders__customer__user=user, hosting_orders__approved=True, **kwargs)\
|
||||
.distinct()
|
||||
|
|
21
hosting/migrations/0014_auto_20160505_0541.py
Normal file
21
hosting/migrations/0014_auto_20160505_0541.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-05-05 05:41
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('hosting', '0013_auto_20160505_0302'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='hostingorder',
|
||||
name='VMPlan',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='hosting_orders', to='hosting.VirtualMachinePlan'),
|
||||
),
|
||||
]
|
|
@ -95,10 +95,6 @@ class VirtualMachinePlan(models.Model):
|
|||
name = 'vm-%s' % self.id
|
||||
return name
|
||||
|
||||
@cached_property
|
||||
def orders(self):
|
||||
return [self.hostingorder]
|
||||
|
||||
@classmethod
|
||||
def create(cls, data, user):
|
||||
instance = cls.objects.create(**data)
|
||||
|
@ -110,7 +106,7 @@ class HostingOrder(models.Model):
|
|||
ORDER_APPROVED_STATUS = 'Approved'
|
||||
ORDER_DECLINED_STATUS = 'Declined'
|
||||
|
||||
VMPlan = models.ForeignKey(VirtualMachinePlan)
|
||||
VMPlan = models.ForeignKey(VirtualMachinePlan, related_name='hosting_orders')
|
||||
customer = models.ForeignKey(StripeCustomer)
|
||||
billing_address = models.ForeignKey(BillingAddress)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
<strong>Order Date:</strong><br>
|
||||
{{object.created_at}}<br><br>
|
||||
<strong>Status:</strong><br>
|
||||
<strong class="text-danger">{{object.status}}</strong><br><br>
|
||||
<strong class="{% if object.status == 'Approved' %}text-success
|
||||
{%else%} text-danger
|
||||
{% endif %}">{{object.status}}</strong>
|
||||
<br><br>
|
||||
</address>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for order in virtual_machine.orders %}
|
||||
{% for order in virtual_machine.hosting_orders.all %}
|
||||
<tr>
|
||||
<td scope="row">{{order.id}}</td>
|
||||
<td>{{order.created_at}}</td>
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.urlresolvers import resolve
|
||||
from .models import VirtualMachineType
|
||||
from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView
|
||||
|
||||
|
||||
class ProcessVMSelectionTestMixin(object):
|
||||
|
||||
def url_resolve_to_view_correctly(self):
|
||||
found = resolve(self.url)
|
||||
self.assertEqual(found.func.__name__, self.view.__name__)
|
||||
|
||||
def test_get(self):
|
||||
response = self.client.get(self.url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(self.view.get_context_data(), self.expected_context)
|
||||
self.assertEqual(response.context['hosting'], self.expected_context['hosting'])
|
||||
self.assertTemplateUsed(response, self.expected_template)
|
||||
|
||||
def test_anonymous_post(self):
|
||||
response = self.client.post(self.url)
|
||||
self.assertRedirects(response, expected_url=reverse('hosting:login'),
|
||||
status_code=302, target_status_code=200)
|
||||
|
||||
|
||||
class DjangoHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
|
||||
|
||||
def setUp(self):
|
||||
self.url = reverse('django.hosting')
|
||||
self.view = DjangoHostingView()
|
||||
self.expected_template = 'hosting/django.html'
|
||||
self.expected_context = {
|
||||
'hosting': "django",
|
||||
'hosting_long': "Django",
|
||||
'domain': "django-hosting.ch",
|
||||
'google_analytics': "UA-62285904-6",
|
||||
'email': "info@django-hosting.ch",
|
||||
'vm_types': VirtualMachineType.get_serialized_vm_types(),
|
||||
}
|
||||
|
||||
|
||||
class RailsHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
|
||||
|
||||
def setUp(self):
|
||||
self.url = reverse('rails.hosting')
|
||||
self.view = RailsHostingView()
|
||||
self.expected_template = 'hosting/rails.html'
|
||||
self.expected_context = {
|
||||
'hosting': "rails",
|
||||
'hosting_long': "Ruby On Rails",
|
||||
'domain': "rails-hosting.ch",
|
||||
'google_analytics': "UA-62285904-5",
|
||||
'email': "info@rails-hosting.ch",
|
||||
'vm_types': VirtualMachineType.get_serialized_vm_types(),
|
||||
}
|
||||
|
||||
|
||||
class NodeJSHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
|
||||
|
||||
def setUp(self):
|
||||
self.url = reverse('node.hosting')
|
||||
self.view = NodeJSHostingView()
|
||||
self.expected_template = 'hosting/nodejs.html'
|
||||
self.expected_context = {
|
||||
'hosting': "nodejs",
|
||||
'hosting_long': "NodeJS",
|
||||
'domain': "node-hosting.ch",
|
||||
'google_analytics': "UA-62285904-7",
|
||||
'email': "info@node-hosting.ch",
|
||||
'vm_types': VirtualMachineType.get_serialized_vm_types(),
|
||||
}
|
|
@ -131,7 +131,7 @@ class StripeCustomer(models.Model):
|
|||
Check if there is a registered stripe customer with that email
|
||||
or create a new one
|
||||
"""
|
||||
|
||||
stripe_customer = None
|
||||
try:
|
||||
stripe_utils = StripeUtils()
|
||||
stripe_customer = cls.objects.get(user__email=email)
|
||||
|
|
|
@ -52,8 +52,6 @@ def handleStripeError(f):
|
|||
return handleProblems
|
||||
|
||||
|
||||
|
||||
|
||||
class StripeUtils(object):
|
||||
CURRENCY = 'chf'
|
||||
INTERVAL = 'month'
|
||||
|
@ -71,7 +69,7 @@ class StripeUtils(object):
|
|||
customer = stripe.Customer.retrieve(id)
|
||||
except stripe.InvalidRequestError:
|
||||
customer = self.create_customer(token, user.email)
|
||||
user.stripecustomer.stripe_id = customer.get('id')
|
||||
user.stripecustomer.stripe_id = customer.get('response_object').get('id')
|
||||
user.stripecustomer.save()
|
||||
return customer
|
||||
|
||||
|
|
Loading…
Reference in a new issue