Пример #1
0
 def testPostgreConectionThree(self):
     try:
         connection_postgres("host", "database", "", "senha", 10, 1000, "")
         teste = 1
     except:
         teste = 0
     self.assertFalse(
         bool(teste),
         msg="Teste 3 (Postgre) veio true (1), mas esperava falso (0).")
Пример #2
0
 def testPostgreConectionOne(self):
     try:
         connection_postgres("", "database", "usuario", "senha", 10, 1000,
                             "")
         teste = 1
     except:
         teste = 0
     self.assertTrue(
         bool(teste),
         msg="Teste 1 (Postgre) veio true (1), mas esperava falso (0).")
Пример #3
0
 def testPostgreConectionEight(self):
     try:
         connection_postgres("host", "database", "usuario", "senha", 10,
                             1000, "AND gdfssg > 1000")
         teste = 1
     except:
         teste = 0
     self.assertFalse(
         bool(teste),
         msg="Teste 8 (Postgre) veio true (1), mas esperava falso (0).")
Пример #4
0
    def testPostgreConectionSeven(self):
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 10, 10,
                                ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 10,
                                100, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 10,
                                1000, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 10,
                                10000, ""))

        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 14, 10,
                                ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 14,
                                100, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 14,
                                1000, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 14,
                                10000, ""))

        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 16, 10,
                                ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 16,
                                100, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 16,
                                1000, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 16,
                                10000, ""))

        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 17, 10,
                                ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 17,
                                100, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 17,
                                1000, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 17,
                                10000, ""))

        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 19, 10,
                                ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 19,
                                100, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 19,
                                1000, ""))
        self.assertTrue(
            connection_postgres("host", "database", "usuario", "senha", 19,
                                10000, ""))
Пример #5
0
    if len(last_id) != 0:  # Se last_id que eh uma lista for diferente de vazia, passamos o where com o valor retornado
        where = 'AND hf.id > {0}'.format(last_id[0][0])  # Parte da clausula Where que deve ser inserida na conecção com postgres
    else:
        where = ''  # passamos vazio pois nao existe um primeiro id inserido no SQL Server

    # Parametros da funcao connection_postgres:
    # Host
    # Database
    # Usuario
    # Senha
    # id_maquina: id da maquina que desejamos retornar os valores (Inserir os ids em lista_maquinas_consulta)
    # limit_value: Valor limitante de quantos registros desejamos retornar do banco
    # where: Caso uma primeira consulta ja executada, envia uma restrição para puxar ids maiores que o ultimo ja migrado

    # maq recebe os dados puxados do database postgres
    maq = connection_postgres("Host", "Database", "User", "Senha", id_maquina, 1000, where)
    # e apenda os dados para cada id de maquina
    lista_response.append(maq)

count_for_query = 1  # ID que conta cada linha de dado puxada. A cada 1000 registros, devemos realizar a insercao
for rows in lista_response:  # para cada maquina, ou seja, para todos os dados de cada maquina retornado
    q_insert = "INSERT INTO Teste2 VALUES "
    for row in rows:  # Para uma unica maquina, itera sobre as dicts

        q_insert += "({},{},'{}',CONVERT(datetime,'{}',127),{},'{}',{},'{}',{},{},{},'{}',{}),".format(
            row["id"],
            row["maquina_id"],
            row["maquina_nome"],
            row["inicio"].strftime("%Y-%m-%dT%H:%M:%SZ"),
            row["op_id"],
            row["op_name"],