def test_email_url_value(self): value = EmailURLValue() self.assertEqual(value.default, {}) with env(EMAIL_URL='smtps://[email protected]:[email protected]:587'): self.assertEqual(value.setup('EMAIL_URL'), { 'EMAIL_BACKEND': 'django.core.mail.backends.smtp.EmailBackend', 'EMAIL_FILE_PATH': '', 'EMAIL_HOST': 'smtp.example.com', 'EMAIL_HOST_PASSWORD': '******', 'EMAIL_HOST_USER': '******', 'EMAIL_PORT': 587, 'EMAIL_USE_SSL': False, 'EMAIL_USE_TLS': True}) with env(EMAIL_URL='console://'): self.assertEqual(value.setup('EMAIL_URL'), { 'EMAIL_BACKEND': 'django.core.mail.backends.console.EmailBackend', 'EMAIL_FILE_PATH': '', 'EMAIL_HOST': None, 'EMAIL_HOST_PASSWORD': None, 'EMAIL_HOST_USER': None, 'EMAIL_PORT': None, 'EMAIL_USE_SSL': False, 'EMAIL_USE_TLS': False}) with env(EMAIL_URL='smtps://[email protected]:[email protected]:wrong'): self.assertRaises(ValueError, value.setup, 'TEST')
def test_email_url_value(self): value = EmailURLValue() self.assertEqual(value.default, {}) with env(EMAIL_URL= 'smtps://[email protected]:[email protected]:587'): self.assertEqual( value.setup('EMAIL_URL'), { 'EMAIL_BACKEND': 'django.core.mail.backends.smtp.EmailBackend', 'EMAIL_FILE_PATH': '', 'EMAIL_HOST': 'smtp.example.com', 'EMAIL_HOST_PASSWORD': '******', 'EMAIL_HOST_USER': '******', 'EMAIL_PORT': 587, 'EMAIL_USE_TLS': True }) with env(EMAIL_URL='console://'): self.assertEqual( value.setup('EMAIL_URL'), { 'EMAIL_BACKEND': 'django.core.mail.backends.console.EmailBackend', 'EMAIL_FILE_PATH': '', 'EMAIL_HOST': None, 'EMAIL_HOST_PASSWORD': None, 'EMAIL_HOST_USER': None, 'EMAIL_PORT': None, 'EMAIL_USE_TLS': False }) with env(EMAIL_URL= 'smtps://[email protected]:[email protected]:wrong'): self.assertRaises(ValueError, value.setup, 'TEST')
def test_email_url_value(self): value = EmailURLValue() self.assertEqual(value.default, {}) with env(EMAIL_URL="smtps://[email protected]:[email protected]:587"): self.assertEqual( value.setup("EMAIL_URL"), { "EMAIL_BACKEND": "django.core.mail.backends.smtp.EmailBackend", "EMAIL_FILE_PATH": "", "EMAIL_HOST": "smtp.example.com", "EMAIL_HOST_PASSWORD": "******", "EMAIL_HOST_USER": "******", "EMAIL_PORT": 587, "EMAIL_USE_TLS": True, }, ) with env(EMAIL_URL="console://"): self.assertEqual( value.setup("EMAIL_URL"), { "EMAIL_BACKEND": "django.core.mail.backends.console.EmailBackend", "EMAIL_FILE_PATH": "", "EMAIL_HOST": None, "EMAIL_HOST_PASSWORD": None, "EMAIL_HOST_USER": None, "EMAIL_PORT": None, "EMAIL_USE_TLS": False, }, ) with env(EMAIL_URL="smtps://[email protected]:[email protected]:wrong"): self.assertRaises(ValueError, value.setup, "TEST")
def test_setup_value(self): class Target(object): pass value = EmailURLValue() with env(EMAIL_URL= 'smtps://[email protected]:[email protected]:587'): setup_value(Target, 'EMAIL', value) self.assertEqual( Target.EMAIL, { 'EMAIL_BACKEND': 'django.core.mail.backends.smtp.EmailBackend', 'EMAIL_FILE_PATH': '', 'EMAIL_HOST': 'smtp.example.com', 'EMAIL_HOST_PASSWORD': '******', 'EMAIL_HOST_USER': '******', 'EMAIL_PORT': 587, 'EMAIL_USE_SSL': False, 'EMAIL_USE_TLS': True }) self.assertEqual(Target.EMAIL_BACKEND, 'django.core.mail.backends.smtp.EmailBackend') self.assertEqual(Target.EMAIL_FILE_PATH, '') self.assertEqual(Target.EMAIL_HOST, 'smtp.example.com') self.assertEqual(Target.EMAIL_HOST_PASSWORD, 'password') self.assertEqual(Target.EMAIL_HOST_USER, '*****@*****.**') self.assertEqual(Target.EMAIL_PORT, 587) self.assertEqual(Target.EMAIL_USE_TLS, True)