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
ca136d4e47
commit
342512036d
9 changed files with 106 additions and 15 deletions
|
@ -446,8 +446,8 @@ AUTH_USER_MODEL = 'membership.CustomUser'
|
||||||
|
|
||||||
# PAYMENT
|
# PAYMENT
|
||||||
|
|
||||||
STRIPE_API_PUBLIC_KEY = 'pk_test_ZRg6P8g5ybiHE6l2RW5pSaYV' # used in frontend to call from user browser
|
STRIPE_API_PUBLIC_KEY = 'pk_test_QqBZ50Am8KOxaAlOxbcm9Psl' # used in frontend to call from user browser
|
||||||
STRIPE_API_PRIVATE_KEY = 'sk_test_uIPMdgXoRGydrcD7fkwcn7dj' # used in backend payment
|
STRIPE_API_PRIVATE_KEY = 'sk_test_dqAmbKAij12QCGfkYZ3poGt2' # used in backend payment
|
||||||
STRIPE_DESCRIPTION_ON_PAYMENT = "Payment for ungleich GmbH services"
|
STRIPE_DESCRIPTION_ON_PAYMENT = "Payment for ungleich GmbH services"
|
||||||
|
|
||||||
# EMAIL MESSAGES
|
# EMAIL MESSAGES
|
||||||
|
|
|
@ -4,5 +4,6 @@ from django.db import models
|
||||||
class VMPlansManager(models.Manager):
|
class VMPlansManager(models.Manager):
|
||||||
|
|
||||||
def active(self, user, **kwargs):
|
def active(self, user, **kwargs):
|
||||||
return self.select_related('hostingorder__customer__user').\
|
return self.prefetch_related('hosting_orders__customer__user').\
|
||||||
filter(hostingorder__customer__user=user, hostingorder__approved=True, **kwargs)
|
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
|
name = 'vm-%s' % self.id
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def orders(self):
|
|
||||||
return [self.hostingorder]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, data, user):
|
def create(cls, data, user):
|
||||||
instance = cls.objects.create(**data)
|
instance = cls.objects.create(**data)
|
||||||
|
@ -110,7 +106,7 @@ class HostingOrder(models.Model):
|
||||||
ORDER_APPROVED_STATUS = 'Approved'
|
ORDER_APPROVED_STATUS = 'Approved'
|
||||||
ORDER_DECLINED_STATUS = 'Declined'
|
ORDER_DECLINED_STATUS = 'Declined'
|
||||||
|
|
||||||
VMPlan = models.ForeignKey(VirtualMachinePlan)
|
VMPlan = models.ForeignKey(VirtualMachinePlan, related_name='hosting_orders')
|
||||||
customer = models.ForeignKey(StripeCustomer)
|
customer = models.ForeignKey(StripeCustomer)
|
||||||
billing_address = models.ForeignKey(BillingAddress)
|
billing_address = models.ForeignKey(BillingAddress)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
|
@ -23,7 +23,10 @@
|
||||||
<strong>Order Date:</strong><br>
|
<strong>Order Date:</strong><br>
|
||||||
{{object.created_at}}<br><br>
|
{{object.created_at}}<br><br>
|
||||||
<strong>Status:</strong><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>
|
</address>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -100,7 +100,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for order in virtual_machine.orders %}
|
{% for order in virtual_machine.hosting_orders.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td scope="row">{{order.id}}</td>
|
<td scope="row">{{order.id}}</td>
|
||||||
<td>{{order.created_at}}</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
|
Check if there is a registered stripe customer with that email
|
||||||
or create a new one
|
or create a new one
|
||||||
"""
|
"""
|
||||||
|
stripe_customer = None
|
||||||
try:
|
try:
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
stripe_customer = cls.objects.get(user__email=email)
|
stripe_customer = cls.objects.get(user__email=email)
|
||||||
|
|
|
@ -52,8 +52,6 @@ def handleStripeError(f):
|
||||||
return handleProblems
|
return handleProblems
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StripeUtils(object):
|
class StripeUtils(object):
|
||||||
CURRENCY = 'chf'
|
CURRENCY = 'chf'
|
||||||
INTERVAL = 'month'
|
INTERVAL = 'month'
|
||||||
|
@ -71,7 +69,7 @@ class StripeUtils(object):
|
||||||
customer = stripe.Customer.retrieve(id)
|
customer = stripe.Customer.retrieve(id)
|
||||||
except stripe.InvalidRequestError:
|
except stripe.InvalidRequestError:
|
||||||
customer = self.create_customer(token, user.email)
|
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()
|
user.stripecustomer.save()
|
||||||
return customer
|
return customer
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue