Beispiel #1
0
class ModelTestCase(unittest.TestCase):

    def setUp(self):
       
        self.session = create_session()
        self._old_now_func = tables.set_now_func(utc_now)

        self.dummy_processor = DummyProcessor()

        self.model_factory = ModelFactory(
            session=self.session,
            processor_factory=lambda: self.dummy_processor,
            settings={},
        )
        self.company_model = self.model_factory.create_company_model()
        self.customer_model = self.model_factory.create_customer_model()
        self.plan_model = self.model_factory.create_plan_model()
        self.subscription_model = self.model_factory.create_subscription_model()
        self.invoice_model = self.model_factory.create_invoice_model()
        self.transaction_model = self.model_factory.create_transaction_model()
        self.transaction_failure_model = self.model_factory.create_transaction_failure_model()

    def tearDown(self):
        self.session.close()
        self.session.remove()
        tables.DeclarativeBase.metadata.drop_all()
        self.session.bind.dispose()
        tables.set_now_func(self._old_now_func)
Beispiel #2
0
class ModelTestCase(unittest.TestCase):
    def setUp(self):

        self.session = create_session()
        self._old_now_func = tables.set_now_func(utc_now)

        self.dummy_processor = DummyProcessor()

        self.model_factory = ModelFactory(
            session=self.session,
            processor_factory=lambda: self.dummy_processor,
            settings={},
        )
        self.company_model = self.model_factory.create_company_model()
        self.customer_model = self.model_factory.create_customer_model()
        self.plan_model = self.model_factory.create_plan_model()
        self.subscription_model = self.model_factory.create_subscription_model(
        )
        self.invoice_model = self.model_factory.create_invoice_model()
        self.transaction_model = self.model_factory.create_transaction_model()
        self.transaction_failure_model = self.model_factory.create_transaction_failure_model(
        )

    def tearDown(self):
        self.session.close()
        self.session.remove()
        tables.DeclarativeBase.metadata.drop_all()
        self.session.bind.dispose()
        tables.set_now_func(self._old_now_func)
Beispiel #3
0
class ViewTestCase(unittest.TestCase):
    def setUp(self):
        self.dummy_processor = DummyProcessor()

        def model_factory_func():
            return self.model_factory

        if not hasattr(self, 'settings'):
            self.settings = {
                'billy.processor_factory': lambda: self.dummy_processor,
                'model_factory_func': model_factory_func,
                # do not remove when a request is processed, so that we don't
                # have to use session.add every time
                'db_session_cleanup': False,
            }

        # init database
        db_url = os.environ.get('BILLY_FUNC_TEST_DB', 'sqlite://')
        self.settings['sqlalchemy.url'] = db_url
        self.settings = setup_database({}, **self.settings)
        DeclarativeBase.metadata.bind = self.settings['engine']
        DeclarativeBase.metadata.create_all()

        app = main({}, **self.settings)
        self.testapp = TestApp(app)
        self.testapp.session = self.settings['session']

        self.dummy_request = DummyRequest()

        # create model factory
        self.model_factory = ModelFactory(
            session=self.testapp.session,
            processor_factory=lambda: self.dummy_processor,
            settings=self.settings,
        )

        # create all models
        self.company_model = self.model_factory.create_company_model()
        self.customer_model = self.model_factory.create_customer_model()
        self.plan_model = self.model_factory.create_plan_model()
        self.subscription_model = self.model_factory.create_subscription_model(
        )
        self.invoice_model = self.model_factory.create_invoice_model()
        self.transaction_model = self.model_factory.create_transaction_model()
        self.transaction_failure_model = self.model_factory.create_transaction_failure_model(
        )

    def tearDown(self):
        self.testapp.session.close()
        self.testapp.session.remove()
        DeclarativeBase.metadata.drop_all()
        self.testapp.session.bind.dispose()
