Coverage for test/lib_test_util.py: 74%
27 statements
« prev ^ index » next coverage.py v7.9.1, created at 2026-01-26 23:58 +0100
« prev ^ index » next coverage.py v7.9.1, created at 2026-01-26 23:58 +0100
1# -*- coding: utf-8 -*-
2__author__ = 'moilerat'
3#
4# # Safia copyright 2022-2023 VR - LICENSETOBEDEFINED : on premise treatment custom
5#
6#! Package test
7#! TO CREATE test database from init migration db (we should use the consolidate migration (but they are still very different !) )
8#
11# DROP DATABASE IF EXISTS mtr;
12# CREATE DATABASE mtr;
13# \c mtr
15# This function expect a specific format
16def read_and_modify_migration_for_db_test(path_to_file_migration_db, DB_NAME_PROD = "mtr", DB_NAME_TEST = "mtr_nrg"):
18 number_match = 0
20 with open(path_to_file_migration_db, "r") as f:
21 migration_command = f.readlines()
22 migration_command_nrt = []
23 create_db_nrt = ["\set AUTOCOMMIT = ON;"]
24 for m in migration_command:
25 if m == "DROP DATABASE IF EXISTS " + DB_NAME_PROD + ";\n":
26 number_match += 1
27 create_db_nrt.append("DROP DATABASE IF EXISTS " + DB_NAME_TEST + ";\n")
28 elif m == "CREATE DATABASE " + DB_NAME_PROD + ";\n" :
29 number_match += 1
30 create_db_nrt.append("CREATE DATABASE " + DB_NAME_TEST + ";\n")
31 elif m == "\c " + DB_NAME_PROD + "\n" :
32 number_match += 1
33 # migration_command_nrt.append("--\c " + DB_NAME_TEST + "\n")
34 elif m == ' user_id INTEGER NOT NULL REFERENCES mtruser.user (id),\n' : # en plus il y en a plusieurs, seul celui dans projet, enfin bon
35 #" user_id INTEGER NOT NULL REFERENCES mtruser.user (id),": # useless when we use consolidate migration 0.3.6
36 # owner_id
37 number_match += 1
38 migration_command_nrt.append(" owner_id INTEGER NOT NULL REFERENCES mtruser.user (id),\n")
39 # temporary 13-7-23
40 elif m == " CONSTRAINT unique_userid_filename UNIQUE (user_id, filename) -- Ajout de la contrainte UNIQUE sur le couple (user_id, filename)\n":
41 number_match += 1
42 migration_command_nrt.append(" CONSTRAINT unique_userid_filename UNIQUE (owner_id, filename) -- Ajout de la contrainte UNIQUE sur le couple (user_id, filename)\n")
43 else :
44 migration_command_nrt.append(m)
46 if number_match < 3:
47 print("We won't modify the prod database (even on integration server), so we return null stuff")
48 return ""
50 return "".join(migration_command_nrt), "".join(create_db_nrt)