switch to fastapi :-/

This commit is contained in:
2021-12-21 21:15:45 +03:00
parent 97aabdb460
commit cbc1b449ba
17 changed files with 308 additions and 711 deletions

View File

@@ -5,28 +5,66 @@ import logging
import time
import hexathon
import pytest
import requests
from cic_eth.runnable.daemons.server import application
from pytest_localserver.http import WSGIServer
from cic_eth.runnable.daemons.server import app
from fastapi.testclient import TestClient
log = logging.getLogger(__name__)
@pytest.fixture
def testserver(request):
"""Defines the testserver funcarg"""
server = WSGIServer(application=application)
server.start()
request.addfinalizer(server.stop)
return server
client = TestClient(app)
def test_account(testserver):
def test_default_token():
# Default Token
response = requests.get(
testserver.url + '/default_token',
)
response = client.get('/default_token')
log.debug(f"balance response {response}")
default_token = response.json()
assert default_token == {
'address': '3FF776B6f888980DEf9d4220858803f9dC5e341e',
'decimals': 6,
'name': 'Giftable Token',
'symbol': 'GFT',
}
def test_token():
# Default Token
response = client.get('/token?token_symbol=GFT')
log.debug(f"token response {response}")
token = response.json()
assert token == {
'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
'converters': [],
'decimals': 6,
'name': 'Giftable Token',
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
'symbol': 'GFT',
}
def test_tokens():
# Default Token
response = client.get('/tokens', params={'token_symbols': ['GFT', 'COFE']})
log.debug(f"tokens response {response}")
tokens = response.json()
assert tokens == {
'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
'converters': [],
'decimals': 6,
'name': 'Giftable Token',
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
'symbol': 'GFT',
}
def test_account():
# Default Token
response = client.get('/default_token',
)
log.debug(f"balance response {response}")
default_token = response.json()
@@ -35,8 +73,8 @@ def test_account(testserver):
'password': '',
'register': True
}
response = requests.post(
testserver.url + '/create_account',
response = client.post(
'/create_account',
params=params)
address_1 = hexathon.valid(response.json())
@@ -45,9 +83,8 @@ def test_account(testserver):
'password': '',
'register': True
}
response = requests.post(
testserver.url + '/create_account',
params=params)
response = client.post('/create_account',
params=params)
address_2 = hexathon.valid(response.json())
time.sleep(30) # Required to allow balance to show
@@ -57,9 +94,8 @@ def test_account(testserver):
'token_symbol': 'COFE',
'include_pending': True
}
response = requests.get(
testserver.url + '/balance',
params=params)
response = client.get('/balance',
params=params)
balance = response.json()
assert (balance[0] == {
@@ -78,9 +114,8 @@ def test_account(testserver):
'value': 100,
'token_symbol': 'COFE'
}
response = requests.post(
testserver.url + '/transfer',
params=params)
response = client.post('/transfer',
params=params)
transfer = response.json()
# Balance Account 1
@@ -89,9 +124,8 @@ def test_account(testserver):
'token_symbol': 'COFE',
'include_pending': True
}
response = requests.get(
testserver.url + '/balance',
params=params)
response = client.get('/balance',
params=params)
balance_after_transfer = response.json()
assert (balance_after_transfer[0] == {
"address": default_token.get('address').lower(),
@@ -107,13 +141,11 @@ def test_account(testserver):
'address': address_1,
'limit': 10
}
response = requests.get(
testserver.url + '/transactions',
params=params)
response = client.get('/transactions',
params=params)
transactions = response.json()
## TODO: What are the other 2 transactions
# TODO: What are the other 2 transactions
assert len(transactions) == 3
## Check the transaction is correct
# Check the transaction is correct
# TODO wtf is READSEND (Ready to send? Or already sent)
assert transactions[0].status == 'READYSEND'
exit(1) # Forcing it to fail to i get logs out of pytest