コード例 #1
0
    def __init__(self, version: str, dest_path: Path):

        self.version = version
        self.dest_path = dest_path
        self.sqlite = self.dest_path / (self.version + ".sqlite")
        self.sql = self.dest_path / (self.version + ".sql")
        self.db = Database()
        self.f = Faker(self.db)

        # setup temp file
        file = tempfile.NamedTemporaryFile(delete=False)
        file.close()
        self.tmp_path = Path(file.name)
        self.db.bind(provider="sqlite", filename=file.name)
        init_models(self.db)
        self.db.generate_mapping(create_tables=True)
コード例 #2
0
def main_init_database(filename=None, prod=False):
    # init database first
    settings = QSettings()
    logger.info(f"ficher settings : {settings.fileName()}")
    newdb = Database()
    create_db = False
    import mycartable.database

    if prod:
        from mycartable.defaults.files_path import ROOT_DATA

        filename = settings.value("General/ddb_path",
                                  ROOT_DATA / "mycartable.ddb")
        create_db = True
    else:
        QStandardPaths.setTestModeEnabled(True)
        # filename.unlink()
        filename = Path(tempfile.gettempdir()) / "devddbmdk.sqlite"
        # filename = "/home/jimmy/Documents/MyCartable/mycartable.ddb"
        # filename = ":memory:"
        # filename = ":memory:"
        create_db = True

    from mycartable.migrations.migrations import make_migrations

    if filename != ":memory:" and Path(filename).is_file():
        migrate_res = make_migrations(filename)
        if not migrate_res:
            from mycartable.defaults.files_path import LOGFILE

            raise SystemError(f"voir dans {LOGFILE}")

    mycartable.database.db = newdb

    db = mycartable.database.init_database(newdb,
                                           filename=filename,
                                           create_db=create_db)

    if not prod:
        from tests.factory import Faker

        with db_session:
            db.Configuration.add("annee", 2019)

        try:
            f = Faker(db)
            m = f.f_matiere(groupe=2019)
            ac = f.f_activite(matiere=m)
            p = f.f_page(activite=ac)
            f.f_textSection(page=p)
        except:
            pass

    return mycartable.database.db
コード例 #3
0
def fkc(ddbr_class):
    return Faker(ddbr_class)
コード例 #4
0
def fk(ddbr):

    return Faker(ddbr)
コード例 #5
0
class GenerateDatabase:
    def __init__(self, version: str, dest_path: Path):

        self.version = version
        self.dest_path = dest_path
        self.sqlite = self.dest_path / (self.version + ".sqlite")
        self.sql = self.dest_path / (self.version + ".sql")
        self.db = Database()
        self.f = Faker(self.db)

        # setup temp file
        file = tempfile.NamedTemporaryFile(delete=False)
        file.close()
        self.tmp_path = Path(file.name)
        self.db.bind(provider="sqlite", filename=file.name)
        init_models(self.db)
        self.db.generate_mapping(create_tables=True)

    def __call__(self):
        self.build()
        self.finalize()

    @property
    def sqlite_and_sql(self):
        return self.sqlite.is_file() and self.sql.is_file()

    def build(self):
        getattr(self, "version_" + self.version.replace(".", "_"))()
        self.db.disconnect()

    def finalize(self):

        if self.sqlite_and_sql:
            self.compare_schema()
        else:
            self.store_db_and_schema()

    def compare_schema(self):
        actual_schema = self.sql.read_text()
        assert (
            Schema(self.db).schema == actual_schema
        ), f"Les schémas actuel et stocké ne correspondent plus. version: {self.version}"

    def store_db_and_schema(self):
        shutil.move(self.tmp_path, self.sqlite)
        schema = Schema(self.sqlite)
        schema.version = self.version
        schema.to_file(self.sql)

    """
    Sous cette marque, on définie les fonctions pour les versions
    """

    def generate_items(self):
        """genere au moins 1 élément de chaque table"""
        self.f.f_annotationDessin(
        )  # User, Annee,  GroupeMatiere, Matiere, ACtivite, Section, Page , Annotation
        self.f.f_tableauCell()  # TableauSection, TableauCell
        self.f.f_friseLegende()  # FriseSection, ZoneFrise, FriseLegende
        self.f.f_configuration()  # configuration

    def version_1_3_0(self):
        self.generate_items()
        self.f.f_annotationDessin(points="""[{"x": 0.3, "y": 0.4}]""")

    def version_1_4_0(self):
        self.generate_items()

    def version_1_5_0(self):
        self.generate_items()
        self.f.f_traduction(content="coucou", locale="fr_FR")

    def version_1_6_0(self):
        self.generate_items()
        self.f.f_traduction(content="hello", locale="fr_FR")
コード例 #6
0
ファイル: conftest.py プロジェクト: jgirardet/MyCartable
 def __init__(self, db, parent=None):
     super().__init__(parent)
     self.db = db
     self.faker = Faker(db)