Added HostingUserLoginForm test, Added HostingUserSignupForm test, Added PasswordResetRequestForm Test, Added SetPasswordForm test, Created custom 404 page

This commit is contained in:
Levi 2016-07-07 23:35:50 -05:00
parent e22e25cea0
commit 202562011e
9 changed files with 224 additions and 7 deletions

View file

@ -136,7 +136,8 @@ TEMPLATES = [
os.path.join(PROJECT_DIR, 'hosting/templates/'),
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/ungleich')
os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich'),
os.path.join(PROJECT_DIR, 'ungleich_page/templates/ungleich_page')
],
'APP_DIRS': True,

View file

@ -21,6 +21,9 @@ class HostingOrderAdminForm(forms.ModelForm):
raise forms.ValidationError("""You can't make a charge over
a canceled virtual machine plan""")
if not customer:
raise forms.ValidationError("""You need select a costumer""")
# Make a charge to the customer
stripe_utils = StripeUtils()
charge_response = stripe_utils.make_charge(customer=customer.stripe_id,

116
hosting/test_forms.py Normal file
View 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())

View 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;
}

View 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>

View file

@ -48,7 +48,6 @@ class SetPasswordForm(forms.Form):
return password2
class BillingAddressForm(forms.ModelForm):
token = forms.CharField(widget=forms.HiddenInput())

View file

@ -82,7 +82,6 @@ class StripeUtils(object):
)
return customer
@handleStripeError
def make_charge(self, amount=None, customer=None):
amount = int(amount * 100) # stripe amount unit, in cents

View file

@ -1,5 +1,51 @@
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):

View file

@ -5,9 +5,6 @@ from django.http.request import HttpRequest
from model_mommy import mommy
class BaseTestCase(TestCase):
"""
Base class to initialize the test cases