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%} + + + +
+ +