Delete mail service example mini app

This commit is contained in:
Roman Mogylatov 2020-09-07 22:04:50 -04:00
parent 139e67dd95
commit 039e51d4ba
3 changed files with 1 additions and 80 deletions

View File

@ -16,6 +16,7 @@ Develop
- Fix declarative container mypy stub to ``__init__`` to accept not only providers. - Fix declarative container mypy stub to ``__init__`` to accept not only providers.
- Refactor main module of the "decoupled packages" example. - Refactor main module of the "decoupled packages" example.
- Delete "api client" example mini app. - Delete "api client" example mini app.
- Delete "mail service" example mini app.
3.40.0 3.40.0
------ ------

View File

@ -1,41 +0,0 @@
"""Mail service and user registration DI container example."""
from dependency_injector.containers import DeclarativeContainer
from dependency_injector.providers import Callable, Singleton
import example
class Container(DeclarativeContainer):
"""DI container."""
mail_service = Singleton(example.MailService,
host='localhost',
port=587,
login='my_login',
password='super_secret_password')
add_user = Callable(example.add_user,
mailer=mail_service)
if __name__ == '__main__':
print('Using real mail service:')
Container.add_user('sample@mail.com', 'password')
# Using real mail service:
# Connecting server localhost:587 with my_login:super_secret_password
# Sending "Your password is password" to "sample@mail.com"
print('Using mail service stub:')
Container.add_user('sample@mail.com', 'password',
mailer=example.MailServiceStub())
# Using mail service stub:
# Emulating sending "Your password is password" to "sample@mail.com"
# Also you can override provider by another provider:
Container.mail_service.override(Singleton(example.MailServiceStub))
print('Using mail service stub by overriding mail service provider:')
Container.add_user('sample@mail.com', 'password')
# Using mail service stub by overriding mail service provider:
# Emulating sending "Your password is password" to "sample@mail.com"
Container.mail_service.reset_override() # Resetting provider overriding

View File

@ -1,39 +0,0 @@
"""Mail service and user registration example."""
class AbstractMailService:
"""Abstract mail service."""
def send(self, email, body):
"""Send email."""
raise NotImplementedError()
class MailService(AbstractMailService):
"""Mail service."""
def __init__(self, host, port, login, password):
"""Initialize instance."""
self._host = host
self._port = port
self._login = login
self._password = password
def send(self, email, body):
"""Send email."""
print('Connecting server {0}:{1} with {2}:{3}'.format(
self._host, self._port, self._login, self._password))
print('Sending "{0}" to "{1}"'.format(body, email))
class MailServiceStub(AbstractMailService):
"""Mail service stub."""
def send(self, email, body):
"""Send email."""
print('Emulating sending "{0}" to "{1}"'.format(body, email))
def add_user(email, password, mailer):
"""Register user."""
mailer.send(email, 'Your password is {0}'.format(password))