Beispiel #1
0
def init_example_application_with_sqlalchemy():
    init_example_application(
        entity_active_record_strategy=SQLAlchemyActiveRecordStrategy(
            active_record_class=IntegerSequencedItem,
            session=db.session,
        )
    )
def init_example_application_with_sqlalchemy():
    init_example_application(
        entity_record_manager=SQLAlchemyRecordManager(
            record_class=IntegerSequencedItem,
            session=db.session,
        )
    )
    def test(self):
        self.datastore.setup_connection()
        self.datastore.setup_tables()
        active_record_strategy = SQLAlchemyActiveRecordStrategy(
            active_record_class=IntegerSequencedItemRecord,
            session=self.datastore.session,
        )

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_active_record_strategy=active_record_strategy
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_active_record_strategy=active_record_strategy
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))

        # Close single instance.
        close_example_application()

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_active_record_strategy=active_record_strategy
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_active_record_strategy=active_record_strategy
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))
    def test(self):
        self.datastore.setup_connection()
        self.datastore.setup_tables()
        record_manager = SQLAlchemyRecordManager(
            record_class=IntegerSequencedNoIDRecord,
            session=self.datastore.session,
        )

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_record_manager=record_manager
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_record_manager=record_manager
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))

        # Close single instance.
        close_example_application()

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_record_manager=record_manager
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_record_manager=record_manager
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))