Skip to content

Commit

Permalink
demoapp
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpoi committed Oct 10, 2024
1 parent 8ecbb40 commit c00186f
Show file tree
Hide file tree
Showing 68 changed files with 40 additions and 514 deletions.
Binary file removed .coverage
Binary file not shown.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
omit =
*/post_office/migrations/*
*/post_office/tests/*
*/celery_project/*
*/demoapp/*
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ jobs:
- name: Run Test
env:
DJANGO_SETTINGS_MODULE: post_office.test_settings
DJANGO_SETTINGS_MODULE: demoapp.test_settings
run: |
pytest celery_project
pytest demoapp
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ celerybeat-schedule
staticfiles/
static/
.coverage
.coveragerc
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion celery_project/celery.py → demoapp/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "celery_project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demoapp.settings")

app = Celery("celery_project")

Expand Down
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion testapp/middleware.py → demoapp/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def process_request(self, request):
admin_user = get_user_model().objects.first()
if not admin_user:
admin_user = get_user_model().objects.create_user(username='admin', password='secret', is_superuser=True, is_staff=True)
request.user = admin_user
request.user = admin_user
2 changes: 1 addition & 1 deletion celery_project/pytest.ini → demoapp/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = post_office.test_settings
DJANGO_SETTINGS_MODULE = demoapp.test_settings
python_files = tests.py test_*.py *_tests.py
addopts = --cov --cov-report=term-missing --cov-config=.coveragerc
12 changes: 6 additions & 6 deletions celery_project/settings.py → demoapp/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for celery_project project.
Django settings for demoapp project.
Generated by 'django-admin startproject' using Django 3.0.5.
Expand Down Expand Up @@ -70,12 +70,12 @@
MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'testapp.middleware.AutoLoginMiddleware',
'demoapp.middleware.AutoLoginMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
]

ROOT_URLCONF = 'celery_project.urls'
ROOT_URLCONF = 'demoapp.urls'

SILENCED_SYSTEM_CHECKS = ['admin.E408']

Expand Down Expand Up @@ -103,7 +103,7 @@
{
'BACKEND': 'post_office.template.backends.post_office.PostOfficeTemplates',
'APP_DIRS': True,
'DIRS': [os.path.join(BASE_DIR / 'celery_project' / 'templates')],
'DIRS': [os.path.join(BASE_DIR / 'demoapp' / 'templates')],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
Expand Down Expand Up @@ -145,12 +145,12 @@
'ses': 'django_ses.SESBackend'
},
'BASE_FILES': [
('/home/mykhailo/Desktop/emails/django-post_office/celery_project/templates/email/default.html', _('Default')),
('/home/mykhailo/Desktop/emails/django-post_office/demoapp/templates/email/default.html', _('Default')),
('email/placeholders.html', _('Placeholders')),
('/home/mykhailo/Desktop/out.html', _('Out')),
]
}
WSGI_APPLICATION = "celery_project.wsgi.application"
WSGI_APPLICATION = "demoapp.wsgi.application"

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions post_office/test_settings.py → demoapp/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for celery_project project.
Django settings for demoapp project.
Generated by 'django-admin startproject' using Django 3.0.5.
Expand Down Expand Up @@ -74,7 +74,7 @@
'django.middleware.csrf.CsrfViewMiddleware',
]

ROOT_URLCONF = 'celery_project.urls'
ROOT_URLCONF = 'demoapp.urls'

SILENCED_SYSTEM_CHECKS = ['admin.E408']

Expand All @@ -93,7 +93,7 @@
{
'BACKEND': 'post_office.template.backends.post_office.PostOfficeTemplates',
'APP_DIRS': True,
'DIRS': [os.path.join(BASE_DIR, 'celery_project/templates')],
'DIRS': [os.path.join(BASE_DIR, 'demoapp/templates')],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
Expand Down Expand Up @@ -126,10 +126,10 @@
'BACKENDS': {
'default': 'django.core.mail.backends.dummy.EmailBackend',
'locmem': 'django.core.mail.backends.locmem.EmailBackend',
'error': 'celery_project.tests.conftest.ErrorRaisingBackend',
'error': 'demoapp.tests.conftest.ErrorRaisingBackend',
'smtp': 'django.core.mail.backends.smtp.EmailBackend',
'connection_tester': 'post_office.tests.test_mail.ConnectionTestingBackend',
'slow_backend': 'celery_project.tests.conftest.SlowTestBackend',
'slow_backend': 'demoapp.tests.conftest.SlowTestBackend',
},
'TEMPLATE_ENGINE': 'post_office',
'CELERY_ENABLED': False,
Expand All @@ -139,7 +139,7 @@
'MESSAGE_ID_FQDN': 'example.com',
}

WSGI_APPLICATION = "celery_project.wsgi.application"
WSGI_APPLICATION = "demoapp.wsgi.application"

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,5 @@ def test_send_many(settings, cleanup_messages, template):

assert get_html_message_for_recipient('john@gmail.com', messages).count('#test_var#') == 0
assert get_html_message_for_recipient('marry@gmail.com', messages).count('#test_var#') == 0


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
def test_connections():
assert isinstance(connections['error'], ErrorRaisingBackend)
assert isinstance(connections['slow_backend'], SlowTestBackend)

with pytest.raises(KeyError):
conn = connections['not_valid']
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_get_message(settings, simple_email):
assert isinstance(email, EmailMessage)

html_with_inlines = (f"{{% load post_office %}}\n "
f"<img src='{{% inline_image '{settings.BASE_DIR / 'celery_project' / 'tests' / 'assets' / 'logo.png'}'%}}'"
f"<img src='{{% inline_image '{settings.BASE_DIR / 'demoapp' / 'tests' / 'assets' / 'logo.png'}'%}}'"
f"{simple_email.html_message}")
simple_email.html_message = html_with_inlines

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions celery_project/tests/test_tags.py → demoapp/tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_absolute_path(settings):
template._attached_images = []
context = Context({'dry_run': False})
context.template = template
path = str(settings.BASE_DIR / 'celery_project' / 'tests' / 'assets' / 'logo.png')
path = str(settings.BASE_DIR / 'demoapp' / 'tests' / 'assets' / 'logo.png')
print(path)
result = inline_image(context, path)
assert result.startswith('cid:')
Expand All @@ -45,7 +45,7 @@ def test_fileobj(settings):
template._attached_images = []
context = Context({'dry_run': False})
context.template = template
path = str(settings.BASE_DIR / 'celery_project' / 'tests' / 'assets' / 'logo.png')
path = str(settings.BASE_DIR / 'demoapp' / 'tests' / 'assets' / 'logo.png')
file = ImageFile(open(path, 'rb'))
result = inline_image(context, file)
assert result.startswith('cid:')
Expand All @@ -54,7 +54,7 @@ def test_fileobj(settings):


def test_media_urls(settings):
settings.MEDIA_ROOT = str(settings.BASE_DIR / 'celery_project' / 'tests' / 'assets')
settings.MEDIA_ROOT = str(settings.BASE_DIR / 'demoapp' / 'tests' / 'assets')
template = mock.Mock()
template._attached_images = []
context = Context({'dry_run': False})
Expand All @@ -72,13 +72,13 @@ def test_placeholders():


def test_static(settings):
settings.STATICFILES_DIRS = [str(settings.BASE_DIR / 'celery_project' / 'tests' / 'assets')]
settings.STATICFILES_DIRS = [str(settings.BASE_DIR / 'demoapp' / 'tests' / 'assets')]
template = mock.Mock()
template._attached_images = []
context = Context({'dry_run': False})
context.template = template
filename = 'logo.png'
abs_path = str(settings.BASE_DIR / 'celery_project' / 'tests' / 'assets' / filename)
abs_path = str(settings.BASE_DIR / 'demoapp' / 'tests' / 'assets' / filename)
result = inline_image(context, filename)
assert result.startswith('cid:')
assert len(template._attached_images) == 1
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def test_template():

@pytest.mark.django_db
def test_get_template(settings, test_template):
assert get_email_template('test_name', 'en') == test_template
assert get_email_template('test_name') == test_template
settings.POST_OFFICE_TEMPLATE_CACHE = False
assert get_email_template('test_name', 'en') == test_template
assert get_email_template('test_name') == test_template


@pytest.mark.django_db
Expand Down
2 changes: 1 addition & 1 deletion celery_project/urls.py → demoapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.urls import path, include
from celery_project import views
from demoapp import views
from django.conf import settings
from django.conf.urls.static import static

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion celery_project/wsgi.py → demoapp/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "celery_project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demoapp.settings")

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "celery_project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demoapp.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
2 changes: 1 addition & 1 deletion post_office/cache_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def get_placeholders(template, language=''):
"""
Function that returns an email template instance, from cache or DB.
"""
use_cache = getattr(settings, 'POST_OFFICE_CACHE', True)
use_cache = getattr(settings, 'POST_OFFICE_CACHE', False)
if use_cache:
use_cache = getattr(settings, 'POST_OFFICE_PLACEHOLDERS_CACHE', True)
if not use_cache:
Expand Down
2 changes: 1 addition & 1 deletion post_office/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def send(

# template can be an EmailMerge instance or name
if not isinstance(template, EmailMergeModel):
template = EmailMergeModel.objects.get(name=template)
template = get_email_template(template)

if backend and backend not in get_available_backends().keys():
raise ValueError('%s is not a valid backend alias' % backend)
Expand Down
3 changes: 1 addition & 2 deletions post_office/management/commands/send_queued_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def send_queued_mail_until_done(self):
try:
self.send_queued()
except Exception as e:
#self.stderr.write(e)
raise
self.stderr.write(str(e))


db_connection.close()
Expand Down
3 changes: 0 additions & 3 deletions post_office/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
"""

import datetime
import logging
import time

from django.utils.timezone import now

from post_office.mail import _send_bulk, get_queued
from post_office.utils import cleanup_expired_mails
from .dblock import db_lock, TimeoutException, LockedException
from django.db import connection as db_connection
from django.db import transaction

Expand Down
6 changes: 3 additions & 3 deletions post_office/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ def send_mail(
return emails


def get_email_template(name, language=''):
def get_email_template(name):
"""
Function that returns an email template instance, from cache or DB.
"""
use_cache = getattr(settings, 'POST_OFFICE_CACHE', True)
use_cache = getattr(settings, 'POST_OFFICE_CACHE', False)
if use_cache:
use_cache = getattr(settings, 'POST_OFFICE_TEMPLATE_CACHE', True)
if not use_cache:
return EmailMergeModel.objects.get(name=name)
else:
composite_name = '%s:%s' % (name, language)
composite_name = '%s' % name
email_template = cache.get(composite_name)

if email_template is None:
Expand Down
Empty file removed testapp/__init__.py
Empty file.
23 changes: 0 additions & 23 deletions testapp/manage.py

This file was deleted.

Empty file removed testapp/models.py
Empty file.
4 changes: 0 additions & 4 deletions testapp/pytest.ini

This file was deleted.

35 changes: 0 additions & 35 deletions testapp/requirements.txt

This file was deleted.

Loading

0 comments on commit c00186f

Please sign in to comment.