def test_insert_encoded_by_file(self):
        append_text_to_file(
            self.filename,
            "database_name:" + b64encode(self.database_name) + "\n")
        append_text_to_file(self.filename,
                            "table_name:" + b64encode(self.table_name) + "\n")
        append_text_to_file(self.filename,
                            "delete_flag:" + b64encode("False") + "\n")
        append_text_to_file(self.filename,
                            "decode_flag:" + b64encode("True") + "\n")
        append_text_to_file(
            self.filename, "columns:" +
            "$$".join([b64encode(field) for field in self.columns]) + "\n")

        put_2darray_in_file(self.filename,
                            self.row,
                            suffix="rows:",
                            encoding="base64")
        DatabaseInsertRows.insert_by_file(self.filename,
                                          runtime_path=self.runtime_path)
        database = Database(
            self.runtime_path + "\\" + self.database_name + ".sqlite", True)

        with database:
            _, result, _ = tbl_rows_get(database, self.table_name)

        self.assertEqual(DatabaseBase._decode_2darray(result), self.row)
    def test_(self):
        append_text_to_file(
            self.filename, "columns:" +
            "$$".join([b64encode(field) for field in self.columns]) + "\n")
        rows = get_2darray_from_file(path.join(TESTDIR, "testdata.csv"))
        put_2darray_in_file(self.filename,
                            rows,
                            suffix="rows:",
                            encoding="base64")

        DatabaseInsertRows.insert_by_file(self.filename)

        database = Database(self.database_name, True)
        with database:
            columns, rows, _ = tbl_query(
                database,
                "select Description from foobar where LastName = \"" +
                b64encode("Osborn") + "\"")

        expected_results = [
            b64encode(
                "dictum mi, ac mattis velit justo nec ante. Maecenas mi felis, adipiscing fringilla, porttitor vulputate, posuere vulputate, lacus. Cras interdum. Nunc sollicitudin commodo ipsum. Suspendisse non leo. Vivamus nibh dolor, nonummy ac, feugiat non, lobortis quis, pede. Suspendisse dui. Fusce diam nunc, ullamcorper eu, euismod ac, fermentum vel, mauris. Integer sem elit, pharetra ut, pharetra sed, hendrerit a, arcu. Sed et"
            )
        ]
        self.assertListEqual(rows[0], expected_results)
    def test_insert_by_file_encoded(self):
        # encoding of input / output files
        # encoding of database content

        append_text_to_file(
            self.filename,
            "database_name:" + b64encode(self.database_name) + "\n")
        append_text_to_file(self.filename,
                            "table_name:" + b64encode(self.table_name) + "\n")
        append_text_to_file(self.filename,
                            "delete_flag:" + b64encode("False") + "\n")
        #append_text_to_file(self.filename,"decode_flag:"+b64encode("False") + "\n")
        append_text_to_file(
            self.filename, "columns:" +
            "$$".join([b64encode(field) for field in self.columns]) + "\n")

        put_2darray_in_file(self.filename,
                            self.row,
                            suffix="rows:",
                            encoding="base64")

        DatabaseInsertRows.insert_by_file(self.filename)

        database = Database(self.database_name, True)
        with database:
            _, result, _ = tbl_rows_get(database, self.table_name)

        self.assertEqual(DatabaseBase._decode_2darray(result), self.row)
        os_file_delete(self.filename)
