示例#1
0
def delete_test_base():
    """Delete entire test database"""
    Configuration.set_configuration(config)
    deletion_request ="""DROP TABLE xtest;"""
    RecordManager.record(
        Adapter.raw_sql_request(deletion_request)
    )
    RecordManager.execute()
示例#2
0
 def test_update(self):
     """Test de la fonction de mise à jour"""
     timestamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
     RecordManager.record(
         Adapter.update('xtest', 'datestamp', timestamp, condition="nom='toto'")
     )
     RecordManager.execute()
     cnx_object = mysql.connector.connect(**config)
     cursor = cnx_object.cursor()
     query = ("SELECT datestamp FROM xtest")
     cursor.execute(query)
     result = cursor.fetchone()
     cursor.close()
     cnx_object.close()
     self.assertEqual(timestamp, result[0].strftime('%Y-%m-%d %H:%M:%S'))
示例#3
0
 def test_insert(self):
     """Test de la fonction d'insertion"""
     timestamp1 = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
     timestamp2 = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
     RecordManager.record(
         Adapter.insert('xtest',
             [('jerry', timestamp1 ), ('levy', timestamp2)],
             ('nom', 'datestamp')
         )
     )
     RecordManager.execute()
     cnx_object = mysql.connector.connect(**config)
     cursor = cnx_object.cursor()
     query = ("SELECT datestamp FROM xtest WHERE nom='jerry'")
     cursor.execute(query)
     result = cursor.fetchone()
     cursor.close()
     cnx_object.close()
     self.assertEqual(timestamp1, result[0].strftime('%Y-%m-%d %H:%M:%S'))
示例#4
0
def set_up_test_base():
    """Create test database"""
    Configuration.set_configuration(config)
    timestamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
    creation_request ="CREATE TABLE xtest (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, nom VARCHAR(180) NOT NULL, datestamp TIMESTAMP NOT NULL);"
    insertion_request = "INSERT INTO xtest (nom, datestamp) VALUES ('toto', '"+ str(timestamp) + "');"
    RecordManager.record(
        Adapter.raw_sql_request(creation_request)
    )
    RecordManager.record(
            Adapter.raw_sql_request(insertion_request)
        )
    RecordManager.execute()
示例#5
0
 def test_save_and_file_loading(self):
     """Teste la fonction de sauvegarde et le chargement du fichier de save et son exécution"""
     set_up_test_base()
     timestamp1 = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
     RecordManager.record(
         Adapter.insert('xtest',
             [('bibi', timestamp1 )],
             ('nom', 'datestamp')
         )
     )
     RecordManager.delete('test_save')
     RecordManager.save('test_save')
     RecordManager.execute('test_save')
     cnx_object = mysql.connector.connect(**config)
     cursor = cnx_object.cursor()
     query = ("SELECT datestamp FROM xtest WHERE nom='bibi'")
     cursor.execute(query)
     result = cursor.fetchone()
     cursor.close()
     cnx_object.close()
     self.assertEqual(timestamp1, result[0].strftime('%Y-%m-%d %H:%M:%S'))
     delete_test_base()
示例#6
0
def database_maj():
    """Fonction de mise à jour de la base de donnee, chaque embranchement conditionnel correspond a une tache"""
    while True:
        dtn = datetime.datetime.now()
        # Entre le premier et dix du mois, on met les fiche de frais à CL
        if dtn.day > 1 and dtn.day < 9:
            weird_month = Datemanager.get_weird_gsb_last_month()
            RecordManager.delete("update_fichefrais")
            RecordManager.record(
                Adapter.update("fichefrais", "idEtat", "CL",
                               "mois={}".format(weird_month)))
            RecordManager.save('update_fichefrais')
            TimeCron.schedule(RecordManager.execute, ("update_fichefrais"))
        if dtn.day == 20:
            weird_month = Datemanager.get_weird_gsb_last_month()
            RecordManager.delete("update_fichefrais")
            RecordManager.record(
                Adapter.update("fichefrais", "idEtat", "RB",
                               "mois={}".format(weird_month)))
            RecordManager.save('update_fichefrais')
            TimeCron.schedule(RecordManager.execute, ("update_fichefrais"))
        # Attendre le prochain contrôle le lendemain
        time.sleep(86400)
示例#7
0
 def test_record(self):
     """Vérifie l'enregistrement des requêtes"""
     RecordManager.record("SELECT * FROM test")
     RecordManager.record("SELECT * FROM test")
     self.assertEqual(len(RecordManager._queue), 2)
示例#8
0
 def tearDown(self):
     RecordManager.clear()
示例#9
0
 def setUp(self):
     RecordManager.clear()