<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import unittest

import dj_email_url


class EmailTestSuite(unittest.TestCase):
    def test_smtp_parsing(self):
        url = 'smtps://<EMAIL>:<EMAIL>:587'
        url = dj_email_url.parse(url)

        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'] == '<EMAIL>'
        assert url['EMAIL_PORT'] == 587
        assert url['EMAIL_USE_TLS'] is True

    def test_email_url(self):
        a = dj_email_url.config()
        assert not a

        os.environ['EMAIL_URL'] = \
            'smtps://<EMAIL>:password@smtp.example.com:587'

        url = dj_email_url.config()

        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'] == '<EMAIL>'
        assert url['EMAIL_PORT'] == 587
        assert url['EMAIL_USE_TLS'] is True


if __name__ == '__main__':
    unittest.main()
<commit_msg>Add test for ssl and tls query params<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import unittest

import dj_email_url


class EmailTestSuite(unittest.TestCase):
    def test_smtp_parsing(self):
        url = 'smtps://user@domain.com:password@smtp.example.com:587'
        url = dj_email_url.parse(url)

        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'] == '<EMAIL>'
        assert url['EMAIL_PORT'] == 587
        assert url['EMAIL_USE_TLS'] is True

    def test_email_url(self):
        a = dj_email_url.config()
        assert not a

        os.environ['EMAIL_URL'] = \
            'smtps://<EMAIL>:<EMAIL>:587'

        url = dj_email_url.config()

        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'] == '<EMAIL>'
        assert url['EMAIL_PORT'] == 587
        assert url['EMAIL_USE_TLS'] is True

    def test_smtp_backend_with_ssl(self):
        url = 'smtp://user@<EMAIL>.<EMAIL>:pass@smtp.example.com:465/?ssl=True'
        url = dj_email_url.parse(url)
        assert url['EMAIL_USE_SSL'] is True
        assert url['EMAIL_USE_TLS'] is False

    def test_smtp_backend_with_tls(self):
        url = 'smtp://<EMAIL>@<EMAIL>:pass@smtp.example.com:587/?tls=True'
        url = dj_email_url.parse(url)
        assert url['EMAIL_USE_SSL'] is False
        assert url['EMAIL_USE_TLS'] is True


if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.14399733954107083, 'fraction_numerical': 0.010641835716661123, 'mean_word_length': 2.788413098236776, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7280106', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1034, 'n_words': 177}