From a55ec1d1d05d6e75b930f4b0975024ba08df36a1 Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Mon, 28 Sep 2020 14:20:22 -0700 Subject: [PATCH] Expose adapter classes directly under adapters module --- src/protean/__init__.py | 13 +------- src/protean/adapters/__init__.py | 30 ++++++++++++++++++- src/protean/adapters/broker/celery.py | 2 +- src/protean/adapters/email/__init__.py | 4 +-- src/protean/domain/__init__.py | 20 +++++-------- tests/adapters/broker/celery_broker/config.py | 4 +-- .../broker/celery_broker/test_subscriber.py | 2 +- tests/adapters/broker/celery_broker/tests.py | 2 +- tests/adapters/email/sendgrid_email/config.py | 4 +-- tests/adapters/email/sendgrid_email/tests.py | 2 +- .../model/elasticsearch_model/config.py | 2 +- .../model/elasticsearch_model/elements.py | 2 +- .../model/elasticsearch_model/tests.py | 2 +- .../repository/elasticsearch_repo/config.py | 2 +- .../elasticsearch_repo/test_provider.py | 3 +- tests/config.py | 6 ++-- tests/configuration/tests.py | 6 ++-- tests/email_provider/tests.py | 2 +- tests/identity/config_int.py | 2 +- tests/identity/config_string.py | 2 +- tests/identity/config_uuid.py | 2 +- 21 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/protean/__init__.py b/src/protean/__init__.py index 2b67cca7..5108bc30 100644 --- a/src/protean/__init__.py +++ b/src/protean/__init__.py @@ -5,15 +5,4 @@ # Local/Relative Imports from .domain import Domain -# Adapters -from .adapters.broker.celery import CeleryBroker, ProteanTask -from .adapters.broker.inline import InlineBroker -from .adapters.email.sendgrid import SendgridEmailProvider - -__all__ = ( - "Domain", - "CeleryBroker", - "ProteanTask", - "InlineBroker", - "SendgridEmailProvider", -) +__all__ = ("Domain",) diff --git a/src/protean/adapters/__init__.py b/src/protean/adapters/__init__.py index c0f5e1b2..ae6671d6 100644 --- a/src/protean/adapters/__init__.py +++ b/src/protean/adapters/__init__.py @@ -1 +1,29 @@ -"""Package for defining concrete implementations of Protean""" +# Adapters +from protean.adapters.broker import Brokers +from protean.adapters.broker.celery import CeleryBroker, ProteanTask +from protean.adapters.broker.inline import InlineBroker +from protean.adapters.email import EmailProviders +from protean.adapters.email.dummy import DummyEmailProvider +from protean.adapters.email.sendgrid import SendgridEmailProvider +from protean.adapters.repository import Providers +from protean.adapters.repository.elasticsearch import ESProvider, ElasticsearchModel +from protean.adapters.repository.sqlalchemy import SAProvider, SqlalchemyModel +from protean.adapters.repository.memory import MemoryProvider, MemoryModel + + +__all__ = ( + "Brokers", + "CeleryBroker", + "ProteanTask", + "InlineBroker", + "EmailProviders", + "DummyEmailProvider", + "SendgridEmailProvider", + "Providers", + "ESProvider", + "ElasticsearchModel", + "SAProvider", + "SqlalchemyModel", + "MemoryProvider", + "MemoryModel", +) diff --git a/src/protean/adapters/broker/celery.py b/src/protean/adapters/broker/celery.py index 81e3e9a0..6709f2d6 100644 --- a/src/protean/adapters/broker/celery.py +++ b/src/protean/adapters/broker/celery.py @@ -13,7 +13,7 @@ from protean.utils import fully_qualified_name from protean.utils.inflection import underscore -logger = logging.getLogger("protean.adapters.broker.celery") +logger = logging.getLogger("protean.adapters.celery") class ProteanTask(Task): diff --git a/src/protean/adapters/email/__init__.py b/src/protean/adapters/email/__init__.py index 4be13688..be73c134 100644 --- a/src/protean/adapters/email/__init__.py +++ b/src/protean/adapters/email/__init__.py @@ -4,10 +4,10 @@ from protean.core.exceptions import ConfigurationError from protean.globals import current_uow -logger = logging.getLogger("protean.emails") +logger = logging.getLogger("protean.email_providers") -class Emails: +class EmailProviders: def __init__(self, domain): self.domain = domain self._email_providers = None diff --git a/src/protean/domain/__init__.py b/src/protean/domain/__init__.py index fe135a0e..c4948d8b 100644 --- a/src/protean/domain/__init__.py +++ b/src/protean/domain/__init__.py @@ -11,9 +11,7 @@ ObjectNotFoundError, ) from protean.domain.registry import _DomainRegistry -from protean.adapters.broker import Brokers -from protean.adapters.email import Emails -from protean.adapters.repository import Providers +from protean.adapters import Brokers, EmailProviders, Providers from protean.utils import fully_qualified_name, DomainObjects from werkzeug.datastructures import ImmutableDict @@ -87,15 +85,11 @@ class Domain(_PackageBoundObject): "AUTOLOAD_DOMAIN": True, "IDENTITY_STRATEGY": IdentityStrategy.UUID, "IDENTITY_TYPE": IdentityType.STRING, - "DATABASES": { - "default": { - "PROVIDER": "protean.adapters.repository.memory.MemoryProvider", - }, - }, - "BROKERS": {"default": {"PROVIDER": "protean.InlineBroker",},}, + "DATABASES": {"default": {"PROVIDER": "protean.adapters.MemoryProvider",},}, + "BROKERS": {"default": {"PROVIDER": "protean.adapters.InlineBroker",},}, "EMAIL_PROVIDERS": { "default": { - "PROVIDER": "protean.adapters.email.dummy.DummyEmailProvider", + "PROVIDER": "protean.adapters.DummyEmailProvider", "DEFAULT_FROM_EMAIL": "admin@team8solutions.com", }, }, @@ -123,7 +117,7 @@ def __init__( self.providers = Providers(self) self.brokers = Brokers(self) - self.emails = Emails(self) + self.email_providers = EmailProviders(self) # Cache for holding Model to Entity/Aggregate associations self._models = {} @@ -511,7 +505,7 @@ def get_dao(self, aggregate_cls): ####################### def get_email_provider(self, provider_name): - return self.emails.get_email_provider(provider_name) + return self.email_providers.get_email_provider(provider_name) def send_email(self, email): - return self.emails.send_email(email) + return self.email_providers.send_email(email) diff --git a/tests/adapters/broker/celery_broker/config.py b/tests/adapters/broker/celery_broker/config.py index 8489dd17..b825ed85 100644 --- a/tests/adapters/broker/celery_broker/config.py +++ b/tests/adapters/broker/celery_broker/config.py @@ -11,7 +11,7 @@ # Database Configuration DATABASES = { - "default": {"PROVIDER": "protean.adapters.repository.memory.MemoryProvider"}, + "default": {"PROVIDER": "protean.adapters.MemoryProvider"}, "sqlite": { "PROVIDER": "protean.adapters.repository.sqlalchemy.SAProvider", "DATABASE": Database.SQLITE.value, @@ -40,7 +40,7 @@ # Messaging Mediums BROKERS = { "default": { - "PROVIDER": "protean.CeleryBroker", + "PROVIDER": "protean.adapters.CeleryBroker", "URI": "redis://127.0.0.1:6379/2", "IS_ASYNC": True, }, diff --git a/tests/adapters/broker/celery_broker/test_subscriber.py b/tests/adapters/broker/celery_broker/test_subscriber.py index e65faa8b..2ccc7371 100644 --- a/tests/adapters/broker/celery_broker/test_subscriber.py +++ b/tests/adapters/broker/celery_broker/test_subscriber.py @@ -3,7 +3,7 @@ from celery import Task from protean.globals import current_domain -from protean import CeleryBroker, ProteanTask +from protean.adapters import CeleryBroker, ProteanTask from tests.adapters.broker.celery_broker.elements import NotifySSOSubscriber, Person diff --git a/tests/adapters/broker/celery_broker/tests.py b/tests/adapters/broker/celery_broker/tests.py index 36ce9123..deeda89c 100644 --- a/tests/adapters/broker/celery_broker/tests.py +++ b/tests/adapters/broker/celery_broker/tests.py @@ -3,7 +3,7 @@ from mock import patch from protean.globals import current_domain -from protean import CeleryBroker +from protean.adapters import CeleryBroker from tests.adapters.broker.celery_broker.elements import ( NotifySSOSubscriber, Person, diff --git a/tests/adapters/email/sendgrid_email/config.py b/tests/adapters/email/sendgrid_email/config.py index 505d6c54..400ba338 100644 --- a/tests/adapters/email/sendgrid_email/config.py +++ b/tests/adapters/email/sendgrid_email/config.py @@ -13,7 +13,7 @@ # Database Configuration DATABASES = { - "default": {"PROVIDER": "protean.adapters.repository.memory.MemoryProvider"}, + "default": {"PROVIDER": "protean.adapters.MemoryProvider"}, } # Identity strategy to use when persisting Entities/Aggregates. @@ -36,7 +36,7 @@ # Messaging Mediums BROKERS = { - "default": {"PROVIDER": "protean.InlineBroker"}, + "default": {"PROVIDER": "protean.adapters.InlineBroker"}, } EMAIL_PROVIDERS = { diff --git a/tests/adapters/email/sendgrid_email/tests.py b/tests/adapters/email/sendgrid_email/tests.py index bca939d4..00a22a84 100644 --- a/tests/adapters/email/sendgrid_email/tests.py +++ b/tests/adapters/email/sendgrid_email/tests.py @@ -2,7 +2,7 @@ import pytest from mock import patch -from protean import SendgridEmailProvider +from protean.adapters import SendgridEmailProvider # Local/Relative Imports from .elements import Person, PersonAdded, WelcomeEmail, WelcomeNewPerson diff --git a/tests/adapters/model/elasticsearch_model/config.py b/tests/adapters/model/elasticsearch_model/config.py index b251382f..87552421 100644 --- a/tests/adapters/model/elasticsearch_model/config.py +++ b/tests/adapters/model/elasticsearch_model/config.py @@ -21,7 +21,7 @@ # Define the databases DATABASES = { "default": { - "PROVIDER": "protean.adapters.repository.elasticsearch.ESProvider", + "PROVIDER": "protean.adapters.ESProvider", "DATABASE": Database.ELASTICSEARCH.value, "DATABASE_URI": {"hosts": ["localhost"]}, }, diff --git a/tests/adapters/model/elasticsearch_model/elements.py b/tests/adapters/model/elasticsearch_model/elements.py index 5b822e97..593acf6e 100644 --- a/tests/adapters/model/elasticsearch_model/elements.py +++ b/tests/adapters/model/elasticsearch_model/elements.py @@ -11,7 +11,7 @@ from protean.core.field.basic import Text as ProteanText from protean.core.field.embedded import ValueObjectField from protean.core.value_object import BaseValueObject -from protean.adapters.repository.elasticsearch import ElasticsearchModel +from protean.adapters import ElasticsearchModel class Person(BaseAggregate): diff --git a/tests/adapters/model/elasticsearch_model/tests.py b/tests/adapters/model/elasticsearch_model/tests.py index 266f4070..fded925e 100644 --- a/tests/adapters/model/elasticsearch_model/tests.py +++ b/tests/adapters/model/elasticsearch_model/tests.py @@ -1,7 +1,7 @@ # Protean import pytest -from protean.adapters.repository.elasticsearch import ElasticsearchModel +from protean.adapters import ElasticsearchModel # Local/Relative Imports from .elements import ( diff --git a/tests/adapters/repository/elasticsearch_repo/config.py b/tests/adapters/repository/elasticsearch_repo/config.py index b251382f..87552421 100644 --- a/tests/adapters/repository/elasticsearch_repo/config.py +++ b/tests/adapters/repository/elasticsearch_repo/config.py @@ -21,7 +21,7 @@ # Define the databases DATABASES = { "default": { - "PROVIDER": "protean.adapters.repository.elasticsearch.ESProvider", + "PROVIDER": "protean.adapters.ESProvider", "DATABASE": Database.ELASTICSEARCH.value, "DATABASE_URI": {"hosts": ["localhost"]}, }, diff --git a/tests/adapters/repository/elasticsearch_repo/test_provider.py b/tests/adapters/repository/elasticsearch_repo/test_provider.py index 703c6704..1f02e1cb 100644 --- a/tests/adapters/repository/elasticsearch_repo/test_provider.py +++ b/tests/adapters/repository/elasticsearch_repo/test_provider.py @@ -4,8 +4,7 @@ from elasticsearch import Elasticsearch from elasticsearch_dsl.response import Response -from protean.adapters.repository import Providers -from protean.adapters.repository.elasticsearch import ESProvider +from protean.adapters import Providers, ESProvider # Local/Relative Imports from .elements import Alien, Person diff --git a/tests/config.py b/tests/config.py index 26ad0c49..0bd43536 100644 --- a/tests/config.py +++ b/tests/config.py @@ -12,7 +12,7 @@ # Database Configuration DATABASES = { - "default": {"PROVIDER": "protean.adapters.repository.memory.MemoryProvider"}, + "default": {"PROVIDER": "protean.adapters.MemoryProvider"}, "sqlite": { "PROVIDER": "protean.adapters.repository.sqlalchemy.SAProvider", "DATABASE": Database.SQLITE.value, @@ -40,12 +40,12 @@ # Messaging Mediums BROKERS = { - "default": {"PROVIDER": "protean.InlineBroker"}, + "default": {"PROVIDER": "protean.adapters.InlineBroker"}, } EMAIL_PROVIDERS = { "default": { - "PROVIDER": "protean.adapters.email.dummy.DummyEmailProvider", + "PROVIDER": "protean.adapters.DummyEmailProvider", "DEFAULT_FROM_EMAIL": "admin@team8solutions.com", }, } diff --git a/tests/configuration/tests.py b/tests/configuration/tests.py index a7185855..99c915bd 100644 --- a/tests/configuration/tests.py +++ b/tests/configuration/tests.py @@ -38,9 +38,9 @@ def test_config_repr(self): "'AUTOLOAD_DOMAIN': True, " "'IDENTITY_STRATEGY': , " "'IDENTITY_TYPE': , " - "'DATABASES': {'default': {'PROVIDER': 'protean.adapters.repository.memory.MemoryProvider'}}, " - "'BROKERS': {'default': {'PROVIDER': 'protean.InlineBroker'}}, " - "'EMAIL_PROVIDERS': {'default': {'PROVIDER': 'protean.adapters.email.dummy.DummyEmailProvider', " + "'DATABASES': {'default': {'PROVIDER': 'protean.adapters.MemoryProvider'}}, " + "'BROKERS': {'default': {'PROVIDER': 'protean.adapters.InlineBroker'}}, " + "'EMAIL_PROVIDERS': {'default': {'PROVIDER': 'protean.adapters.DummyEmailProvider', " "'DEFAULT_FROM_EMAIL': 'admin@team8solutions.com'}}, " "'AGGREGATE_CHILDREN_LIMIT': 100, " "'TEST_KEY': 'foo'}>" diff --git a/tests/email_provider/tests.py b/tests/email_provider/tests.py index 724de3bc..148b6c63 100644 --- a/tests/email_provider/tests.py +++ b/tests/email_provider/tests.py @@ -3,7 +3,7 @@ from mock import patch from protean.core.email import BaseEmail -from protean.adapters.email.dummy import DummyEmailProvider +from protean.adapters import DummyEmailProvider from protean.utils import fully_qualified_name # Local/Relative Imports diff --git a/tests/identity/config_int.py b/tests/identity/config_int.py index fed5773a..2aeedb33 100644 --- a/tests/identity/config_int.py +++ b/tests/identity/config_int.py @@ -23,5 +23,5 @@ # Messaging Mediums BROKERS = { - "default": {"PROVIDER": "protean.InlineBroker"}, + "default": {"PROVIDER": "protean.adapters.InlineBroker"}, } diff --git a/tests/identity/config_string.py b/tests/identity/config_string.py index ba1fc790..2bc2bd0d 100644 --- a/tests/identity/config_string.py +++ b/tests/identity/config_string.py @@ -25,5 +25,5 @@ # Messaging Mediums BROKERS = { - "default": {"PROVIDER": "protean.InlineBroker"}, + "default": {"PROVIDER": "protean.adapters.InlineBroker"}, } diff --git a/tests/identity/config_uuid.py b/tests/identity/config_uuid.py index 8d469b9d..7a756d80 100644 --- a/tests/identity/config_uuid.py +++ b/tests/identity/config_uuid.py @@ -25,5 +25,5 @@ # Messaging Mediums BROKERS = { - "default": {"PROVIDER": "protean.InlineBroker"}, + "default": {"PROVIDER": "protean.adapters.InlineBroker"}, }