From 273fa75d553faeddea1b9da582efed18d492b160 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 26 Nov 2017 01:12:16 +0100 Subject: [PATCH] Fix PEP8 warnings --- digitalglarus/test_views.py | 40 ++++++++++++++----- hosting/test_views.py | 43 +++++++++++---------- membership/tests.py | 76 ++++++++++++++++++------------------- opennebula_api/tests.py | 9 +++-- ungleich_page/cms_menus.py | 2 +- utils/tests.py | 4 +- 6 files changed, 100 insertions(+), 74 deletions(-) diff --git a/digitalglarus/test_views.py b/digitalglarus/test_views.py index adc25167..cdd23bad 100644 --- a/digitalglarus/test_views.py +++ b/digitalglarus/test_views.py @@ -15,9 +15,11 @@ from membership.models import CustomUser, StripeCustomer from utils.tests import BaseTestCase -from .views import LoginView, SignupView, PasswordResetView, PasswordResetConfirmView,\ +from .views import ( + LoginView, SignupView, PasswordResetView, PasswordResetConfirmView, MembershipPricingView, MembershipPaymentView -from .models import MembershipType, MembershipOrder +) +from .models import MembershipType class ContactViewTest(TestCase): @@ -41,8 +43,14 @@ class ContactViewTest(TestCase): class ViewsTest(CMSTestCase): def setUp(self): - self.page1 = create_page('home', 'home_digitalglarus.html', published=True, language='en-us') - self.page2 = create_page('about', 'about.html', published=True, language='en-us', slug='about') + self.page1 = create_page( + 'home', 'home_digitalglarus.html', published=True, + language='en-us' + ) + self.page2 = create_page( + 'about', 'about.html', published=True, language='en-us', + slug='about' + ) def test_digitalglarus_templates(self): res1 = self.client.get('/en-us/') @@ -69,7 +77,9 @@ class MembershipPricingViewTest(BaseTestCase): # Anonymous user should get data response = self.client.get(self.url) self.assertEqual(response.status_code, 200) - self.assertEqual(response.context['membership_type'], self.membership_type) + self.assertEqual( + response.context['membership_type'], self.membership_type + ) self.assertTemplateUsed(response, self.expected_template) @@ -101,8 +111,10 @@ class MembershipPaymentViewTest(BaseTestCase): # Anonymous user should get redirect to login response = self.client.get(self.url) - expected_url = "%s?next=%s" % (reverse('digitalglarus:signup'), - reverse('digitalglarus:membership_payment')) + expected_url = "%s?next=%s" % ( + reverse('digitalglarus:signup'), + reverse('digitalglarus:membership_payment') + ) self.assertRedirects(response, expected_url=expected_url, status_code=302, target_status_code=200) @@ -132,8 +144,14 @@ class MembershipPaymentViewTest(BaseTestCase): } 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.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(MembershipOrder.objects.filter(customer=stripe_customer).exists()) # membership_order = MembershipOrder.objects.filter( @@ -216,7 +234,9 @@ class SignupViewTest(TestCase): self.assertTemplateUsed(response, self.expected_template) def test_anonymous_user_can_signup(self): - response = self.client.post(self.url, data=self.signup_data, follow=True) + 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.status_code, 200) diff --git a/hosting/test_views.py b/hosting/test_views.py index e417a5e7..30d058ad 100644 --- a/hosting/test_views.py +++ b/hosting/test_views.py @@ -13,10 +13,12 @@ from stored_messages.models import Inbox from membership.models import CustomUser, StripeCustomer from .models import HostingOrder -from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, SignupView, \ - PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineView, \ - VirtualMachinesPlanListView, PasswordResetView, PasswordResetConfirmView, HostingPricingView, \ - NotificationsView, MarkAsReadNotificationView +from .views import ( + DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, + SignupView, PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, + VirtualMachinesPlanListView, PasswordResetView, PasswordResetConfirmView, + HostingPricingView, NotificationsView, MarkAsReadNotificationView +) from utils.tests import BaseTestCase @@ -52,15 +54,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(), } @@ -76,15 +79,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(), } @@ -100,15 +104,16 @@ 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(), } @@ -124,11 +129,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): @@ -184,7 +189,7 @@ class PaymentVMViewTest(BaseTestCase): # } # } - session = self.customer_client.session + # session = self.customer_client.session # session.update(self.session_data) # session.save() @@ -381,8 +386,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' diff --git a/membership/tests.py b/membership/tests.py index d1c057f8..4b36fe4c 100644 --- a/membership/tests.py +++ b/membership/tests.py @@ -1,41 +1,41 @@ -import re +# import re -from django.test import TestCase -from django.core.urlresolvers import reverse -from django.core import mail +# from django.test import TestCase +# from django.core.urlresolvers import reverse +# from django.core import mail -class LoginTestCase(TestCase): - def test_login(self): - url = reverse('login_glarus') - res = self.client.post( - url, - data={ - 'email': 'test@gmail.com', - 'password': 'test', 'name': - 'test'} - ) - #self.assertContains(res, "You\'re successfully registered!", 1, 200) - #self.assertEqual(len(mail.outbox), 1) - - # validation_url = re.findall(r"http://.*?(/.*)", mail.outbox[0].body) - # res1 = self.client.get(validation_url[0] + '/') - # self.assertContains(res1, "Email verified!", 1, 200) - # - # res2 = self.client.post( - # url, data={'email': 'test@gmail.com', 'password': 'test'} - # ) - # self.assertEqual(res2.status_code, 302) - # redirect_location = res2.get('Location') - # - # res3 = self.client.get(redirect_location) - # self.assertContains(res3, 'Pick coworking date.', 1, 200) - - # check fail login - - # res4 = self.client.post( - # url, data={ - # 'email': 'test@gmail.com', 'password': 'falsepassword' - # } - # ) - # self.assertContains(res4, 'Sorry, that login was invalid.', 1, 200) +# class LoginTestCase(TestCase): +# def test_login(self): +# url = reverse('login_glarus') +# res = self.client.post( +# url, +# data={ +# 'email': 'test@gmail.com', +# 'password': 'test', 'name': +# 'test'} +# ) +# self.assertContains(res, "You\'re successfully registered!", 1, 200) +# self.assertEqual(len(mail.outbox), 1) +# +# validation_url = re.findall(r"http://.*?(/.*)", mail.outbox[0].body) +# res1 = self.client.get(validation_url[0] + '/') +# self.assertContains(res1, "Email verified!", 1, 200) +# +# res2 = self.client.post( +# url, data={'email': 'test@gmail.com', 'password': 'test'} +# ) +# self.assertEqual(res2.status_code, 302) +# redirect_location = res2.get('Location') +# +# res3 = self.client.get(redirect_location) +# self.assertContains(res3, 'Pick coworking date.', 1, 200) +# +# # check fail login +# +# res4 = self.client.post( +# url, data={ +# 'email': 'test@gmail.com', 'password': 'falsepassword' +# } +# ) +# self.assertContains(res4, 'Sorry, that login was invalid.', 1, 200) diff --git a/opennebula_api/tests.py b/opennebula_api/tests.py index d25d4be7..c521a7df 100644 --- a/opennebula_api/tests.py +++ b/opennebula_api/tests.py @@ -13,8 +13,8 @@ from utils.models import CustomUser @skipIf( settings.OPENNEBULA_DOMAIN is None or settings.OPENNEBULA_DOMAIN is "test_domain", - """OpenNebula details unavailable, so skipping - OpenNebulaManagerTestCases""" + """OpenNebula details unavailable, so skipping + OpenNebulaManagerTestCases""" ) class OpenNebulaManagerTestCases(TestCase): """This class defines the test suite for the opennebula manager model.""" @@ -127,11 +127,12 @@ class OpenNebulaManagerTestCases(TestCase): """Test the opennebula manager requires the user to have a ssh key when creating a new vm""" + @skipIf( settings.OPENNEBULA_DOMAIN is None or settings.OPENNEBULA_DOMAIN is "test_domain", - """OpenNebula details unavailable, so skipping - VirtualMachineSerializerTestCase""" + """OpenNebula details unavailable, so skipping + VirtualMachineSerializerTestCase""" ) class VirtualMachineSerializerTestCase(TestCase): def setUp(self): diff --git a/ungleich_page/cms_menus.py b/ungleich_page/cms_menus.py index 6aa0ac41..4e17c352 100644 --- a/ungleich_page/cms_menus.py +++ b/ungleich_page/cms_menus.py @@ -14,7 +14,7 @@ class GlasfaserMenu(CMSAttachMenu): nodes = [] glasfaser_cms = 'ungleich_page/glasfaser_cms_page.html' if (request and request.current_page and - request.current_page.get_template() == glasfaser_cms): + request.current_page.get_template() == glasfaser_cms): template_context = { "request": request, } diff --git a/utils/tests.py b/utils/tests.py index 7c7dcc70..ce54800a 100644 --- a/utils/tests.py +++ b/utils/tests.py @@ -28,8 +28,8 @@ class BaseTestCase(TestCase): # Users self.customer, self.another_customer = mommy.make( - 'membership.CustomUser', validated =1, - _quantity=2) + 'membership.CustomUser', validated=1, _quantity=2 + ) self.customer.set_password(self.dummy_password) self.customer.save() self.another_customer.set_password(self.dummy_password)