Exemple #1
0
    def test_i_create_table_and_insert_data_from_csv_file_using_types_and_header(self, open_mock):
        values = (util.rand_string(), util.rand_int(), util.rand_string())
        fake_csv = 'a-text, b:integer, c/varchar:30\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=1, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Exemple #2
0
    def test_i_create_table_and_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_string(), util.rand_string(), util.rand_string())
        fake_csv = '%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_types='default', **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Exemple #3
0
    def test_i_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_int(), util.rand_string(), util.rand_string())
        fake_csv = 'id, name, value\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': 'TestDB',
                    'conn_name': self.general_conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, **kwargs)

        q = self.general_conn.execute('SELECT * FROM TestDB')
        result = q.fetchall()[1]
        self.assertEquals(result, values)
Exemple #4
0
    def test_i_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_int(), util.rand_string(), util.rand_string())
        fake_csv = 'id, name, value\n%s, %s, %s' % values
        kwargs = {
            'filename': util.rand_string(),
            'tablename': 'TestDB',
            'conn_name': self.general_conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, **kwargs)

        q = self.general_conn.execute('SELECT * FROM TestDB')
        result = q.fetchall()[1]
        self.assertEquals(result, values)
Exemple #5
0
    def test_i_create_table_and_insert_data_from_csv_file_using_header(self, open_mock):
        colnames = (tuple((element) for element in util.rand_string(5)))
        values = (util.rand_string(), util.rand_string(), util.rand_int(), round(util.rand_float(), 4), util.rand_string())
        t = colnames + values
        fake_csv = '%s, %s, %s, %s, %s\ntext, varchar:30, integer, float, char\n%s, %s, %s, %s, %s' % t
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=0, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Exemple #6
0
    def test_i_create_table_and_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_string(), util.rand_string(), util.rand_string())
        fake_csv = '%s, %s, %s' % values
        kwargs = {
            'filename': util.rand_string(),
            'tablename': util.rand_string(),
            'conn_name': self.conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_types='default', **kwargs)

        q = self.conn.execute(
            'SELECT * FROM {tn}'.format(tn=kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Exemple #7
0
    def test_i_create_table_and_insert_data_from_csv_file_using_types_and_header(
            self, open_mock):
        values = (util.rand_string(), util.rand_int(), util.rand_string())
        fake_csv = 'a-text, b:integer, c/varchar:30\n%s, %s, %s' % values
        kwargs = {
            'filename': util.rand_string(),
            'tablename': util.rand_string(),
            'conn_name': self.conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=1, **kwargs)

        q = self.conn.execute(
            'SELECT * FROM {tn}'.format(tn=kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Exemple #8
0
    def test_i_create_table_and_insert_data_from_csv_file_using_header(
            self, open_mock):
        colnames = (tuple((element) for element in util.rand_string(5)))
        values = (util.rand_string(), util.rand_string(), util.rand_int(),
                  round(util.rand_float(), 4), util.rand_string())
        t = colnames + values
        fake_csv = '%s, %s, %s, %s, %s\ntext, varchar:30, integer, float, char\n%s, %s, %s, %s, %s' % t
        kwargs = {
            'filename': util.rand_string(),
            'tablename': util.rand_string(),
            'conn_name': self.conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=0, **kwargs)

        q = self.conn.execute(
            'SELECT * FROM {tn}'.format(tn=kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)