Added HostingUserLoginForm test, Added HostingUserSignupForm test, Added PasswordResetRequestForm Test, Added SetPasswordForm test, Created custom 404 page
This commit is contained in:
parent
0dc81fff3d
commit
b34d84657e
9 changed files with 224 additions and 7 deletions
|
@ -136,7 +136,8 @@ TEMPLATES = [
|
||||||
os.path.join(PROJECT_DIR, 'hosting/templates/'),
|
os.path.join(PROJECT_DIR, 'hosting/templates/'),
|
||||||
os.path.join(PROJECT_DIR, 'ungleich/templates/djangocms_blog/'),
|
os.path.join(PROJECT_DIR, 'ungleich/templates/djangocms_blog/'),
|
||||||
os.path.join(PROJECT_DIR, 'ungleich/templates/cms/ungleichch'),
|
os.path.join(PROJECT_DIR, 'ungleich/templates/cms/ungleichch'),
|
||||||
os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich')
|
os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich'),
|
||||||
|
os.path.join(PROJECT_DIR, 'ungleich_page/templates/ungleich_page')
|
||||||
|
|
||||||
],
|
],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
|
|
|
@ -21,6 +21,9 @@ class HostingOrderAdminForm(forms.ModelForm):
|
||||||
raise forms.ValidationError("""You can't make a charge over
|
raise forms.ValidationError("""You can't make a charge over
|
||||||
a canceled virtual machine plan""")
|
a canceled virtual machine plan""")
|
||||||
|
|
||||||
|
if not customer:
|
||||||
|
raise forms.ValidationError("""You need select a costumer""")
|
||||||
|
|
||||||
# Make a charge to the customer
|
# Make a charge to the customer
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
charge_response = stripe_utils.make_charge(customer=customer.stripe_id,
|
charge_response = stripe_utils.make_charge(customer=customer.stripe_id,
|
||||||
|
|
116
hosting/test_forms.py
Normal file
116
hosting/test_forms.py
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from unittest import mock
|
||||||
|
from model_mommy import mommy
|
||||||
|
|
||||||
|
from .forms import HostingOrderAdminForm, HostingUserLoginForm, HostingUserSignupForm
|
||||||
|
from .models import VirtualMachinePlan
|
||||||
|
|
||||||
|
|
||||||
|
class HostingUserLoginFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
password = 'user_password'
|
||||||
|
self.user = mommy.make('CustomUser')
|
||||||
|
|
||||||
|
self.user.set_password(password)
|
||||||
|
self.user.save()
|
||||||
|
self.completed_data = {
|
||||||
|
'email': self.user.email,
|
||||||
|
'password': password
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incorrect_data = {
|
||||||
|
'email': 'test',
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_valid_form(self):
|
||||||
|
form = HostingUserLoginForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = HostingUserLoginForm(data=self.incorrect_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
|
class HostingUserSignupFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
self.completed_data = {
|
||||||
|
'name': 'test name',
|
||||||
|
'email': 'test@ungleich.com',
|
||||||
|
'password': 'test_password',
|
||||||
|
'confirm_password': 'test_password'
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incorrect_data = {
|
||||||
|
'email': 'test',
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_valid_form(self):
|
||||||
|
form = HostingUserSignupForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = HostingUserSignupForm(data=self.incorrect_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
|
class HostingOrderAdminFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
self.customer = mommy.make('StripeCustomer')
|
||||||
|
self.vm_plan = mommy.make('VirtualMachinePlan')
|
||||||
|
self.vm_canceled_plan = mommy.make('VirtualMachinePlan',
|
||||||
|
status=VirtualMachinePlan.CANCELED_STATUS)
|
||||||
|
|
||||||
|
self.mocked_charge = {
|
||||||
|
'amount': 5100,
|
||||||
|
'amount_refunded': 0,
|
||||||
|
'balance_transaction': 'txn_18U99zGjsLAXdRPzUJKkBx3Q',
|
||||||
|
'captured': True,
|
||||||
|
'created': 1467785123,
|
||||||
|
'currency': 'chf',
|
||||||
|
'customer': 'cus_8V61MvJvMd0PhM',
|
||||||
|
'status': 'succeeded'
|
||||||
|
}
|
||||||
|
|
||||||
|
self.completed_data = {
|
||||||
|
'customer': self.customer.id,
|
||||||
|
'vm_plan': self.vm_plan.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incompleted_data = {
|
||||||
|
'vm_plan': self.vm_plan.id,
|
||||||
|
'customer': None
|
||||||
|
}
|
||||||
|
|
||||||
|
@mock.patch('utils.stripe_utils.StripeUtils.make_charge')
|
||||||
|
def test_valid_form(self, stripe_mocked_call):
|
||||||
|
stripe_mocked_call.return_value = {
|
||||||
|
'paid': True,
|
||||||
|
'response_object': self.mocked_charge,
|
||||||
|
'error': None
|
||||||
|
}
|
||||||
|
form = HostingOrderAdminForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
@mock.patch('utils.stripe_utils.StripeUtils.make_charge')
|
||||||
|
def test_invalid_form_canceled_vm(self, stripe_mocked_call):
|
||||||
|
|
||||||
|
self.completed_data.update({
|
||||||
|
'vm_plan': self.vm_canceled_plan.id
|
||||||
|
})
|
||||||
|
stripe_mocked_call.return_value = {
|
||||||
|
'paid': True,
|
||||||
|
'response_object': self.mocked_charge,
|
||||||
|
'error': None
|
||||||
|
}
|
||||||
|
form = HostingOrderAdminForm(data=self.completed_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = HostingOrderAdminForm(data=self.incompleted_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
28
ungleich_page/static/ungleich_page/css/404.css
Normal file
28
ungleich_page/static/ungleich_page/css/404.css
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
.error {
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-code {
|
||||||
|
bottom: 60%;
|
||||||
|
color: #2d353c;
|
||||||
|
font-size: 96px;
|
||||||
|
line-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-desc {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #647788;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-b-10 {
|
||||||
|
margin-bottom: 10px!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-b-20 {
|
||||||
|
margin-bottom: 20px!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-t-20 {
|
||||||
|
margin-top: 20px!important;
|
||||||
|
}
|
28
ungleich_page/templates/ungleich_page/404.html
Normal file
28
ungleich_page/templates/ungleich_page/404.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{% load staticfiles bootstrap3%}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="{% static 'ungleich_page/css/404.css' %}" rel="stylesheet">
|
||||||
|
<title>404 | ungleich</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="error">
|
||||||
|
<div class="error-code m-b-10 m-t-20">404 <i class="fa fa-warning"></i></div>
|
||||||
|
<h3 class="font-bold">We couldn't find the page..</h3>
|
||||||
|
|
||||||
|
<div class="error-desc">
|
||||||
|
Sorry, but the page you are looking for was either not found or does not exist. <br/>
|
||||||
|
Try refreshing the page or click the button below to go back to the Homepage.
|
||||||
|
<div>
|
||||||
|
<a class=" login-detail-panel-button btn" href="http://www.vmware.com/">
|
||||||
|
<i class="fa fa-arrow-left"></i>
|
||||||
|
Go back to Homepage
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -48,7 +48,6 @@ class SetPasswordForm(forms.Form):
|
||||||
return password2
|
return password2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BillingAddressForm(forms.ModelForm):
|
class BillingAddressForm(forms.ModelForm):
|
||||||
token = forms.CharField(widget=forms.HiddenInput())
|
token = forms.CharField(widget=forms.HiddenInput())
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@ class StripeUtils(object):
|
||||||
)
|
)
|
||||||
return customer
|
return customer
|
||||||
|
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
def make_charge(self, amount=None, customer=None):
|
def make_charge(self, amount=None, customer=None):
|
||||||
amount = int(amount * 100) # stripe amount unit, in cents
|
amount = int(amount * 100) # stripe amount unit, in cents
|
||||||
|
|
|
@ -1,5 +1,51 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from .forms import ContactUsForm, BillingAddressForm
|
from .forms import ContactUsForm, BillingAddressForm, PasswordResetRequestForm,\
|
||||||
|
SetPasswordForm
|
||||||
|
|
||||||
|
from model_mommy import mommy
|
||||||
|
|
||||||
|
|
||||||
|
class PasswordResetRequestFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user = mommy.make('CustomUser')
|
||||||
|
self.completed_data = {
|
||||||
|
'email': self.user.email,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incorrect_data = {
|
||||||
|
'email': 'test',
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_valid_form(self):
|
||||||
|
form = PasswordResetRequestForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = PasswordResetRequestForm(data=self.incorrect_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
|
class SetPasswordFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# self.user = mommy.make('CustomUser')
|
||||||
|
self.completed_data = {
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incorrect_data = {
|
||||||
|
'email': 'test',
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_valid_form(self):
|
||||||
|
form = SetPasswordForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = SetPasswordForm(data=self.incorrect_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
class ContactUsFormTest(TestCase):
|
class ContactUsFormTest(TestCase):
|
||||||
|
|
|
@ -5,9 +5,6 @@ from django.http.request import HttpRequest
|
||||||
from model_mommy import mommy
|
from model_mommy import mommy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(TestCase):
|
class BaseTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
Base class to initialize the test cases
|
Base class to initialize the test cases
|
||||||
|
|
Loading…
Reference in a new issue