File: test_email.py

package info (click to toggle)
django-environ 0.12.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: python: 2,434; makefile: 171
file content (34 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# This file is part of the django-environ.
#
# Copyright (c) 2021-2024, Serghei Iakovlev <oss@serghei.pl>
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
#
# For the full copyright and license information, please view
# the LICENSE.txt file that was distributed with this source code.

from environ import Env


def test_smtp_parsing():
    url = 'smtps://user@domain.com:password@smtp.example.com:587'
    url = Env.email_url_config(url)

    assert len(url) == 7

    assert url['EMAIL_BACKEND'] == 'django.core.mail.backends.smtp.EmailBackend'
    assert url['EMAIL_HOST'] == 'smtp.example.com'
    assert url['EMAIL_HOST_PASSWORD'] == 'password'
    assert url['EMAIL_HOST_USER'] == 'user@domain.com'
    assert url['EMAIL_PORT'] == 587
    assert url['EMAIL_USE_TLS'] is True
    assert url['EMAIL_FILE_PATH'] == ''


def test_custom_email_backend():
    """Override EMAIL_BACKEND determined from schema."""
    url = 'smtps://user@domain.com:password@smtp.example.com:587'

    backend = 'mypackage.backends.whatever'
    url = Env.email_url_config(url, backend=backend)

    assert url['EMAIL_BACKEND'] == backend