Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
refactor: give DatabaseManager some saner defaults
Browse files Browse the repository at this point in the history
(for tests)

Issue #956
  • Loading branch information
pjenvey committed Jul 20, 2017
1 parent 5b9bdb7 commit d5c9136
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from boto.dynamodb2.table import Table, Item
from boto.dynamodb2.types import NUMBER
from typing import ( # noqa
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand All @@ -78,6 +79,10 @@
WebPushNotification,
)

if TYPE_CHECKING: # pragma: nocover
from autopush.settings import AutopushSettings # noqa


# Typing
T = TypeVar('T') # noqa

Expand Down Expand Up @@ -863,13 +868,24 @@ class DatabaseManager(object):
metrics = attrib() # type: IMetrics

message_tables = attrib(default=Factory(dict)) # type: Dict[str, Message]
current_msg_month = attrib(default=None) # type: Optional[str]
current_month = attrib(default=None) # type: Optional[int]
current_msg_month = attrib(init=False) # type: Optional[str]
current_month = attrib(init=False) # type: Optional[int]

_message_prefix = attrib(default="message") # type: str

_message_prefix = attrib(default="message") # type: str
def __attrs_post_init__(self):
"""Initialize sane defaults"""
today = datetime.date.today()
self.current_month = today.month
self.current_msg_month = make_rotating_tablename(
self._message_prefix,
date=today
)

@classmethod
def from_settings(cls, settings):
def from_settings(cls, settings, **kwargs):
# type: (AutopushSettings, **Any) -> DatabaseManager
"""Create a DatabaseManager from the given settings"""
router_table = get_router_table(
settings.router_tablename,
settings.router_read_throughput,
Expand All @@ -890,7 +906,8 @@ def from_settings(cls, settings):
storage=Storage(storage_table, metrics),
router=Router(router_table, metrics),
message_prefix=settings.message_tablename,
metrics=metrics
metrics=metrics,
**kwargs
)

def setup(self, preflight_uaid):
Expand Down

0 comments on commit d5c9136

Please sign in to comment.