From b34d84657e1b3bd9d34e74ad89ac6123af84fcfe Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 7 Jul 2016 23:35:50 -0500 Subject: [PATCH] Added HostingUserLoginForm test, Added HostingUserSignupForm test, Added PasswordResetRequestForm Test, Added SetPasswordForm test, Created custom 404 page --- dynamicweb/settings/base.py | 3 +- hosting/forms.py | 3 + hosting/test_forms.py | 116 ++++++++++++++++++ .../static/ungleich_page/css/404.css | 28 +++++ .../templates/ungleich_page/404.html | 28 +++++ utils/forms.py | 1 - utils/stripe_utils.py | 1 - utils/test_forms.py | 48 +++++++- utils/tests.py | 3 - 9 files changed, 224 insertions(+), 7 deletions(-) create mode 100644 hosting/test_forms.py create mode 100644 ungleich_page/static/ungleich_page/css/404.css create mode 100644 ungleich_page/templates/ungleich_page/404.html diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index ab2d6763..53a75f3a 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -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, diff --git a/hosting/forms.py b/hosting/forms.py index 8007b2f4..2a4d67e3 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -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, diff --git a/hosting/test_forms.py b/hosting/test_forms.py new file mode 100644 index 00000000..e0f5df30 --- /dev/null +++ b/hosting/test_forms.py @@ -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()) diff --git a/ungleich_page/static/ungleich_page/css/404.css b/ungleich_page/static/ungleich_page/css/404.css new file mode 100644 index 00000000..2528973d --- /dev/null +++ b/ungleich_page/static/ungleich_page/css/404.css @@ -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; +} diff --git a/ungleich_page/templates/ungleich_page/404.html b/ungleich_page/templates/ungleich_page/404.html new file mode 100644 index 00000000..6b6caf70 --- /dev/null +++ b/ungleich_page/templates/ungleich_page/404.html @@ -0,0 +1,28 @@ +{% load staticfiles bootstrap3%} + + + + + + 404 | ungleich + + + +
+
404
+

We couldn't find the page..

+ +
+ Sorry, but the page you are looking for was either not found or does not exist.
+ Try refreshing the page or click the button below to go back to the Homepage. +
+ +
+
+
+ + + diff --git a/utils/forms.py b/utils/forms.py index 7af6f99a..e87d3579 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -48,7 +48,6 @@ class SetPasswordForm(forms.Form): return password2 - class BillingAddressForm(forms.ModelForm): token = forms.CharField(widget=forms.HiddenInput()) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index fb0a328e..eb17ea09 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -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 diff --git a/utils/test_forms.py b/utils/test_forms.py index dc6d9fcc..46285fc5 100644 --- a/utils/test_forms.py +++ b/utils/test_forms.py @@ -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): diff --git a/utils/tests.py b/utils/tests.py index 195fc060..42831050 100644 --- a/utils/tests.py +++ b/utils/tests.py @@ -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