2017-12-25 17:47:58 +03:00
|
|
|
"""Run 'Bundles' example application."""
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
import boto3
|
2017-12-20 13:25:46 +03:00
|
|
|
|
2017-12-25 00:03:13 +03:00
|
|
|
from dependency_injector import containers
|
2017-12-21 23:58:13 +03:00
|
|
|
from dependency_injector import providers
|
2017-12-20 13:25:46 +03:00
|
|
|
|
2017-12-21 23:06:00 +03:00
|
|
|
from bundles.users import Users
|
|
|
|
from bundles.photos import Photos
|
2017-12-20 13:25:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Core(containers.DeclarativeContainer):
|
|
|
|
"""Core container."""
|
|
|
|
|
2017-12-25 17:47:58 +03:00
|
|
|
config = providers.Configuration('config')
|
|
|
|
sqlite = providers.Singleton(sqlite3.connect, config.database.dsn)
|
|
|
|
s3 = providers.Singleton(
|
|
|
|
boto3.client, 's3',
|
|
|
|
aws_access_key_id=config.aws.access_key_id,
|
|
|
|
aws_secret_access_key=config.aws.secret_access_key)
|
2017-12-20 13:25:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Initializing containers
|
2018-01-24 20:58:34 +03:00
|
|
|
core = Core(config={'database': {'dsn': ':memory:'},
|
2017-12-25 17:47:58 +03:00
|
|
|
'aws': {'access_key_id': 'KEY',
|
|
|
|
'secret_access_key': 'SECRET'}})
|
|
|
|
users = Users(database=core.sqlite)
|
|
|
|
photos = Photos(database=core.sqlite, file_storage=core.s3)
|
2017-12-20 13:25:46 +03:00
|
|
|
|
|
|
|
# Fetching few users
|
|
|
|
user_repository = users.user_repository()
|
|
|
|
user1 = user_repository.get(id=1)
|
|
|
|
user2 = user_repository.get(id=2)
|
|
|
|
|
|
|
|
# Making some checks
|
|
|
|
assert user1.id == 1
|
|
|
|
assert user2.id == 2
|
2017-12-25 17:47:58 +03:00
|
|
|
assert user_repository.db is core.sqlite()
|