Beispiel #4
0
class ViewTestCase(unittest.TestCase):
    def setUp(self):
        self.dummy_processor = DummyProcessor()

        def model_factory_func():
            return self.model_factory

        if not hasattr(self, "settings"):
            self.settings = {
                "billy.processor_factory": lambda: self.dummy_processor,
                "model_factory_func": model_factory_func,
                # do not remove when a request is processed, so that we don't
                # have to use session.add every time
                "db_session_cleanup": False,
            }

        # init database
        db_url = os.environ.get("BILLY_FUNC_TEST_DB", "sqlite://")
        self.settings["sqlalchemy.url"] = db_url
        self.settings = setup_database({}, **self.settings)
        DeclarativeBase.metadata.bind = self.settings["engine"]
        DeclarativeBase.metadata.create_all()

        app = main({}, **self.settings)
        self.testapp = TestApp(app)
        self.testapp.session = self.settings["session"]

        self.dummy_request = DummyRequest()

        # create model factory
        self.model_factory = ModelFactory(
            session=self.testapp.session, processor_factory=lambda: self.dummy_processor, settings=self.settings
        )

        # create all models
        self.company_model = self.model_factory.create_company_model()
        self.customer_model = self.model_factory.create_customer_model()
        self.plan_model = self.model_factory.create_plan_model()
        self.subscription_model = self.model_factory.create_subscription_model()
        self.invoice_model = self.model_factory.create_invoice_model()
        self.transaction_model = self.model_factory.create_transaction_model()
        self.transaction_failure_model = self.model_factory.create_transaction_failure_model()

    def tearDown(self):
        self.testapp.session.close()
        self.testapp.session.remove()
        DeclarativeBase.metadata.drop_all()
        self.testapp.session.bind.dispose()
Beispiel #5
0
class ViewTestCase(unittest.TestCase):
  
    def setUp(self):
        self.dummy_processor = DummyProcessor()

        def model_factory_func():
            return self.model_factory

        if not hasattr(self, 'settings'):
            self.settings = {
                'billy.processor_factory': lambda: self.dummy_processor,
                'model_factory_func': model_factory_func,
            }

        # init database
        db_url = os.environ.get('BILLY_FUNC_TEST_DB', 'sqlite://')
        self.settings['sqlalchemy.url'] = db_url
        self.settings = setup_database({}, **self.settings)
        DeclarativeBase.metadata.bind = self.settings['engine']
        DeclarativeBase.metadata.create_all()

        app = main({}, **self.settings)
        self.testapp = TestApp(app)
        self.testapp.session = self.settings['session']

        self.dummy_request = DummyRequest()

        # create model factory
        self.model_factory = ModelFactory(
            session=self.testapp.session,
            processor_factory=lambda: self.dummy_processor,
            settings=self.settings,
        )

        # create all models
        self.company_model = self.model_factory.create_company_model()
        self.customer_model = self.model_factory.create_customer_model()
        self.plan_model = self.model_factory.create_plan_model()
        self.subscription_model = self.model_factory.create_subscription_model()
        self.invoice_model = self.model_factory.create_invoice_model()
        self.transaction_model = self.model_factory.create_transaction_model()
        self.transaction_failure_model = self.model_factory.create_transaction_failure_model()

    def tearDown(self):
        self.testapp.session.close()
        self.testapp.session.remove()
        DeclarativeBase.metadata.drop_all()
        self.testapp.session.bind.dispose()
def main(argv=sys.argv, processor=None):
    logger = logging.getLogger(__name__)

    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    settings = setup_database({}, **settings)

    session = settings['session']
    try:
        if processor is None:
            processor_factory = get_processor_factory(settings)
        else:
            processor_factory = lambda: processor
        factory = ModelFactory(
            session=session,
            processor_factory=processor_factory,
            settings=settings,
        )
        subscription_model = factory.create_subscription_model()
        tx_model = factory.create_transaction_model()

        # yield all transactions and commit before we process them, so that
        # we won't double process them.
        with db_transaction.manager:
            logger.info('Yielding transaction ...')
            subscription_model.yield_invoices()

        with db_transaction.manager:
            logger.info('Processing transaction ...')
            tx_model.process_transactions()
        logger.info('Done')
    finally:
        session.close()