def setUp(self): connection_string = app_settings.get_connection_string() connection_pool = DictRowConnectionPool( None, connection_string, min=app_settings.API_MIN_CONNECTIONS) self.connection_pool = yield connection_pool.start() root = api.Root(connection_pool) self.web = DummySite(root)
def handle(self, *args, **options): """Run the Billing server""" def connection_established(connection_pool): from twisted.web.server import Site root = api.Root(connection_pool) site = Site(root) endpoint = serverFromString( reactor, app_settings.ENDPOINT_DESCRIPTION_STRING) endpoint.listen(site) reactor.callWhenRunning( lambda _: _.stdout.write( "Billing server is running on %s\n" % app_settings.ENDPOINT_DESCRIPTION_STRING), self) def connection_error(err): self.stderr.write(err) log.startLogging(sys.stdout) connection_string = app_settings.get_connection_string() connection_pool = DictRowConnectionPool( None, connection_string, min=app_settings.API_MIN_CONNECTIONS) self.stdout.write("Connecting to database %s..." % (connection_string,)) d = connection_pool.start() d.addCallbacks(connection_established, connection_error) reactor.run()
import pytest from twisted.internet.defer import inlineCallbacks, returnValue from vumi.tests.helpers import VumiTestCase from go.billing import settings as app_settings from go.billing import api from go.billing.models import MessageCost from go.billing.utils import DummySite, DictRowConnectionPool, JSONDecoder DB_SUPPORTED = False try: app_settings.get_connection_string() DB_SUPPORTED = True except ValueError: pass skipif_unsupported_db = pytest.mark.skipif( "True" if not DB_SUPPORTED else "False", reason="Billing API requires PostGreSQL") class ApiCallError(Exception): """Raised if a billing API call fails.""" def __init__(self, response): super(ApiCallError, self).__init__(response.value()) self.response = response