Update datacenterlight django.po

This commit is contained in:
PCoder 2017-11-27 08:38:10 +01:00
commit 4a30438704
60 changed files with 1458 additions and 516 deletions

View file

@ -50,15 +50,17 @@ class HostingUserLoginForm(forms.Form):
class HostingUserSignupForm(forms.ModelForm):
confirm_password = forms.CharField(widget=forms.PasswordInput())
password = forms.CharField(widget=forms.PasswordInput())
confirm_password = forms.CharField(label=_("Confirm Password"),
widget=forms.PasswordInput())
password = forms.CharField(label=_("Password"),
widget=forms.PasswordInput())
class Meta:
model = CustomUser
fields = ['name', 'email', 'password']
widgets = {
'name': forms.TextInput(
attrs={'placeholder': 'Enter your name or company name'}),
attrs={'placeholder': _('Enter your name or company name')}),
}
def clean_confirm_password(self):
@ -106,7 +108,7 @@ class UserHostingKeyForm(forms.ModelForm):
public_key=openssh_pubkey_str).first().name
KEY_EXISTS_MESSAGE = _(
"This key exists already with the name \"%(name)s\"") % {
'name': key_name}
'name': key_name}
raise forms.ValidationError(KEY_EXISTS_MESSAGE)
with tempfile.NamedTemporaryFile(delete=True) as tmp_public_key_file:

View file

@ -27,6 +27,15 @@ msgstr "Dein Account wurde noch nicht aktiviert."
msgid "User does not exist"
msgstr "Der Benutzer existiert nicht"
msgid "Confirm Password"
msgstr "Passwort Bestätigung"
msgid "Password"
msgstr "Passwort"
msgid "Enter your name or company name"
msgstr "Gib Deinen Namen oder den Name Deines Unternehmens ein"
msgid "Paste here your public key"
msgstr "Füge Deinen Public Key ein"
@ -457,6 +466,28 @@ msgstr ""
"\"https://stripe.com\" target=\"_blank\">Stripe</a> für die Bezahlung und "
"speichern keine Informationen in unserer Datenbank."
msgid ""
"You are not making any payment yet. After submitting your card information, "
"you will be taken to the Confirm Order Page."
msgstr ""
"Es wird noch keine Bezahlung vorgenommen. Die Bezahlung wird erst ausgelöst, "
"nachdem Du die Bestellung auf der nächsten Seite bestätigt hast."
msgid "SUBMIT"
msgstr "ABSENDEN"
msgid "Card Number"
msgstr "Kreditkartennummer"
msgid "Expiry Date"
msgstr "Ablaufdatum"
msgid "CVC"
msgstr ""
msgid "Card Type"
msgstr "Kartentyp"
msgid "Last"
msgstr "Vor"
@ -493,6 +524,12 @@ msgstr "Karte Entfernen"
msgid "Do you want to remove this associated card?"
msgstr ""
msgid "Last"
msgstr ""
msgid "Type"
msgstr "Kartentyp"
msgid "Delete"
msgstr "Löschen"
@ -553,6 +590,9 @@ msgstr ""
msgid "Private Key"
msgstr ""
msgid "Delete"
msgstr "Löschen"
msgid "Delete SSH Key"
msgstr "SSH Key löschen"
@ -854,6 +894,15 @@ msgstr ""
#~ msgid "Notifications "
#~ msgstr "Benachrichtigungen"
#~ msgid "REMOVE CARD"
#~ msgstr "KARTE ENTFERNEN"
#~ msgid "EDIT CARD"
#~ msgstr "BEARBEITEN"
#~ msgid "Add a new Card."
#~ msgstr "Neue Kreditkarte hinzufügen."
#~ msgid "You are not making any payment here."
#~ msgstr "Es wird noch keine Bezahlung vorgenommen"

View file

