convert api tests to uwsgi
This commit is contained in:
parent
6a0544b579
commit
3c3745228e
@ -19,10 +19,9 @@ spec = create_spec(spec_dict)
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
|
# TODO Implement wei conversions
|
||||||
|
|
||||||
# uwsgi application
|
# uwsgi application
|
||||||
|
|
||||||
|
|
||||||
def application(env, start_response):
|
def application(env, start_response):
|
||||||
oAPIRequest = UWSGIOpenAPIRequest(env)
|
oAPIRequest = UWSGIOpenAPIRequest(env)
|
||||||
validator = RequestValidator(spec)
|
validator = RequestValidator(spec)
|
||||||
@ -46,7 +45,7 @@ def application(env, start_response):
|
|||||||
|
|
||||||
# Setup Channel to receive the result
|
# Setup Channel to receive the result
|
||||||
|
|
||||||
if path == '/list':
|
if path == '/transactions':
|
||||||
address = params.pop('address')
|
address = params.pop('address')
|
||||||
print('address', address, )
|
print('address', address, )
|
||||||
# address, limit=10
|
# address, limit=10
|
||||||
|
@ -58,4 +58,5 @@ class UWSGIOpenAPIRequestFactory:
|
|||||||
body=body,
|
body=body,
|
||||||
mimetype=mimetype,
|
mimetype=mimetype,
|
||||||
)
|
)
|
||||||
|
|
||||||
UWSGIOpenAPIRequest = UWSGIOpenAPIRequestFactory.create
|
UWSGIOpenAPIRequest = UWSGIOpenAPIRequestFactory.create
|
@ -13,7 +13,7 @@ info:
|
|||||||
servers:
|
servers:
|
||||||
- url: /
|
- url: /
|
||||||
paths:
|
paths:
|
||||||
/token:
|
/default_token:
|
||||||
description: Retrieves the default fallback token of the custodial network.
|
description: Retrieves the default fallback token of the custodial network.
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
@ -310,8 +310,8 @@ components:
|
|||||||
type: integer
|
type: integer
|
||||||
description: Decimals
|
description: Decimals
|
||||||
example:
|
example:
|
||||||
symbol: 'GTF'
|
symbol: "GTF"
|
||||||
address: '3FF776B6f888980DEf9d4220858803f9dC5e341e'
|
address: "3FF776B6f888980DEf9d4220858803f9dC5e341e"
|
||||||
decimals: 6
|
decimals: 6
|
||||||
name: "Gift Token"
|
name: "Gift Token"
|
||||||
TokenBalance:
|
TokenBalance:
|
||||||
|
@ -2,6 +2,7 @@ pytest==6.0.1
|
|||||||
pytest-celery==0.0.0a1
|
pytest-celery==0.0.0a1
|
||||||
pytest-mock==3.3.1
|
pytest-mock==3.3.1
|
||||||
pytest-cov==2.10.1
|
pytest-cov==2.10.1
|
||||||
|
pytest-localserver==0.5.1
|
||||||
pytest-redis==2.0.0
|
pytest-redis==2.0.0
|
||||||
redis==3.5.3
|
redis==3.5.3
|
||||||
eth-tester==0.5.0b3
|
eth-tester==0.5.0b3
|
||||||
|
@ -1,159 +0,0 @@
|
|||||||
# coding: utf-8
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import time
|
|
||||||
|
|
||||||
import hexathon
|
|
||||||
import pytest
|
|
||||||
from cic_eth.server.app import create_app
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
log.debug("Here")
|
|
||||||
app = create_app({'TESTING': True})
|
|
||||||
with app.app.test_client() as client:
|
|
||||||
# with app.app_context():
|
|
||||||
# init_db()
|
|
||||||
yield client
|
|
||||||
|
|
||||||
|
|
||||||
def test_account(client):
|
|
||||||
# Default Token
|
|
||||||
query_string = []
|
|
||||||
response = client.open(
|
|
||||||
'/token',
|
|
||||||
method='GET',
|
|
||||||
query_string=query_string)
|
|
||||||
default_token = response.get_json()
|
|
||||||
|
|
||||||
# Create Account 1
|
|
||||||
query_string = [('password', ''),
|
|
||||||
('register', True)]
|
|
||||||
response = client.open(
|
|
||||||
'/create_account',
|
|
||||||
method='POST',
|
|
||||||
query_string=query_string)
|
|
||||||
address_1 = hexathon.valid(response.get_json())
|
|
||||||
|
|
||||||
# Create Account 2
|
|
||||||
query_string = [('password', ''),
|
|
||||||
('register', True)]
|
|
||||||
response = client.open(
|
|
||||||
'/create_account',
|
|
||||||
method='POST',
|
|
||||||
query_string=query_string)
|
|
||||||
address_2 = hexathon.valid(response.get_json())
|
|
||||||
time.sleep(30) # Required to allow balance to show
|
|
||||||
|
|
||||||
# Balance Account 1
|
|
||||||
query_string = [('address', address_1),
|
|
||||||
('token_symbol', 'COFE'),
|
|
||||||
('include_pending', True)]
|
|
||||||
response = client.open(
|
|
||||||
'/balance',
|
|
||||||
method='GET',
|
|
||||||
query_string=query_string)
|
|
||||||
balance = response.get_json()
|
|
||||||
|
|
||||||
assert (balance[0] == {
|
|
||||||
"address": default_token.get('address').lower(),
|
|
||||||
"balance_available": 30000000000,
|
|
||||||
"balance_incoming": 0,
|
|
||||||
"balance_network": 30000000000,
|
|
||||||
"balance_outgoing": 0,
|
|
||||||
"converters": []
|
|
||||||
})
|
|
||||||
|
|
||||||
# Transfer
|
|
||||||
query_string = [('from_address', address_1),
|
|
||||||
('to_address', address_2),
|
|
||||||
('value', 100),
|
|
||||||
('token_symbol', 'COFE')]
|
|
||||||
response = client.open(
|
|
||||||
'/transfer',
|
|
||||||
method='POST',
|
|
||||||
query_string=query_string)
|
|
||||||
transfer = response.get_json()
|
|
||||||
|
|
||||||
# Balance Account 1
|
|
||||||
query_string = [('address', address_1),
|
|
||||||
('token_symbol', 'COFE'),
|
|
||||||
('include_pending', True)]
|
|
||||||
response = client.open(
|
|
||||||
'/balance',
|
|
||||||
method='GET',
|
|
||||||
query_string=query_string)
|
|
||||||
balance_after_transfer = response.get_json()
|
|
||||||
assert (balance_after_transfer[0] == {
|
|
||||||
"address": default_token.get('address').lower(),
|
|
||||||
"balance_available": 29900000000,
|
|
||||||
"balance_incoming": 0,
|
|
||||||
"balance_network": 30000000000,
|
|
||||||
"balance_outgoing": 100000000,
|
|
||||||
"converters": []
|
|
||||||
})
|
|
||||||
|
|
||||||
# Transactions Account 1
|
|
||||||
query_string = [('address', address_1),
|
|
||||||
('limit', 10)]
|
|
||||||
response = client.open(
|
|
||||||
'/transactions',
|
|
||||||
method='GET',
|
|
||||||
query_string=query_string)
|
|
||||||
transactions = response.get_json()
|
|
||||||
log.debug(transactions)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# def test_list_transactions(client):
|
|
||||||
# """Test case for list_transactions
|
|
||||||
|
|
||||||
|
|
||||||
# """
|
|
||||||
# query_string = [('address', "test_address"),
|
|
||||||
# ('limit', 10)]
|
|
||||||
# response = client.open(
|
|
||||||
# '/transactions',
|
|
||||||
# method='GET',
|
|
||||||
# query_string=query_string)
|
|
||||||
# self.assert200(response,
|
|
||||||
# 'Response body is : ' + response.data.decode('utf-8'))
|
|
||||||
|
|
||||||
|
|
||||||
# def test_transfer(client):
|
|
||||||
# """Test case for transfer
|
|
||||||
|
|
||||||
|
|
||||||
# """
|
|
||||||
# query_string = [('from_address', "test_address"),
|
|
||||||
# ('to_address', "test_address"),
|
|
||||||
# ('value', 56),
|
|
||||||
# ('token_symbol', 'token_symbol_example')]
|
|
||||||
# response = client.open(
|
|
||||||
# '/transfer',
|
|
||||||
# method='POST',
|
|
||||||
# query_string=query_string)
|
|
||||||
# self.assert200(response,
|
|
||||||
# 'Response body is : ' + response.data.decode('utf-8'))
|
|
||||||
|
|
||||||
|
|
||||||
# def test_transfer_from(client):
|
|
||||||
# """Test case for transfer_from
|
|
||||||
|
|
||||||
|
|
||||||
# """
|
|
||||||
# query_string = [('from_address', "test_address"),
|
|
||||||
# ('to_address', "test_address"),
|
|
||||||
# ('value', 56),
|
|
||||||
# ('token_symbol', 'token_symbol_example'),
|
|
||||||
# ('spender_address', "test_address")]
|
|
||||||
# response = client.open(
|
|
||||||
# '/transfer_from',
|
|
||||||
# method='POST',
|
|
||||||
# query_string=query_string)
|
|
||||||
# self.assert200(response,
|
|
||||||
# 'Response body is : ' + response.data.decode('utf-8'))
|
|
@ -1,43 +0,0 @@
|
|||||||
# # coding: utf-8
|
|
||||||
|
|
||||||
# from __future__ import absolute_import
|
|
||||||
|
|
||||||
# import logging
|
|
||||||
|
|
||||||
# import connexion
|
|
||||||
# from cic_eth.server.encoder import JSONEncoder
|
|
||||||
# from cic_eth.server.models.token import Token
|
|
||||||
# from flask import json
|
|
||||||
# from flask_testing import TestCase
|
|
||||||
# from six import BytesIO
|
|
||||||
|
|
||||||
|
|
||||||
# class BaseTestCase(TestCase):
|
|
||||||
|
|
||||||
# def create_app(self):
|
|
||||||
# logging.getLogger('connexion.operation').setLevel('ERROR')
|
|
||||||
# app = connexion.App(
|
|
||||||
# __name__, specification_dir='../../cic_eth/server/openapi')
|
|
||||||
# app.app.json_encoder = JSONEncoder
|
|
||||||
# app.add_api('server.yaml')
|
|
||||||
# return app.app
|
|
||||||
|
|
||||||
|
|
||||||
# class TestTokenController(BaseTestCase):
|
|
||||||
# """TokenController integration test stubs"""
|
|
||||||
|
|
||||||
# def test_get_default_token(self):
|
|
||||||
# """Test case for get_default_token
|
|
||||||
|
|
||||||
|
|
||||||
# """
|
|
||||||
# response = self.client.open(
|
|
||||||
# '/token',
|
|
||||||
# method='GET')
|
|
||||||
# self.assert200(response,
|
|
||||||
# 'Response body is : ' + response.data.decode('utf-8'))
|
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == '__main__':
|
|
||||||
# import unittest
|
|
||||||
# unittest.main()
|
|
115
apps/cic-eth/tests/test_server.py
Normal file
115
apps/cic-eth/tests/test_server.py
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
import hexathon
|
||||||
|
import pytest
|
||||||
|
import requests
|
||||||
|
from cic_eth.runnable.daemons.server import application
|
||||||
|
from pytest_localserver.http import WSGIServer
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def test_account(testserver):
|
||||||
|
# Default Token
|
||||||
|
response = requests.get(
|
||||||
|
testserver.url + '/default_token',
|
||||||
|
)
|
||||||
|
log.debug(f"balance response {response}")
|
||||||
|
default_token = response.json()
|
||||||
|
|
||||||
|
# Create Account 1
|
||||||
|
params = {
|
||||||
|
'password': '',
|
||||||
|
'register': True
|
||||||
|
}
|
||||||
|
response = requests.post(
|
||||||
|
testserver.url + '/create_account',
|
||||||
|
params=params)
|
||||||
|
address_1 = hexathon.valid(response.json())
|
||||||
|
|
||||||
|
# Create Account 2
|
||||||
|
params = {
|
||||||
|
'password': '',
|
||||||
|
'register': True
|
||||||
|
}
|
||||||
|
response = requests.post(
|
||||||
|
testserver.url + '/create_account',
|
||||||
|
params=params)
|
||||||
|
address_2 = hexathon.valid(response.json())
|
||||||
|
time.sleep(30) # Required to allow balance to show
|
||||||
|
|
||||||
|
# Balance Account 1
|
||||||
|
params = {
|
||||||
|
'address': address_1,
|
||||||
|
'token_symbol': 'COFE',
|
||||||
|
'include_pending': True
|
||||||
|
}
|
||||||
|
response = requests.get(
|
||||||
|
testserver.url + '/balance',
|
||||||
|
params=params)
|
||||||
|
balance = response.json()
|
||||||
|
|
||||||
|
assert (balance[0] == {
|
||||||
|
"address": default_token.get('address').lower(),
|
||||||
|
"balance_available": 30000000000,
|
||||||
|
"balance_incoming": 0,
|
||||||
|
"balance_network": 30000000000,
|
||||||
|
"balance_outgoing": 0,
|
||||||
|
"converters": []
|
||||||
|
})
|
||||||
|
|
||||||
|
# Transfer
|
||||||
|
params = {
|
||||||
|
'from_address': address_1,
|
||||||
|
'to_address': address_2,
|
||||||
|
'value': 100,
|
||||||
|
'token_symbol': 'COFE'
|
||||||
|
}
|
||||||
|
response = requests.post(
|
||||||
|
testserver.url + '/transfer',
|
||||||
|
params=params)
|
||||||
|
transfer = response.json()
|
||||||
|
|
||||||
|
# Balance Account 1
|
||||||
|
params = {
|
||||||
|
'address': address_1,
|
||||||
|
'token_symbol': 'COFE',
|
||||||
|
'include_pending': True
|
||||||
|
}
|
||||||
|
response = requests.get(
|
||||||
|
testserver.url + '/balance',
|
||||||
|
params=params)
|
||||||
|
balance_after_transfer = response.json()
|
||||||
|
assert (balance_after_transfer[0] == {
|
||||||
|
"address": default_token.get('address').lower(),
|
||||||
|
"balance_available": 29900000000,
|
||||||
|
"balance_incoming": 0,
|
||||||
|
"balance_network": 30000000000,
|
||||||
|
"balance_outgoing": 100000000,
|
||||||
|
"converters": []
|
||||||
|
})
|
||||||
|
|
||||||
|
# Transactions Account 1
|
||||||
|
params = {
|
||||||
|
'address': address_1,
|
||||||
|
'limit': 10
|
||||||
|
}
|
||||||
|
response = requests.get(
|
||||||
|
testserver.url + '/transactions',
|
||||||
|
params=params)
|
||||||
|
transactions = response.json()
|
||||||
|
log.debug(transactions)
|
||||||
|
exit(1)
|
@ -220,10 +220,8 @@ services:
|
|||||||
set -a
|
set -a
|
||||||
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
||||||
set +a
|
set +a
|
||||||
/usr/local/bin/uwsgi \
|
pip install -r test_requirements.txt
|
||||||
--wsgi-file /root/cic_eth/runnable/daemons/server.py \
|
tail -F ./requirements.txt
|
||||||
--http :5000 \
|
|
||||||
--pyargv "-vv"
|
|
||||||
|
|
||||||
cic-eth-tracker:
|
cic-eth-tracker:
|
||||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||||
|
Loading…
Reference in New Issue
Block a user