mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-07 07:00:49 +03:00
Delete api client example mini app
This commit is contained in:
parent
e1844a3040
commit
139e67dd95
|
@ -15,6 +15,7 @@ Develop
|
|||
- Refactor "factory of factories" pattern example.
|
||||
- Fix declarative container mypy stub to ``__init__`` to accept not only providers.
|
||||
- Refactor main module of the "decoupled packages" example.
|
||||
- Delete "api client" example mini app.
|
||||
|
||||
3.40.0
|
||||
------
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
"""API client module."""
|
||||
|
||||
|
||||
class ApiClient:
|
||||
"""Some API client."""
|
||||
|
||||
def __init__(self, host, api_key):
|
||||
"""Initialize instance."""
|
||||
self.host = host
|
||||
self.api_key = api_key
|
||||
|
||||
def call(self, operation, data):
|
||||
"""Make some network operations."""
|
||||
print('API call [{0}:{1}], method - {2}, data - {3}'.format(
|
||||
self.host, self.api_key, operation, repr(data)))
|
|
@ -1,36 +0,0 @@
|
|||
"""Main module."""
|
||||
|
||||
from dependency_injector import providers
|
||||
|
||||
import api
|
||||
import models
|
||||
|
||||
|
||||
# Creating ApiClient and User providers:
|
||||
api_client = providers.Singleton(api.ApiClient,
|
||||
host='production.com',
|
||||
api_key='PROD_API_KEY')
|
||||
user_factory = providers.Factory(models.User,
|
||||
api_client=api_client)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Creating several users and register them:
|
||||
user1 = user_factory(1)
|
||||
user1.register()
|
||||
# API call [production.com:PROD_API_KEY], method - register, data -
|
||||
# {'id': 1}
|
||||
|
||||
user2 = user_factory(2)
|
||||
user2.register()
|
||||
# API call [production.com:PROD_API_KEY], method - register, data -
|
||||
# {'id': 2}
|
||||
|
||||
# Overriding of ApiClient on dev environment:
|
||||
api_client.override(providers.Singleton(api.ApiClient,
|
||||
host='localhost',
|
||||
api_key='DEV_API_KEY'))
|
||||
|
||||
user3 = user_factory(3)
|
||||
user3.register()
|
||||
# API call [localhost:DEV_API_KEY], method - register, data - {'id': 3}
|
|
@ -1,14 +0,0 @@
|
|||
"""Models module."""
|
||||
|
||||
|
||||
class User:
|
||||
"""User model."""
|
||||
|
||||
def __init__(self, id, api_client):
|
||||
"""Initialize instance."""
|
||||
self.id = id
|
||||
self.api_client = api_client
|
||||
|
||||
def register(self):
|
||||
"""Register user."""
|
||||
self.api_client.call('register', {'id': self.id})
|
|
@ -1,12 +0,0 @@
|
|||
"""Tests module."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import main
|
||||
import api
|
||||
|
||||
# Mock ApiClient for testing:
|
||||
with main.api_client.override(Mock(api.ApiClient)) as api_client_mock:
|
||||
user = main.user_factory('test')
|
||||
user.register()
|
||||
api_client_mock().call.assert_called_with('register', {'id': 'test'})
|
Loading…
Reference in New Issue
Block a user