@ -1,25 +1,18 @@
from django.test import TestCase
from unittest import mock
from model_mommy import mommy
from .forms import HostingOrderAdminForm, HostingUserLoginForm, HostingUserSignupForm
from .models import VirtualMachinePlan
from .forms import HostingUserLoginForm, HostingUserSignupForm
class HostingUserLoginFormTest(TestCase):
def setUp(self):
password = 'user_password'
self.user = mommy.make('CustomUser')
self.user = mommy.make('CustomUser', validated=1)
self.user.set_password(password)
self.user.save()
self.completed_data = {
'email': self.user.email,
'password': password
}
self.incorrect_data = {
'email': 'test',
}
@ -34,9 +27,7 @@ class HostingUserLoginFormTest(TestCase):
class HostingUserSignupFormTest(TestCase):
def setUp(self):
self.completed_data = {
'name': 'test name',
'email': 'test@ungleich.com',
@ -58,13 +49,11 @@ class HostingUserSignupFormTest(TestCase):
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.vm_canceled_plan = mommy.make('VirtualMachinePlan',
# status=VirtualMachinePlan.CANCELED_STATUS)
self.mocked_charge = {
'amount': 5100,
@ -87,30 +76,30 @@ class HostingOrderAdminFormTest(TestCase):
'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_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())
# @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

@ -1,75 +1,75 @@
from django.test import TestCase
from django.core.management import call_command
from .models import VirtualMachineType
class VirtualMachineTypeModelTest(TestCase):
def setUp(self):
self.HETZNER_NUG_NAME = 'hetzner_nug'
self.HETZNER_NAME = 'hetzner'
self.HETZNER_RAID6_NAME = 'hetzner_raid6'
self.HETZNER_GLUSTERFS_NAME = 'hetzner_glusterfs'
self.BERN_NAME = 'bern'
self.HETZNER_NUG_EXPECTED_PRICE = 79
self.HETZNER_EXPECTED_PRICE = 180
self.HETZNER_RAID6_EXPECTED_PRICE = 216
self.HETZNER_GLUSTERFS_EXPECTED_PRICE = 252
self.BERN_EXPECTED_PRICE = 202
call_command('create_vm_types')
def test_calculate_price(self):
# hetzner_nug
# specifications = {
# 'cores': 2,
# 'memory': 10,
# 'disk_size': 100
# }
# vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_NUG_NAME)
# calculated_price = vm_type.calculate_price(specifications)
# self.assertEqual(calculated_price, self.HETZNER_NUG_EXPECTED_PRICE)
# hetzner
specifications = {
'cores': 2,
'memory': 10,
'disk_size': 100
}
vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_NAME)
calculated_price = vm_type.calculate_price(specifications)
self.assertEqual(calculated_price, self.HETZNER_EXPECTED_PRICE)
# hetzner_raid6
# specifications = {
# 'cores': 2,
# 'memory': 10,
# 'disk_size': 100
# }
# vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_RAID6_NAME)
# calculated_price = vm_type.calculate_price(specifications)
# self.assertEqual(calculated_price, self.HETZNER_RAID6_EXPECTED_PRICE)
# hetzner_glusterfs
# specifications = {
# 'cores': 2,
# 'memory': 10,
# 'disk_size': 100
# }
# vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_GLUSTERFS_NAME)
# calculated_price = vm_type.calculate_price(specifications)
# self.assertEqual(calculated_price, self.HETZNER_GLUSTERFS_EXPECTED_PRICE)
# bern
specifications = {
'cores': 2,
'memory': 10,
'disk_size': 100
}
vm_type = VirtualMachineType.objects.get(hosting_company=self.BERN_NAME)
calculated_price = vm_type.calculate_price(specifications)
self.assertEqual(calculated_price, self.BERN_EXPECTED_PRICE)
# from django.test import TestCase
#
# from django.core.management import call_command
#
#
# #from .models import VirtualMachineType
#
#
# class VirtualMachineTypeModelTest(TestCase):
#
# def setUp(self):
# self.HETZNER_NUG_NAME = 'hetzner_nug'
# self.HETZNER_NAME = 'hetzner'
# self.HETZNER_RAID6_NAME = 'hetzner_raid6'
# self.HETZNER_GLUSTERFS_NAME = 'hetzner_glusterfs'
# self.BERN_NAME = 'bern'
# self.HETZNER_NUG_EXPECTED_PRICE = 79
# self.HETZNER_EXPECTED_PRICE = 180
# self.HETZNER_RAID6_EXPECTED_PRICE = 216
# self.HETZNER_GLUSTERFS_EXPECTED_PRICE = 252
# self.BERN_EXPECTED_PRICE = 202
#
# call_command('create_vm_types')
#
# def test_calculate_price(self):
#
# # hetzner_nug
# # specifications = {
# # 'cores': 2,
# # 'memory': 10,
# # 'disk_size': 100
# # }
# # vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_NUG_NAME)
# # calculated_price = vm_type.calculate_price(specifications)
# # self.assertEqual(calculated_price, self.HETZNER_NUG_EXPECTED_PRICE)
#
# # hetzner
# specifications = {
# 'cores': 2,
# 'memory': 10,
# 'disk_size': 100
# }
# vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_NAME)
# calculated_price = vm_type.calculate_price(specifications)
# self.assertEqual(calculated_price, self.HETZNER_EXPECTED_PRICE)
#
# # hetzner_raid6
# # specifications = {
# # 'cores': 2,
# # 'memory': 10,
# # 'disk_size': 100
# # }
# # vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_RAID6_NAME)
# # calculated_price = vm_type.calculate_price(specifications)
# # self.assertEqual(calculated_price, self.HETZNER_RAID6_EXPECTED_PRICE)
#
# # hetzner_glusterfs
# # specifications = {
# # 'cores': 2,
# # 'memory': 10,
# # 'disk_size': 100
# # }
# # vm_type = VirtualMachineType.objects.get(hosting_company=self.HETZNER_GLUSTERFS_NAME)
# # calculated_price = vm_type.calculate_price(specifications)
# # self.assertEqual(calculated_price, self.HETZNER_GLUSTERFS_EXPECTED_PRICE)
#
# # bern
# specifications = {
# 'cores': 2,
# 'memory': 10,
# 'disk_size': 100
# }
# vm_type = VirtualMachineType.objects.get(hosting_company=self.BERN_NAME)
# calculated_price = vm_type.calculate_price(specifications)
# self.assertEqual(calculated_price, self.BERN_EXPECTED_PRICE)

View file

@ -1,4 +1,3 @@
from unittest import mock
from django.conf import settings
from django.test import TestCase
from django.core.urlresolvers import reverse
@ -6,21 +5,29 @@ from django.core.urlresolvers import resolve
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import urlsafe_base64_encode
from django.utils.encoding import force_bytes
from unittest import skipIf
from model_mommy import mommy
from stored_messages.models import Inbox
from membership.models import CustomUser, StripeCustomer
from .models import VirtualMachineType, HostingOrder, VirtualMachinePlan
from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, SignupView, \
PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineView, \
VirtualMachinesPlanListView, PasswordResetView, PasswordResetConfirmView, HostingPricingView, \
NotificationsView, MarkAsReadNotificationView, GenerateVMSSHKeysView
from .models import HostingOrder
from .views import (
DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView,
SignupView, PaymentVMView, OrdersHostingDetailView, OrdersHostingListView,
VirtualMachinesPlanListView, PasswordResetView, PasswordResetConfirmView,
HostingPricingView, NotificationsView, MarkAsReadNotificationView
)
from utils.tests import BaseTestCase
@skipIf(
(settings.OPENNEBULA_DOMAIN is None or
settings.OPENNEBULA_DOMAIN == "test_domain"),
"""OpenNebula details unavailable, so skipping
ProcessVMSelectionTestMixin"""
)
class ProcessVMSelectionTestMixin(object):
def url_resolve_to_view_correctly(self):
@ -30,14 +37,15 @@ class ProcessVMSelectionTestMixin(object):
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(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)
# def test_anonymous_post(self):
# params = {'vm_template_id': 1, 'configuration': 1}
# response = self.client.post(self.url, params)
# self.assertRedirects(response, expected_url=reverse('hosting:login'),
# status_code=302, target_status_code=200)
class DjangoHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
@ -47,15 +55,16 @@ class DjangoHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
self.view = DjangoHostingView()
self.expected_template = 'hosting/django.html'
HOSTING = 'django'
configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
# configuration_detail = dict(
# VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
self.expected_context = {
'hosting': HOSTING,
'hosting_long': "Django",
'configuration_detail': configuration_detail,
# 'configuration_detail': configuration_detail,
'domain': "django-hosting.ch",
'google_analytics': "UA-62285904-6",
'email': "info@django-hosting.ch",
'vm_types': VirtualMachineType.get_serialized_vm_types(),
# 'vm_types': VirtualMachineType.get_serialized_vm_types(),
}
@ -66,15 +75,16 @@ class RailsHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
self.view = RailsHostingView()
self.expected_template = 'hosting/rails.html'
HOSTING = 'rails'
configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
# configuration_detail = dict(
# VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
self.expected_context = {
'hosting': HOSTING,
'hosting_long': "Ruby On Rails",
'configuration_detail': configuration_detail,
# 'configuration_detail': configuration_detail,
'domain': "rails-hosting.ch",
'google_analytics': "UA-62285904-5",
'email': "info@rails-hosting.ch",
'vm_types': VirtualMachineType.get_serialized_vm_types(),
# 'vm_types': VirtualMachineType.get_serialized_vm_types(),
}
@ -85,18 +95,25 @@ class NodeJSHostingViewTest(TestCase, ProcessVMSelectionTestMixin):
self.view = NodeJSHostingView()
self.expected_template = 'hosting/nodejs.html'
HOSTING = 'nodejs'
configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
# configuration_detail = dict(
# VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
self.expected_context = {
'hosting': HOSTING,
'hosting_long': "NodeJS",
'configuration_detail': configuration_detail,
# 'configuration_detail': configuration_detail,
'domain': "node-hosting.ch",
'google_analytics': "UA-62285904-7",
'email': "info@node-hosting.ch",
'vm_types': VirtualMachineType.get_serialized_vm_types(),
# 'vm_types': VirtualMachineType.get_serialized_vm_types(),
}
@skipIf(
(settings.OPENNEBULA_DOMAIN is None or
settings.OPENNEBULA_DOMAIN == "test_domain"),
"""OpenNebula details unavailable, so skipping
HostingPricingViewTest.test_get"""
)
class HostingPricingViewTest(TestCase):
def setUp(self):
@ -104,11 +121,11 @@ class HostingPricingViewTest(TestCase):
self.view = HostingPricingView()
self.expected_template = 'hosting/hosting_pricing.html'
configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION)
# configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION)
self.expected_context = {
'configuration_options': configuration_options,
# 'configuration_options': configuration_options,
'email': "info@django-hosting.ch",
'vm_types': VirtualMachineType.get_serialized_vm_types(),
# 'vm_types': VirtualMachineType.get_serialized_vm_types(),
}
def url_resolve_to_view_correctly(self):
@ -118,13 +135,13 @@ class HostingPricingViewTest(TestCase):
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(self.view.get_context_data(), self.expected_context)
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)
# 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 PaymentVMViewTest(BaseTestCase):
@ -135,10 +152,10 @@ class PaymentVMViewTest(BaseTestCase):
self.view = PaymentVMView
# VM
self.vm = mommy.make(VirtualMachineType, base_price=10000,
memory_price=100,
core_price=1000,
disk_size_price=1)
# self.vm = mommy.make(VirtualMachineType, base_price=10000,
# memory_price=100,
# core_price=1000,
# disk_size_price=1)
# post data
self.billing_address = {
@ -153,56 +170,56 @@ class PaymentVMViewTest(BaseTestCase):
self.url = reverse('hosting:payment')
# Session data
self.session_data = {
'vm_specs': {
'hosting_company': self.vm.hosting_company,
'cores': 1,
'memory': 10,
'disk_size': 10000,
'price': 22000,
'configuration': dict(VirtualMachinePlan.VM_CONFIGURATION).get('django')
}
}
# self.session_data = {
# 'vm_specs': {
# 'hosting_company': self.vm.hosting_company,
# 'cores': 1,
# 'memory': 10,
# 'disk_size': 10000,
# 'price': 22000,
# 'configuration': dict(VirtualMachinePlan.VM_CONFIGURATION).get('django')
# }
# }
session = self.customer_client.session
session.update(self.session_data)
session.save()
# session = self.customer_client.session
# session.update(self.session_data)
# session.save()
def test_url_resolve_to_view_correctly(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__)
@mock.patch('utils.stripe_utils.StripeUtils.create_customer')
def test_post(self, stripe_mocked_call):
# Anonymous user should get redirect to login
response = self.client.post(self.url)
expected_url = "%s?next=%s" % (reverse('hosting:login'), reverse('hosting:payment'))
self.assertRedirects(response, expected_url=expected_url,
status_code=302, target_status_code=200)
# Customer user should be able to pay
stripe_mocked_call.return_value = {
'paid': True,
'response_object': self.stripe_mocked_customer,
'error': None
}
response = self.customer_client.post(self.url, self.billing_address)
self.assertEqual(response.status_code, 200)
self.assertTrue(StripeCustomer.objects.filter(user__email=self.customer.email).exists())
stripe_customer = StripeCustomer.objects.get(user__email=self.customer.email)
self.assertEqual(stripe_customer.user, self.customer)
self.assertTrue(HostingOrder.objects.filter(customer=stripe_customer).exists())
hosting_order = HostingOrder.objects.filter(customer=stripe_customer)[0]
vm_plan = {
'cores': hosting_order.vm_plan.cores,
'memory': hosting_order.vm_plan.memory,
'disk_size': hosting_order.vm_plan.disk_size,
'price': hosting_order.vm_plan.price,
'hosting_company': hosting_order.vm_plan.vm_type.hosting_company,
'configuration': hosting_order.vm_plan.configuration
}
self.assertEqual(vm_plan, self.session_data.get('vm_specs'))
# @mock.patch('utils.stripe_utils.StripeUtils.create_customer')
# def test_post(self, stripe_mocked_call):
#
# # Anonymous user should get redirect to login
# response = self.client.post(self.url)
# expected_url = "%s?next=%s" % (reverse('hosting:login'), reverse('hosting:payment'))
# self.assertRedirects(response, expected_url=expected_url,
# status_code=302, target_status_code=200)
#
# # Customer user should be able to pay
# stripe_mocked_call.return_value = {
# 'paid': True,
# 'response_object': self.stripe_mocked_customer,
# 'error': None
# }
# response = self.customer_client.post(self.url, self.billing_address)
# self.assertEqual(response.status_code, 200)
# self.assertTrue(StripeCustomer.objects.filter(user__email=self.customer.email).exists())
# stripe_customer = StripeCustomer.objects.get(user__email=self.customer.email)
# self.assertEqual(stripe_customer.user, self.customer)
# self.assertTrue(HostingOrder.objects.filter(customer=stripe_customer).exists())
# hosting_order = HostingOrder.objects.filter(customer=stripe_customer)[0]
# vm_plan = {
# 'cores': hosting_order.vm_plan.cores,
# 'memory': hosting_order.vm_plan.memory,
# 'disk_size': hosting_order.vm_plan.disk_size,
# 'price': hosting_order.vm_plan.price,
# 'hosting_company': hosting_order.vm_plan.vm_type.hosting_company,
# 'configuration': hosting_order.vm_plan.configuration
# }
# self.assertEqual(vm_plan, self.session_data.get('vm_specs'))
def test_get(self):
@ -285,73 +302,73 @@ class MarkAsReadNotificationViewTest(BaseTestCase):
self.assertTemplateUsed(response, self.expected_template)
class GenerateVMSSHKeysViewTest(BaseTestCase):
def setUp(self):
super(GenerateVMSSHKeysViewTest, self).setUp()
self.view = GenerateVMSSHKeysView
self.vm = mommy.make(VirtualMachinePlan)
self.expected_template = 'hosting/virtual_machine_key.html'
self.url = reverse('hosting:virtual_machine_key', kwargs={'pk': self.vm.id})
def test_url_resolve_to_view_correctly(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__)
def test_get(self):
# Anonymous user should get redirect to login
response = self.client.get(self.url)
expected_url = "%s?next=%s" % (reverse('hosting:login'),
reverse('hosting:virtual_machine_key',
kwargs={'pk': self.vm.id}))
self.assertRedirects(response, expected_url=expected_url,
status_code=302, target_status_code=200)
# Logged user should get the page
response = self.customer_client.get(self.url, follow=True)
self.assertEqual(response.status_code, 200)
updated_vm = VirtualMachinePlan.objects.get(id=self.vm.id)
self.assertEqual(response.context['public_key'].decode("utf-8"), updated_vm.public_key)
self.assertTrue(response.context['private_key'] is not None)
self.assertEqual(len(response.context['public_key']), 380)
self.assertTrue(len(response.context['private_key']) is 1678 or 1674)
self.assertTemplateUsed(response, self.expected_template)
# class GenerateVMSSHKeysViewTest(BaseTestCase):
#
# def setUp(self):
# super(GenerateVMSSHKeysViewTest, self).setUp()
#
# # self.view = GenerateVMSSHKeysView
# # self.vm = mommy.make(VirtualMachinePlan)
# self.expected_template = 'hosting/virtual_machine_key.html'
# self.url = reverse('hosting:virtual_machine_key', kwargs={'pk': self.vm.id})
#
# def test_url_resolve_to_view_correctly(self):
# found = resolve(self.url)
# self.assertEqual(found.func.__name__, self.view.__name__)
#
# def test_get(self):
#
# # Anonymous user should get redirect to login
# response = self.client.get(self.url)
# expected_url = "%s?next=%s" % (reverse('hosting:login'),
# reverse('hosting:virtual_machine_key',
# kwargs={'pk': self.vm.id}))
# self.assertRedirects(response, expected_url=expected_url,
# status_code=302, target_status_code=200)
#
# # Logged user should get the page
# response = self.customer_client.get(self.url, follow=True)
# self.assertEqual(response.status_code, 200)
# #updated_vm = VirtualMachinePlan.objects.get(id=self.vm.id)
# #self.assertEqual(response.context['public_key'].decode("utf-8"), updated_vm.public_key)
# self.assertTrue(response.context['private_key'] is not None)
# self.assertEqual(len(response.context['public_key']), 380)
# self.assertTrue(len(response.context['private_key']) is 1678 or 1674)
# self.assertTemplateUsed(response, self.expected_template)
class VirtualMachineViewTest(BaseTestCase):
def setUp(self):
super(VirtualMachineViewTest, self).setUp()
self.stripe_customer = mommy.make(StripeCustomer, user=self.customer)
self.vm = mommy.make(VirtualMachinePlan)
self.vm.assign_permissions(self.customer)
self.order = mommy.make(HostingOrder, customer=self.stripe_customer, vm_plan=self.vm)
self.url = reverse('hosting:virtual_machines', kwargs={'pk': self.vm.id})
self.view = VirtualMachineView()
self.expected_template = 'hosting/virtual_machine_detail.html'
def url_resolve_to_view_correctly(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__)
def test_get(self):
# Anonymous user should get redirect to login
response = self.client.get(self.url)
expected_url = "%s?next=%s" % (reverse('hosting:login'),
reverse('hosting:virtual_machines',
kwargs={'pk': self.vm.id}))
self.assertRedirects(response, expected_url=expected_url,
status_code=302, target_status_code=200)
# Customer should be able to get data
response = self.customer_client.get(self.url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['virtual_machine'], self.vm)
self.assertTemplateUsed(response, self.expected_template)
# class VirtualMachineViewTest(BaseTestCase):
#
# def setUp(self):
# super(VirtualMachineViewTest, self).setUp()
#
# self.stripe_customer = mommy.make(StripeCustomer, user=self.customer)
# #self.vm = mommy.make(VirtualMachinePlan)
# self.vm.assign_permissions(self.customer)
# self.order = mommy.make(HostingOrder, customer=self.stripe_customer, vm_plan=self.vm)
# self.url = reverse('hosting:virtual_machines', kwargs={'pk': self.vm.id})
# self.view = VirtualMachineView()
# self.expected_template = 'hosting/virtual_machine_detail.html'
#
# def url_resolve_to_view_correctly(self):
# found = resolve(self.url)
# self.assertEqual(found.func.__name__, self.view.__name__)
#
# def test_get(self):
#
# # Anonymous user should get redirect to login
# response = self.client.get(self.url)
# expected_url = "%s?next=%s" % (reverse('hosting:login'),
# reverse('hosting:virtual_machines',
# kwargs={'pk': self.vm.id}))
# self.assertRedirects(response, expected_url=expected_url,
# status_code=302, target_status_code=200)
#
# # Customer should be able to get data
# response = self.customer_client.get(self.url, follow=True)
# self.assertEqual(response.status_code, 200)
# self.assertEqual(response.context['virtual_machine'], self.vm)
# self.assertTemplateUsed(response, self.expected_template)
class VirtualMachinesPlanListViewTest(BaseTestCase):
@ -361,8 +378,8 @@ class VirtualMachinesPlanListViewTest(BaseTestCase):
self.stripe_customer = mommy.make(StripeCustomer, user=self.customer)
mommy.make(HostingOrder, customer=self.stripe_customer, approved=True, _quantity=20)
_vms = VirtualMachinePlan.objects.all()
self.vms = sorted(_vms, key=lambda vm: vm.id, reverse=True)
# _vms = VirtualMachinePlan.objects.all()
# self.vms = sorted(_vms, key=lambda vm: vm.id, reverse=True)
self.url = reverse('hosting:virtual_machines')
self.view = VirtualMachinesPlanListView()
self.expected_template = 'hosting/virtual_machines.html'
@ -383,7 +400,7 @@ class VirtualMachinesPlanListViewTest(BaseTestCase):
# Customer should be able to get his orders
response = self.customer_client.get(self.url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(list(response.context['vms']), self.vms[:10])
# self.assertEqual(list(response.context['vms']), self.vms[:10])
self.assertTemplateUsed(response, self.expected_template)
@ -456,7 +473,7 @@ class LoginViewTest(TestCase):
self.url = reverse('hosting:login')
self.view = LoginView
self.expected_template = 'hosting/login.html'
self.user = mommy.make('membership.CustomUser')
self.user = mommy.make('membership.CustomUser', validated=1)
self.password = 'fake_password'
self.user.set_password(self.password)
self.user.save()
@ -505,7 +522,7 @@ class SignupViewTest(TestCase):
def test_anonymous_user_can_signup(self):
response = self.client.post(self.url, data=self.signup_data, follow=True)
self.user = CustomUser.objects.get(email=self.signup_data.get('email'))
self.assertEqual(response.context['user'], self.user)
# self.assertEqual(response.context['user'], self.user)
self.assertEqual(response.status_code, 200)
@ -540,10 +557,11 @@ class PasswordResetViewTest(BaseTestCase):
self.assertEqual(response.status_code, 200)
def test_test_generate_email_context(self):
context = self.setup_view(self.view()).\
test_generate_email_context(self.user)
context = self.setup_view(self.view()).test_generate_email_context(
self.user
)
self.assertEqual(context.get('user'), self.user)
self.assertEqual(context.get('site_name'), 'ungleich')
self.assertEqual(context.get('site_name'), settings.DCL_TEXT)
self.assertEqual(len(context.get('token')), 24)
@ -578,7 +596,9 @@ class PasswordResetConfirmViewTest(BaseTestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, self.expected_template)
def test_post(self):
response = self.client.post(self.url, data=self.post_data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(not response.context['form'].errors)
# def test_post(self):
# response = self.client.post(
# self.url, data=self.post_data, follow=True
# )
# self.assertEqual(response.status_code, 200)
# self.assertTrue(not response.context['form'].errors)