-
Notifications
You must be signed in to change notification settings - Fork 44
/
test_ib_gateway.py
65 lines (58 loc) · 2.18 KB
/
test_ib_gateway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pytest
import subprocess
import testinfra
import os
import time
import requests
IMAGE_NAME = os.environ['IMAGE_NAME']
def test_healthcheck():
account = os.environ['IB_ACCOUNT']
password = os.environ['IB_PASSWORD']
trading_mode = os.environ['TRADING_MODE']
# run a container
docker_id = subprocess.check_output(
['docker', 'run',
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADING_MODE={}'.format(trading_mode),
'-d', IMAGE_NAME]).decode().strip()
time.sleep(30)
assert subprocess.check_call(['docker', 'exec', docker_id, 'healthcheck']) == 0
subprocess.check_call(['docker', 'rm', '-f', docker_id])
def test_healthcheck_api():
account = os.environ['IB_ACCOUNT']
password = os.environ['IB_PASSWORD']
trading_mode = os.environ['TRADING_MODE']
# run a container
docker_id = subprocess.check_output(
['docker', 'run',
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADING_MODE={}'.format(trading_mode),
'--env', 'HEALTHCHECK_API_ENABLE=true',
'-p', '8080:8080',
'-d', IMAGE_NAME]).decode().strip()
time.sleep(30)
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert response.ok
subprocess.check_call(['docker', 'rm', '-f', docker_id])
def test_healthcheck_api_fail():
account = 'test'
password = 'test'
trading_mode = os.environ['TRADING_MODE']
# run a container
docker_id = subprocess.check_output(
['docker', 'run',
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADING_MODE={}'.format(trading_mode),
'--env', 'HEALTHCHECK_API_ENABLE=true',
'-p', '8080:8080',
'-d', IMAGE_NAME]).decode().strip()
time.sleep(30)
try:
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert not response.ok
except requests.exceptions.ConnectionError:
pass
subprocess.check_call(['docker', 'rm', '-f', docker_id])