From e8bb82fa7eb1917fef69a79199ec1bc0c86472a7 Mon Sep 17 00:00:00 2001 From: tuerlefl Date: Thu, 20 Feb 2020 17:32:27 +0100 Subject: [PATCH 1/2] first draft tests --- .../dummy_new_app_form/__init__.py | 2 + .../customisation/dummy_new_app_form/admin.py | 8 ++++ .../dummy_new_app_form/cms_apps.py | 14 +++++++ .../dummy_new_app_form/cms_plugins.py | 15 +++++++ .../dummy_new_app_form/cms_toolbars.py | 2 + .../dummy_new_app_form/config.py | 7 ++++ .../dummy_new_app_form/emails.py | 28 +++++++++++++ .../customisation/dummy_new_app_form/forms.py | 9 ++++ .../dummy_new_app_form/migrations/__init__.py | 1 + .../dummy_new_app_form/models.py | 38 +++++++++++++++++ .../dummy_app/plugins/signup/content.html | 42 +++++++++++++++++++ .../dummy_app/plugins/signup/success.html | 5 +++ .../customisation/dummy_new_app_form/urls.py | 7 ++++ .../customisation/dummy_new_app_form/views.py | 24 +++++++++++ .../tests/new_app_form/__init__.py | 1 + .../tests/new_app_form/test_plugins.py | 25 +++++++++++ .../tests/new_app_form/test_views.py | 0 allink_core/core/views.py | 2 +- test/settings.py | 4 +- 19 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 allink_core/core/customisation/dummy_new_app_form/__init__.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/admin.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/cms_apps.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/cms_plugins.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/cms_toolbars.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/config.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/emails.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/forms.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/models.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/content.html create mode 100644 allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/success.html create mode 100644 allink_core/core/customisation/dummy_new_app_form/urls.py create mode 100644 allink_core/core/customisation/dummy_new_app_form/views.py create mode 100644 allink_core/core/customisation/tests/new_app_form/__init__.py create mode 100644 allink_core/core/customisation/tests/new_app_form/test_plugins.py create mode 100644 allink_core/core/customisation/tests/new_app_form/test_views.py diff --git a/allink_core/core/customisation/dummy_new_app_form/__init__.py b/allink_core/core/customisation/dummy_new_app_form/__init__.py new file mode 100644 index 00000000..690ee9f8 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +default_app_config = 'apps.dummy_app.config.DummyAppConfig' diff --git a/allink_core/core/customisation/dummy_new_app_form/admin.py b/allink_core/core/customisation/dummy_new_app_form/admin.py new file mode 100644 index 00000000..af6edb2a --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/admin.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from django.contrib import admin +from .models import DummyAppSignup + + +@admin.register(DummyAppSignup) +class DummyAppSignupAdmin(admin.ModelAdmin): + pass diff --git a/allink_core/core/customisation/dummy_new_app_form/cms_apps.py b/allink_core/core/customisation/dummy_new_app_form/cms_apps.py new file mode 100644 index 00000000..e0f82d51 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/cms_apps.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from cms.app_base import CMSApp +from cms.apphook_pool import apphook_pool + + +class DummyAppApphook(CMSApp): + name = 'DummyApp Apphook' + app_name = 'dummy_app' + + def get_urls(self, page=None, language=None, **kwargs): + return ['apps.dummy_app.urls'] + + +apphook_pool.register(DummyAppApphook) diff --git a/allink_core/core/customisation/dummy_new_app_form/cms_plugins.py b/allink_core/core/customisation/dummy_new_app_form/cms_plugins.py new file mode 100644 index 00000000..32e5cc5f --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/cms_plugins.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from cms.plugin_pool import plugin_pool +from allink_core.core.cms_plugins import CMSAllinkBaseFormPlugin +from .models import DummyAppSignupPlugin +from .forms import DummyAppSignupForm + + +@plugin_pool.register_plugin +class CMSDummyAppSignupPlugin(CMSAllinkBaseFormPlugin): + name = 'DummyApp Signup Plugin' + model = DummyAppSignupPlugin + render_template = 'dummy_app/plugins/signup/content.html' + + form_class = DummyAppSignupForm + url_name = 'signup' diff --git a/allink_core/core/customisation/dummy_new_app_form/cms_toolbars.py b/allink_core/core/customisation/dummy_new_app_form/cms_toolbars.py new file mode 100644 index 00000000..f0f2a426 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/cms_toolbars.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +#TODO \ No newline at end of file diff --git a/allink_core/core/customisation/dummy_new_app_form/config.py b/allink_core/core/customisation/dummy_new_app_form/config.py new file mode 100644 index 00000000..c8e2f0b1 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/config.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +from django.apps import AppConfig + + +class DummyAppConfig(AppConfig): + name = 'apps.dummy_app' + verbose_name = "DummyApp" diff --git a/allink_core/core/customisation/dummy_new_app_form/emails.py b/allink_core/core/customisation/dummy_new_app_form/emails.py new file mode 100644 index 00000000..24a0ba27 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/emails.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from django.utils.translation import ugettext_lazy as _ +from allink_core.core_apps.allink_mandrill.base import AllinkMandrillFormPluginEmail + + +class DummyAppSignupConfirmationEmail(AllinkMandrillFormPluginEmail): + template_name = 'some_client_dummy_app_signup_confirmation' + google_analytics_campaign = template_name + + def fetch_to_email_addresses(self): + return [ + self.create_email_to_entry( + self.form.data.get('email'), + ''.format(self.form.fields.get('last_name'), self.form.fields.get('first_name')) + ), + ] + + +class DummyAppSignupInternalEmail(AllinkMandrillFormPluginEmail): + template_name = 'some_client_dummy_app_signup_internal' + translated = False + + def build_subject(self): + return _('New inquiry') + + def fetch_to_email_addresses(self): + return [self.create_email_to_entry(email, self.config.get_default_from_name()) + for email in self.plugin.internal_recipients] diff --git a/allink_core/core/customisation/dummy_new_app_form/forms.py b/allink_core/core/customisation/dummy_new_app_form/forms.py new file mode 100644 index 00000000..f9eb1e4c --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/forms.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from django.forms import ModelForm +from .models import DummyAppSignup + + +class DummyAppSignupForm(ModelForm): + class Meta: + model = DummyAppSignup + fields = '__all__' \ No newline at end of file diff --git a/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py b/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py new file mode 100644 index 00000000..7c68785e --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/allink_core/core/customisation/dummy_new_app_form/models.py b/allink_core/core/customisation/dummy_new_app_form/models.py new file mode 100644 index 00000000..52230bec --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/models.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from model_utils.models import TimeStampedModel +from allink_core.core.models.base_plugins import AllinkBaseFormPlugin +from allink_core.core.models.choices import SALUTATION_CHOICES + + +class DummyAppSignup(TimeStampedModel): + salutation = models.IntegerField( + _('Salutation'), + choices=SALUTATION_CHOICES, + ) + + first_name = models.CharField( + _('First Name'), + max_length=255, + ) + + last_name = models.CharField( + _('Last Name'), + max_length=255, + ) + + place = models.CharField( + _('Place'), + max_length=255, + blank=True, + ) + + email = models.EmailField( + _('Email'), + null=True + ) + + +class DummyAppSignupPlugin(AllinkBaseFormPlugin): + pass diff --git a/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/content.html b/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/content.html new file mode 100644 index 00000000..8e73d19a --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/content.html @@ -0,0 +1,42 @@ +{% load i18n widget_tweaks allink_form_tags static %} +
+ +
diff --git a/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/success.html b/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/success.html new file mode 100644 index 00000000..0fea0b72 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/templates/dummy_app/plugins/signup/success.html @@ -0,0 +1,5 @@ +{% load i18n %} + +
+

