From 280bc58695da60737c5aac730c78f2b55d4e1725 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Tue, 27 Jun 2017 02:03:10 +0300 Subject: [PATCH] mails template --- docker-compose.yml | 2 ++ src/commons/utils.py | 13 +++++++--- src/customer/utils.py | 7 +++++- src/dokumentor/settings/common.py | 2 ++ src/tests/test_tasks.py | 35 ++++++++++++-------------- src/tests/test_utils.py | 17 ++++++++++--- templates/emails/license_activated.txt | 2 +- templates/emails/license_ended.txt | 2 +- templates/emails/license_ends.txt | 2 +- 9 files changed, 53 insertions(+), 29 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6333a18..2e480dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,6 +47,8 @@ services: - "5671" bower: + restart: always + container_name: dokumentor-bower image: digitallyseamless/nodejs-bower-grunt command: bash -c "bower i" volumes: diff --git a/src/commons/utils.py b/src/commons/utils.py index a54da69..20beb1c 100644 --- a/src/commons/utils.py +++ b/src/commons/utils.py @@ -1,9 +1,13 @@ # -*- coding: utf-8 -*- import datetime +from django.conf import settings + -# convert datetime to json def dthandler(): + """ + convert datetime to json + """ return lambda obj: obj.isoformat() if \ isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date) else None @@ -23,5 +27,8 @@ def only_numerics(value): return u''.join(c for c in value if c.isdigit()) -def get_site_url(request): - return f'{request.scheme}://{request.get_host()}' +def get_site_url(request=None): + if request: + return f'{request.scheme}://{request.get_host()}' + else: + return settings.SITE_URL diff --git a/src/customer/utils.py b/src/customer/utils.py index ebcf400..38df52a 100644 --- a/src/customer/utils.py +++ b/src/customer/utils.py @@ -5,6 +5,8 @@ from django.conf import settings from django.core.mail import EmailMessage from django.template.loader import render_to_string +from commons.utils import get_site_url + def check_one_profile(profile, now, manual=False): @@ -31,6 +33,7 @@ def check_one_profile(profile, now, manual=False): 'support_email': settings.SUPPORT_EMAIL, 'license_starts': licenses[0].date_from, 'license_ends': licenses[0].date_to, + 'site_url': get_site_url() } email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) @@ -52,6 +55,7 @@ def check_one_profile(profile, now, manual=False): 'support_email': settings.SUPPORT_EMAIL, 'license_ends': licenses[0].date_to, 'licenses_to_pay': licenses_to_pay, + 'site_url': get_site_url() } email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) @@ -67,6 +71,7 @@ def check_one_profile(profile, now, manual=False): 'support_email': settings.SUPPORT_EMAIL, 'license_ends': licenses[0].date_to, 'licenses_to_pay': licenses_to_pay, + 'site_url': get_site_url() } email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) @@ -81,7 +86,7 @@ def check_one_profile(profile, now, manual=False): subject = 'Документор: есть неоплаченные счета' dict_context = {'user_email': user_email, 'support_email': settings.SUPPORT_EMAIL, - + 'site_url': get_site_url() } email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) diff --git a/src/dokumentor/settings/common.py b/src/dokumentor/settings/common.py index 9a8d26a..3450e0d 100644 --- a/src/dokumentor/settings/common.py +++ b/src/dokumentor/settings/common.py @@ -330,3 +330,5 @@ YANDEX_MONEY_MAIL_ADMINS_ON_PAYMENT_ERROR = True DADATA_API_KEY = 'e4232c46f82c0b2e8c5f9bd583d6224ce9c934e0' DADATA_SECRET_KEY = '9c5c3fdfba74af122730db650346b3e91586abc7' + +SITE_URL = 'https://dokumentor.ru' diff --git a/src/tests/test_tasks.py b/src/tests/test_tasks.py index 8be26ac..44e3695 100644 --- a/src/tests/test_tasks.py +++ b/src/tests/test_tasks.py @@ -1,37 +1,33 @@ # -*- coding: utf-8 -*- import pytest + from django.utils import timezone + from myauth.models import DokUser, ConfirmEmail from customer.models import UserProfile from customer.tasks import delete_not_activated_users -@pytest.mark.django_db -def test_delete_not_activated_users_more_than_five_day(user): - user.is_active = False - profile = user.profile - profile.active = False - profile.confirmed = False - profile.created_at = timezone.now() - timezone.timedelta(days=15) - profile.save() - user.save() - ConfirmEmail.objects.get_or_create(user=user) - - delete_not_activated_users() +dates_gte_five = [timezone.now() - timezone.timedelta(days=100), + timezone.now() - timezone.timedelta(days=15), + timezone.now() - timezone.timedelta(days=5)] - assert DokUser.objects.count() == 0 - assert UserProfile.objects.count() == 0 - assert ConfirmEmail.objects.count() == 0 +dates_lt_five = [timezone.now() - timezone.timedelta(days=4), + timezone.now() - timezone.timedelta(days=3), + timezone.now() - timezone.timedelta(days=2), + timezone.now() - timezone.timedelta(days=1), + timezone.now() - timezone.timedelta(days=0)] +@pytest.mark.parametrize('create_date', dates_gte_five) @pytest.mark.django_db -def test_delete_not_activated_users_equal_five_day(user): +def test_delete_not_activated_users_great_five_days(user, create_date): user.is_active = False profile = user.profile profile.active = False profile.confirmed = False - profile.created_at = timezone.now() - timezone.timedelta(days=5) + profile.created_at = create_date profile.save() user.save() ConfirmEmail.objects.get_or_create(user=user) @@ -43,13 +39,14 @@ def test_delete_not_activated_users_equal_five_day(user): assert ConfirmEmail.objects.count() == 0 +@pytest.mark.parametrize('create_date', dates_lt_five) @pytest.mark.django_db -def test_delete_not_activated_users_less_five_day(user): +def test_delete_not_activated_users_less_five_day(user, create_date): user.is_active = False profile = user.profile profile.active = False profile.confirmed = False - profile.created_at = timezone.now() - timezone.timedelta(days=4) + profile.created_at = create_date profile.save() user.save() ConfirmEmail.objects.get_or_create(user=user) diff --git a/src/tests/test_utils.py b/src/tests/test_utils.py index be81c64..448f3e5 100644 --- a/src/tests/test_utils.py +++ b/src/tests/test_utils.py @@ -1,8 +1,19 @@ # -*- coding: utf-8 -*- +import pytest -from commons import utils +from commons.utils import get_site_url -def test_utils(mocked_request): - url = utils.get_site_url(mocked_request) +def test_utils_with_request(mocked_request): + url = get_site_url(mocked_request) assert len(url.split('//')) == 2 + + +def test_utils_without_request(): + url = get_site_url() + assert len(url.split('//')) == 2 + + +@pytest.mark.django_db +def test_check_one_profile(): + pass diff --git a/templates/emails/license_activated.txt b/templates/emails/license_activated.txt index d8c3a5c..0adcf63 100644 --- a/templates/emails/license_activated.txt +++ b/templates/emails/license_activated.txt @@ -1,6 +1,6 @@ Здравствуйте! -Ваш профиль на сайте Документор ({{ site_url|default:'https://dokumentor.ru' }}) был активирован. +Ваш профиль на сайте Документор ({{ site_url }}) был активирован. Срок действия лицензии с {{ license_starts }} по {{ license_ends }}. Это письмо написано роботом. Отвечать на него не нужно. diff --git a/templates/emails/license_ended.txt b/templates/emails/license_ended.txt index 8efdb58..92d685f 100644 --- a/templates/emails/license_ended.txt +++ b/templates/emails/license_ended.txt @@ -1,6 +1,6 @@ Здравствуйте! -Закончилось действие вашего аккаунта на сайте Документор ({{ site_url|default:'https://dokumentor.ru' }}). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} +Закончилось действие вашего аккаунта на сайте Документор ({{ site_url }}). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} Это письмо написано роботом. Отвечать на него не нужно. diff --git a/templates/emails/license_ends.txt b/templates/emails/license_ends.txt index 4353b51..9a82a8a 100644 --- a/templates/emails/license_ends.txt +++ b/templates/emails/license_ends.txt @@ -1,6 +1,6 @@ Здравствуйте! -Через 1 день заканчивается действие вашего аккаунта на сайте Документор ({{ site_url|default:'https://dokumentor.ru' }}). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} +Через 1 день заканчивается действие вашего аккаунта на сайте Документор ({{ site_url }}). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} Это письмо написано роботом. Отвечать на него не нужно.