Exemple #1
0
    def test_upsert_many_empty_file(self):
        bulk_upserter = dml.CopyFromUpsert(self.table,
                                           delimiter=self.delimiter,
                                           null_str=self.null_str,
                                           force_null=self.force_null)
        text = '\n'.join([delimited_text().splitlines()[0], ''])
        file_object = io.StringIO(text)

        with self.conn:
            bulk_upserter(self.conn, file_object)
Exemple #2
0
    def test_upsert_many(self):
        records = [('Miami', 'TX'), ('Chicago', 'MI')]

        with self.conn.cursor() as cursor:
            cursor.executemany(self.insert_query, records)
        self.conn.commit()

        bulk_upserter = dml.CopyFromUpsert(self.table,
                                           delimiter=self.delimiter,
                                           null_str=self.null_str,
                                           force_null=self.force_null)
        file_object = io.StringIO(delimited_text())

        with self.conn:
            bulk_upserter(self.conn, file_object)

        result = get_records(self.conn, self.table_name)

        self.assertEqual(self.records, result)
Exemple #3
0
    def test_upsert_many_primary_key(self):
        records = [('Chicago', 'IL')]

        with self.conn.cursor() as cursor:
            cursor.executemany(self.insert_query, records)
        self.conn.commit()

        bulk_upserter = dml.CopyFromUpsert(self.table,
                                           delimiter=self.delimiter,
                                           null_str=self.null_str,
                                           force_null=self.force_null)
        file_object = io.StringIO('\n'.join(
            [*delimited_text().splitlines()[0:1], '']))

        with self.conn:
            bulk_upserter(self.conn, file_object)

        result = get_records(self.conn, self.table_name)

        self.assertEqual(self.records, result)