예제 #4
0
    def setUp(self):
        self.filename = "uupyshell.txt"
        self.result_filename = environ["MYHOME"] + "\\pyshell_result.txt"
        self.datasp = DataStoredProc(path.join(TESTDIR, TESTDBNAME))
        self.encoding = "uu"
        self.columns = [
            "idStudent", "sStudentFirstNm", "sStudentLastNm", "idPrep",
            "iGradeLevel"
        ]
        self.column_defn = [('col1', 'text'), ('col2', 'text'),
                            ('col3', 'integer')]
        self.rows = [[666, 'foo', 'bar', 2, 6], [667, 'blah', 'blah', 3, 6]]
        self.row = ['idPrep', 3, 'idStudent', 666]

        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")

        append_text_to_file(
            self.filename,
            "sp_name:" + encode("insert_student", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "columns:" + "$$".join([field for field in self.columns]) + "\n")

        put_2darray_in_file(self.filename, self.rows, suffix="rows:")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)
        DataStoredProc.sp_args = {}
    def test_(self):

        rows = get_2darray_from_file(path.join(TESTDIR, "testdata_2rows.csv"))

        append_text_to_file(
            self.filename,
            "database_name:" + b64encode(self.database_name) + "\n")
        append_text_to_file(self.filename,
                            "table_name:" + b64encode(self.table_name) + "\n")
        append_text_to_file(self.filename,
                            "delete_flag:" + b64encode("False") + "\n")
        append_text_to_file(self.filename,
                            "decode_flag:" + b64encode("False") + "\n")
        append_text_to_file(
            self.filename, "columns:" +
            "$$".join([b64encode(field) for field in self.columns]) + "\n")
        append_text_to_file(
            self.filename, "column_defns:" + "$$".join([
                b64encode(_name) + "^" + b64encode(_type)
                for _name, _type in self.column_defn
            ]) + "\n")

        put_2darray_in_file(self.filename,
                            rows,
                            suffix="rows:",
                            encoding="base64")

        clsobj = DatabaseBase._parse_input_file(self.filename,
                                                mandatory_fields=[
                                                    'database_name',
                                                    'table_name',
                                                    'delete_flag',
                                                    'decode_flag', 'columns',
                                                    'column_defns'
                                                ],
                                                encoding="base64")

        self.assertEqual(clsobj.database_name, self.database_name)
        self.assertEqual(clsobj.table_name, self.table_name)
        self.assertEqual(clsobj.delete_flag, False)
        self.assertEqual(clsobj.decode_flag, False)
        self.assertEqual(clsobj.runtime_path, ".")
        self.assertEqual(clsobj.columns, self.columns)
        self.assertEqual(clsobj.column_defns, self.column_defn)
        self.assertEqual(len(clsobj.rows), 2)
        self.assertEqual(len(clsobj.rows[0]), 5)
예제 #6
0
    def test_(self):
        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")

        append_text_to_file(
            self.filename,
            "sp_name:" + encode("insert_student", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "header_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "columns:" + "$$".join([field for field in self.columns]) + "\n")

        put_2darray_in_file(self.filename, self.row, suffix="rows:")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)

        DataStoredProc.sp_args = {}

        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "sp_name:" + encode("student", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename, "sp_args:" +
            encode("<root><students>667</students></root>", self.encoding) +
            "\n")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)

        self.assertEqual(result, [[u'blah', u'blah', 667, 3, u'Aurora']])
    def test_insert_by_file(self):
        # no encoding of input / output files
        # no encoding of database content
        self.filename = "unipyshell.txt"
        append_text_to_file(self.filename,
                            "database_name:" + self.database_name + "\n")
        append_text_to_file(self.filename,
                            "table_name:" + self.table_name + "\n")
        append_text_to_file(self.filename, "delete_flag:False" + "\n")
        append_text_to_file(
            self.filename,
            "columns:" + "$$".join([field for field in self.columns]) + "\n")

        put_2darray_in_file(self.filename, self.row, suffix="rows:")

        DatabaseInsertRows.insert_by_file(self.filename)

        database = Database(self.database_name, True)
        with database:
            _, result, _ = tbl_rows_get(database, self.table_name)

        self.assertEqual(result, self.row)
        os_file_delete(self.filename)
    def setUp(self):
        self.database_name = 'foobar'
        self.table_name = 'foobar'
        self.columns = ['col1', 'col2', 'col3']
        self.column_defn = [('col1', 'text'), ('col2', 'text'),
                            ('col3', 'integer')]
        self.row = [['x', 'y', 6]]
        self.qrow = _quotestrs(self.row)
        self.filename = "b64pyshell.txt"
        self.b64row = DatabaseBase._encode_2darray(self.row)

        self.runtime_path = "C:\\Users\\burtnolej"
        append_text_to_file(
            self.filename,
            "database_name:" + b64encode(self.database_name) + "\n")
        append_text_to_file(self.filename,
                            "table_name:" + b64encode(self.table_name) + "\n")
        append_text_to_file(self.filename,
                            "delete_flag:" + b64encode("False") + "\n")
        append_text_to_file(
            self.filename, "columns:" +
            "$$".join([b64encode(field) for field in self.columns]) + "\n")
        append_text_to_file(
            self.filename, "column_defns:" + "$$".join([
                b64encode(_name) + "^" + b64encode(_type)
                for _name, _type in self.column_defn
            ]) + "\n")
        append_text_to_file(
            self.filename, "qry_str:" +
            b64encode("select col1,col2,col3 from " + self.table_name) + "\n")

        put_2darray_in_file(self.filename, self.b64row, suffix="rows:")
        DatabaseCreateTable.create_by_file(self.filename,
                                           runtime_path=self.runtime_path)
        DatabaseInsertRows.insert_by_file(self.filename,
                                          runtime_path=self.runtime_path)