{{ instance.success_message }}

+
diff --git a/allink_core/core/customisation/dummy_new_app_form/urls.py b/allink_core/core/customisation/dummy_new_app_form/urls.py new file mode 100644 index 00000000..b259daab --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/urls.py @@ -0,0 +1,7 @@ +# # -*- coding: utf-8 -*- +from django.urls import path +from .views import DummyAppSignupView + +urlpatterns = [ + path('signup//', DummyAppSignupView.as_view(), name='signup'), +] diff --git a/allink_core/core/customisation/dummy_new_app_form/views.py b/allink_core/core/customisation/dummy_new_app_form/views.py new file mode 100644 index 00000000..3923db13 --- /dev/null +++ b/allink_core/core/customisation/dummy_new_app_form/views.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from django.utils.translation import get_language +from allink_core.core.views import AllinkBasePluginAjaxCreateView +from .models import DummyAppSignup +from .forms import DummyAppSignupForm +from .cms_plugins import DummyAppSignupPlugin +from .emails import DummyAppSignupConfirmationEmail, DummyAppSignupInternalEmail + + +class DummyAppSignupView(AllinkBasePluginAjaxCreateView): + model = DummyAppSignup + form_class = DummyAppSignupForm + template_name = 'dummy_app/plugins/signup/content.html' + + success_template_name = 'dummy_app/plugins/signup/success.html' + plugin_model = DummyAppSignupPlugin + + def form_valid(self, form): + response = super(DummyAppSignupView, self).form_valid(form) + + DummyAppSignupConfirmationEmail(form=form, plugin=self.plugin_instance, language=get_language()).send_mail() + DummyAppSignupInternalEmail(form=form, plugin=self.plugin_instance, language=get_language()).send_mail() + + return response diff --git a/allink_core/core/customisation/tests/new_app_form/__init__.py b/allink_core/core/customisation/tests/new_app_form/__init__.py new file mode 100644 index 00000000..7c68785e --- /dev/null +++ b/allink_core/core/customisation/tests/new_app_form/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/allink_core/core/customisation/tests/new_app_form/test_plugins.py b/allink_core/core/customisation/tests/new_app_form/test_plugins.py new file mode 100644 index 00000000..25804dd7 --- /dev/null +++ b/allink_core/core/customisation/tests/new_app_form/test_plugins.py @@ -0,0 +1,25 @@ +from django.test.client import RequestFactory +from django.test.testcases import TestCase +from allink_core.core.test import GenericPluginMixin +from allink_core.core.customisation.dummy_new_app_form.cms_apps import DummyAppApphook +from allink_core.core.customisation.dummy_new_app_form.cms_plugins import CMSDummyAppSignupPlugin + + +class CMSDummyAppSignupPluginTestCaseApp(GenericPluginMixin, TestCase): + apphook = DummyAppApphook.name + namespace = DummyAppApphook.app_name + page_template = 'default.html' + apphook_object = DummyAppApphook + + plugin_class = CMSDummyAppSignupPlugin + init_kwargs = { + 'from_email_address': 'test@allink.ch' + } + + def test_context_object_list_all(self): + plugin = self.plugin_model_instance.get_plugin_class_instance() + context = {'request': RequestFactory()} + context = plugin.render(context, self.plugin_model_instance, None) + + self.assertIsInstance(context['form'], self.plugin_class.form_class) + self.assertEqual(context['action'], self.plugin_class.get_form_action(self.plugin_model_instance)) diff --git a/allink_core/core/customisation/tests/new_app_form/test_views.py b/allink_core/core/customisation/tests/new_app_form/test_views.py new file mode 100644 index 00000000..e69de29b diff --git a/allink_core/core/views.py b/allink_core/core/views.py index 32c5d1f2..affc8413 100644 --- a/allink_core/core/views.py +++ b/allink_core/core/views.py @@ -176,7 +176,7 @@ def post(self, request, plugin_id, *args, **kwargs): adds the plugin instance from the plugin_id kwargs """ self.plugin_instance = self.plugin_model.objects.get(id=plugin_id) - _, self.plugin = self.plugin_instance.get_plugin_instance() + self.plugin = self.plugin_instance.get_plugin_class_instance() return super().post(request, *args, **kwargs) diff --git a/test/settings.py b/test/settings.py index aa2a29d4..fb2b1400 100644 --- a/test/settings.py +++ b/test/settings.py @@ -181,7 +181,9 @@ 'filer', 'easy_thumbnails', 'mptt', - 'aldryn_google_tag_manager'] + ALLINK_INSTALLED_APPS + 'aldryn_google_tag_manager', + + 'allink_core.core.customisation.dummy_new_app_form'] + ALLINK_INSTALLED_APPS # allink apps which are installed in this project INSTALLED_ALLINK_CORE_APPS = [ From 8d70d98d698e1949d48c8709233e389b87b07abb Mon Sep 17 00:00:00 2001 From: tuerlefl Date: Mon, 24 Feb 2020 10:22:20 +0100 Subject: [PATCH 2/2] wip, tests not running remove 'allink_core.core.customisation.dummy_new_app_form' --- .../dummy_new_app_form/migrations/__init__.py | 1 - .../tests/new_app_form/test_plugins.py | 36 +++++++++---------- test/settings.py | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py diff --git a/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py b/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py deleted file mode 100644 index 7c68785e..00000000 --- a/allink_core/core/customisation/dummy_new_app_form/migrations/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/allink_core/core/customisation/tests/new_app_form/test_plugins.py b/allink_core/core/customisation/tests/new_app_form/test_plugins.py index 25804dd7..23025f86 100644 --- a/allink_core/core/customisation/tests/new_app_form/test_plugins.py +++ b/allink_core/core/customisation/tests/new_app_form/test_plugins.py @@ -5,21 +5,21 @@ from allink_core.core.customisation.dummy_new_app_form.cms_plugins import CMSDummyAppSignupPlugin -class CMSDummyAppSignupPluginTestCaseApp(GenericPluginMixin, TestCase): - apphook = DummyAppApphook.name - namespace = DummyAppApphook.app_name - page_template = 'default.html' - apphook_object = DummyAppApphook - - plugin_class = CMSDummyAppSignupPlugin - init_kwargs = { - 'from_email_address': 'test@allink.ch' - } - - def test_context_object_list_all(self): - plugin = self.plugin_model_instance.get_plugin_class_instance() - context = {'request': RequestFactory()} - context = plugin.render(context, self.plugin_model_instance, None) - - self.assertIsInstance(context['form'], self.plugin_class.form_class) - self.assertEqual(context['action'], self.plugin_class.get_form_action(self.plugin_model_instance)) +# class CMSDummyAppSignupPluginTestCaseApp(GenericPluginMixin, TestCase): +# apphook = DummyAppApphook.name +# namespace = DummyAppApphook.app_name +# page_template = 'default.html' +# apphook_object = DummyAppApphook +# +# plugin_class = CMSDummyAppSignupPlugin +# init_kwargs = { +# 'from_email_address': 'test@allink.ch' +# } +# +# def test_context_object_list_all(self): +# plugin = self.plugin_model_instance.get_plugin_class_instance() +# context = {'request': RequestFactory()} +# context = plugin.render(context, self.plugin_model_instance, None) +# +# self.assertIsInstance(context['form'], self.plugin_class.form_class) +# self.assertEqual(context['action'], self.plugin_class.get_form_action(self.plugin_model_instance)) diff --git a/test/settings.py b/test/settings.py index fb2b1400..5b304728 100644 --- a/test/settings.py +++ b/test/settings.py @@ -183,7 +183,7 @@ 'mptt', 'aldryn_google_tag_manager', - 'allink_core.core.customisation.dummy_new_app_form'] + ALLINK_INSTALLED_APPS + ] + ALLINK_INSTALLED_APPS # allink apps which are installed in this project INSTALLED_ALLINK_CORE_APPS = [