Moves start api to test_api since it was the only place where it's used

This commit is contained in:
Sergi Delgado Segura
2019-11-14 15:40:02 +00:00
parent 1d1efc9ccf
commit f33d2d61ac
2 changed files with 18 additions and 16 deletions

View File

@@ -8,9 +8,7 @@ from hashlib import sha256
from binascii import unhexlify from binascii import unhexlify
from apps.cli.blob import Blob from apps.cli.blob import Blob
from pisa.api import start_api
from pisa.responder import Job from pisa.responder import Job
from pisa.watcher import Watcher
from pisa.tools import bitcoin_cli from pisa.tools import bitcoin_cli
from pisa.db_manager import DBManager from pisa.db_manager import DBManager
from pisa.appointment import Appointment from pisa.appointment import Appointment
@@ -29,18 +27,6 @@ def run_bitcoind():
sleep(0.1) sleep(0.1)
@pytest.fixture(scope="session")
def run_api(db_manager):
watcher = Watcher(db_manager)
api_thread = Thread(target=start_api, args=[watcher])
api_thread.daemon = True
api_thread.start()
# It takes a little bit of time to start the API (otherwise the requests are sent too early and they fail)
sleep(0.1)
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def prng_seed(): def prng_seed():
random.seed(0) random.seed(0)

View File

@@ -1,11 +1,15 @@
import json import json
import pytest import pytest
import requests import requests
from time import sleep
from threading import Thread
from pisa import HOST, PORT, c_logger from pisa.api import start_api
from pisa.watcher import Watcher
from pisa.tools import bitcoin_cli from pisa.tools import bitcoin_cli
from test.unit.conftest import generate_blocks, get_random_value_hex, generate_dummy_appointment_data from pisa import HOST, PORT, c_logger
from pisa.conf import MAX_APPOINTMENTS from pisa.conf import MAX_APPOINTMENTS
from test.unit.conftest import generate_blocks, get_random_value_hex, generate_dummy_appointment_data
c_logger.disabled = True c_logger.disabled = True
@@ -16,6 +20,18 @@ appointments = []
locator_dispute_tx_map = {} locator_dispute_tx_map = {}
@pytest.fixture(scope="module")
def run_api(db_manager):
watcher = Watcher(db_manager)
api_thread = Thread(target=start_api, args=[watcher])
api_thread.daemon = True
api_thread.start()
# It takes a little bit of time to start the API (otherwise the requests are sent too early and they fail)
sleep(0.1)
@pytest.fixture @pytest.fixture
def new_appointment(): def new_appointment():
appointment, dispute_tx = generate_dummy_appointment_data() appointment, dispute_tx = generate_dummy_appointment_data()