get some tests working
This commit is contained in:
12
apps/cic-eth/cic_eth/pytest/helpers/accounts.py
Normal file
12
apps/cic-eth/cic_eth/pytest/helpers/accounts.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# standard imports
|
||||
import os
|
||||
import random
|
||||
import uuid
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def blockchain_address() -> str:
|
||||
return os.urandom(20).hex().lower()
|
||||
|
||||
0
apps/cic-eth/cic_eth/pytest/patches/__init__.py
Normal file
0
apps/cic-eth/cic_eth/pytest/patches/__init__.py
Normal file
132
apps/cic-eth/cic_eth/pytest/patches/account.py
Normal file
132
apps/cic-eth/cic_eth/pytest/patches/account.py
Normal file
@@ -0,0 +1,132 @@
|
||||
# standard imports
|
||||
import os
|
||||
|
||||
# external imports
|
||||
import pytest
|
||||
from celery import uuid
|
||||
# test imports
|
||||
from cic_eth.pytest.helpers.accounts import blockchain_address
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def task_uuid():
|
||||
return uuid()
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def default_token_data(foo_token_symbol, foo_token):
|
||||
return {
|
||||
'symbol': foo_token_symbol,
|
||||
'address': foo_token,
|
||||
'name': 'Giftable Token',
|
||||
'decimals': 6,
|
||||
"converters": []
|
||||
}
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_account_creation_task_request(mocker, task_uuid):
|
||||
def mock_request(self):
|
||||
mocked_task_request = mocker.patch('celery.app.task.Task.request')
|
||||
mocked_task_request.id = task_uuid
|
||||
return mocked_task_request
|
||||
mocker.patch('cic_eth.api.api_task.Api.create_account', mock_request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_account_creation_task_result(mocker, task_uuid):
|
||||
def task_result(self):
|
||||
sync_res = mocker.patch('celery.result.AsyncResult')
|
||||
sync_res.id = task_uuid
|
||||
sync_res.get.return_value = blockchain_address()
|
||||
return sync_res
|
||||
mocker.patch('cic_eth.api.api_task.Api.create_account', task_result)
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_token_api_query(foo_token_symbol, foo_token, mocker, task_uuid):
|
||||
def mock_query(self, token_symbol, proof=None):
|
||||
sync_res = mocker.patch('celery.result.AsyncResult')
|
||||
sync_res.id = task_uuid
|
||||
sync_res.get.return_value = [
|
||||
{
|
||||
'address': foo_token,
|
||||
'converters': [],
|
||||
'decimals': 6,
|
||||
'name': 'Giftable Token',
|
||||
'proofs': ['5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3'],
|
||||
'symbol': foo_token_symbol,
|
||||
},{'5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C','Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}
|
||||
]
|
||||
return sync_res
|
||||
mocker.patch('cic_eth.api.api_task.Api.token', mock_query)
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_tokens_api_query(foo_token_symbol, foo_token, mocker, task_uuid):
|
||||
def mock_query(self, token_symbol, proof=None):
|
||||
sync_res = mocker.patch('celery.result.AsyncResult')
|
||||
sync_res.id = task_uuid
|
||||
sync_res.get.return_value = [[
|
||||
{
|
||||
'address': foo_token,
|
||||
'converters': [],
|
||||
'decimals': 6,
|
||||
'name': 'Giftable Token',
|
||||
'proofs': ['5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3'],
|
||||
'symbol': foo_token_symbol,
|
||||
},{'5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C','Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}
|
||||
], [
|
||||
{
|
||||
'address': foo_token,
|
||||
'converters': [],
|
||||
'decimals': 6,
|
||||
'name': 'Giftable Token',
|
||||
'proofs': ['5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3'],
|
||||
'symbol': foo_token_symbol,
|
||||
},{'5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C','Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}
|
||||
]]
|
||||
return sync_res
|
||||
mocker.patch('cic_eth.api.api_task.Api.tokens', mock_query)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_sync_balance_api_query(balances, mocker, task_uuid):
|
||||
def sync_api_query(self, address: str, token_symbol: str):
|
||||
sync_res = mocker.patch('celery.result.AsyncResult')
|
||||
sync_res.id = task_uuid
|
||||
sync_res.get.return_value = balances
|
||||
return sync_res
|
||||
mocker.patch('cic_eth.api.api_task.Api.balance', sync_api_query)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_sync_default_token_api_query(default_token_data, mocker, task_uuid):
|
||||
def mock_query(self):
|
||||
sync_res = mocker.patch('celery.result.AsyncResult')
|
||||
sync_res.id = task_uuid
|
||||
sync_res.get.return_value = default_token_data
|
||||
return sync_res
|
||||
mocker.patch('cic_eth.api.api_task.Api.default_token', mock_query)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_transaction_list_query(mocker):
|
||||
query_args = {}
|
||||
|
||||
def mock_query(self, address: str, limit: int):
|
||||
query_args['address'] = address
|
||||
query_args['limit'] = limit
|
||||
|
||||
mocker.patch('cic_eth.api.api_task.Api.list', mock_query)
|
||||
return query_args
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_transfer_api(mocker):
|
||||
transfer_args = {}
|
||||
|
||||
def mock_transfer(self, from_address: str, to_address: str, value: int, token_symbol: str):
|
||||
transfer_args['from_address'] = from_address
|
||||
transfer_args['to_address'] = to_address
|
||||
transfer_args['value'] = value
|
||||
transfer_args['token_symbol'] = token_symbol
|
||||
|
||||
mocker.patch('cic_eth.api.api_task.Api.transfer', mock_transfer)
|
||||
return transfer_args
|
||||
Reference in New Issue
Block a user