Skip to content

Commit

Permalink
Expose adapter classes directly under adapters module
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Sep 28, 2020
1 parent fe96bdf commit a55ec1d
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 52 deletions.
13 changes: 1 addition & 12 deletions src/protean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)
30 changes: 29 additions & 1 deletion src/protean/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
)
2 changes: 1 addition & 1 deletion src/protean/adapters/broker/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/protean/adapters/email/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions src/protean/domain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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": "[email protected]",
},
},
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests/adapters/broker/celery_broker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/broker/celery_broker/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/broker/celery_broker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/adapters/email/sendgrid_email/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,7 +36,7 @@

# Messaging Mediums
BROKERS = {
"default": {"PROVIDER": "protean.InlineBroker"},
"default": {"PROVIDER": "protean.adapters.InlineBroker"},
}

EMAIL_PROVIDERS = {
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/email/sendgrid_email/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/model/elasticsearch_model/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/model/elasticsearch_model/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/model/elasticsearch_model/tests.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/repository/elasticsearch_repo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": "[email protected]",
},
}
6 changes: 3 additions & 3 deletions tests/configuration/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_config_repr(self):
"'AUTOLOAD_DOMAIN': True, "
"'IDENTITY_STRATEGY': <IdentityStrategy.UUID: 1>, "
"'IDENTITY_TYPE': <IdentityType.STRING: 'STRING'>, "
"'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': '[email protected]'}}, "
"'AGGREGATE_CHILDREN_LIMIT': 100, "
"'TEST_KEY': 'foo'}>"
Expand Down
2 changes: 1 addition & 1 deletion tests/email_provider/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/identity/config_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

# Messaging Mediums
BROKERS = {
"default": {"PROVIDER": "protean.InlineBroker"},
"default": {"PROVIDER": "protean.adapters.InlineBroker"},
}
2 changes: 1 addition & 1 deletion tests/identity/config_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

# Messaging Mediums
BROKERS = {
"default": {"PROVIDER": "protean.InlineBroker"},
"default": {"PROVIDER": "protean.adapters.InlineBroker"},
}
2 changes: 1 addition & 1 deletion tests/identity/config_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

# Messaging Mediums
BROKERS = {
"default": {"PROVIDER": "protean.InlineBroker"},
"default": {"PROVIDER": "protean.adapters.InlineBroker"},
}

0 comments on commit a55ec1d

Please sign in to comment.