def test_(self):

        expected_results = [["abc", u'version'], ["foobar", u'current']]

        with self.database:
            self.dbg.persist()
            origid = self.dbg.id

            self.dbg.update('col2', "\"foobar\"")
            _, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                          ['col2', '__version'])

        # check the value has been updated
        self.assertEqual(self.dbg.col2, "\"foobar\"")

        #check the id should have been updated
        newid = self.dbg.id
        self.assertNotEqual(newid, origid)

        # check the db representation
        self.assertListEqual(expected_results, tbl_rows)

        # check the internal dict representation
        self.assertEquals(self.dbg.dm, {
            'col1': 123,
            'col2': "\"foobar\"",
            'col3': 0x434
        })
 def test_insert(self):
     DatabaseInsertRows.insert(self.database_name, self.table_name,
                               self.columns, self.row)
     database = Database(self.database_name, True)
     with database:
         _, result, _ = tbl_rows_get(database, self.table_name)
     self.assertEqual(result, self.row)
    def test_2updates(self):

        expected_results = [[123, u'version'], [678, u'version'],
                            [91011, u'current']]

        with self.database:
            self.dbg.persist()
            origid = self.dbg.id

            self.dbg.update('col1', 678)
            self.dbg.update('col1', 91011)

            _, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                          ['col1', '__version'])

        # check the value has been updated
        self.assertEqual(self.dbg.col1, 91011)

        #check the id should have been updated
        newid = self.dbg.id
        self.assertNotEqual(newid, origid)

        # check the db representation
        self.assertListEqual(expected_results, tbl_rows)

        # check the internal dict representation
        self.assertEquals(self.dbg.dm, {'col1': 91011})
    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)
    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_dbobject_db_obj_insert(self):
        # tests that string values are wrapped in quotes
        with self.database:
            #with self.assertRaises(Exception):
            self.dbg.persist()

            col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                                 ['col1'])
            self.assertEquals([["1.1.1"]], tbl_rows)
    def test_(self):
        tbl_move(self.database1, self.database2, 'workout', remove_flag=True)

        expected_results = [[250772, u'cycling'], [260772, u'rowing']]

        with self.database2:
            _, rows, _ = tbl_rows_get(self.database2, 'workout')

        self.assertListEqual(rows, expected_results)
    def test_persist(self):
        with self.database:
            self.dbg.persist()

        self.database = Database(test_db.name, remove_flag=True)

        with self.database:
            col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                                 ['col1'])
            self.assertEquals([["abc"]], tbl_rows)
    def test_persist(self):
        with self.database:
            self.dbg.persist()

        self.database = Database(test_db.name, True)

        with self.database:
            col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                                 ['col1', 'col2', 'col3'])
            self.assertEquals([[123, 456, 789]], tbl_rows)
    def test_persist(self):

        with self.database:
            self.foobar.persist()

        self.database = Database('foobar',True)
        with self.database:
            col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['student','teacher']) 
            
            self.assertEquals([['Booker','Amelia']],tbl_rows)
Пример #11
0
    def __init__(self, dbname, tblname, fldname, **kwargs):

        database = Database(dbname)
        with database:
            rows = tbl_rows_get(database, tblname, [fldname])

            # rows is a tuple; list is element 2
            kwargs['set'] = [row[0] for row in rows[1]]

        super(DBSetMember, self).__init__(**kwargs)
        self.validations.append(_SetMemberVdt(**kwargs))
    def test_insert_encoded(self):
        DatabaseInsertRows.insert(self.database_name,
                                  self.table_name,
                                  self.columns,
                                  self.row,
                                  encoding="base64")
        database = Database(self.database_name, True)
        with database:
            _, result, _ = tbl_rows_get(database, self.table_name)

        self.assertEqual(DatabaseBase._decode_2darray(result), self.row)
    def test_persist_customtimestamp(self):
        
        self.foobar.customtimestamp = "%y%m%d_%H%M%S"
        with self.database:
            self.foobar.persist()

        self.database = Database('foobar',True)
        with self.database:
            col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['__timestamp']) 
            
            self.assertTrue(13,len(tbl_rows[0][0]))
    def test_dbobject_db_str_insert(self):
        # tests that string values are wrapped in quotes
        with self.database:
            #with self.assertRaises(S3OperationalError):
            self.dbg.persist()

        self.database = Database(test_db.name, remove_flag=True)

        with self.database:
            col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                                 ['col1'])
            self.assertEquals([["foobar"]], tbl_rows)
    def test_dbobject_assert_id(self):
        from datetime import datetime
        with self.database:
            self.dbg.persist()
        self.database = Database(test_db.name, remove_flag=True)
        with self.database:
            col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                                 ['__timestamp', '__id'])
            dt = datetime.strptime(tbl_rows[0][0], "%H:%M:%S")

            self.assertAlmostEqual(datetime.now().min, dt.min)
            self.assertAlmostEqual(datetime.now().hour, dt.hour)
            self.assertAlmostEqual(datetime.now().second, dt.second)
Пример #16
0
    def test_(self):
        expected_results = [[666, u'foo', u'bar'], [667, u'blah', u'blah']]
        rows = [[666, "\"foo\"", "\"bar\""], [667, "\"blah\"", "\"blah\""]]
        _insert_student(self.database, rows)

        with self.database:
            _, results, _ = tbl_rows_get(
                self.database,
                "Student",
                fields=["idStudent", "sStudentFirstNm", "sStudentLastNm"],
                whereclause=[["idStudent", "in", "(666,667)"]])

        self.assertEqual(results, expected_results)
        _delete_student(self.database, [666, 667])
    def test_update_1field(self):
        
        expected_results = [[u'830', u'AM.AC.SC', u'Booker', u'Amelia', u'version'], 
                            [u'830', u'AM.AC.SC', u'Booker', u'Aaron', u'current']]
        self.foobar.customtimestamp = "%y%m%d_%H%M%S"
        with self.database:
            self.foobar.persist()
            self.foobar.update('teacher',"\"Aaron\"")

        self.database = Database('foobar',True)
        with self.database:
            col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['period','session','student','teacher','__version'] ) 
            
            self.assertListEqual(tbl_rows,expected_results)
    def test_tbl_rows_get_all(self):

        database = Database(test_db.name)

        with database:
            tbl_create(database, test_db.tbl_name, test_db.col_defn)
            tbl_rows_insert(database, test_db.tbl_name, test_db.col_name,
                            test_db.tbl_rows)

        database = Database(test_db.name, remove_flag=True)
        with database:
            col_name, tbl_rows, _ = tbl_rows_get(database, test_db.tbl_name)
            self.assertListEqual(col_name, test_db.col_name)
            self.assertListEqual(tbl_rows, test_db.tbl_rows)
Пример #19
0
    def test_(self):

        expected_results = [[666, 2, 6], [667, 3, 6]]
        # 2=Luna
        rows = [[666, 2, 6], [667, 3, 6]]
        _insert_student_level(self.database, rows)
        with self.database:
            _, results, _ = tbl_rows_get(
                self.database,
                "StudentLevel",
                fields=["idStudent", "idPrep", "iGradeLevel"],
                whereclause=[["idStudent", "in", "(666,667)"]])

        self.assertEqual(results, expected_results)
        _delete_student_level(self.database, [666, 667])
    def test_tbl_rows_get_spoecific_field(self):

        database = Database(test_db.name)

        with database:
            tbl_create(database, test_db.tbl_name, test_db.col_defn)
            tbl_rows_insert(database, test_db.tbl_name, test_db.col_name,
                            test_db.tbl_rows)

        database = Database(test_db.name, remove_flag=True)
        with database:
            col_name, tbl_rows, _ = tbl_rows_get(
                database, test_db.tbl_name,
                ['col_name1', 'col_name2', 'col_name3', 'col_name4'])
            self.assertListEqual(col_name, test_db.col_name)
            self.assertListEqual(tbl_rows, test_db.tbl_rows)
    def test_tbl_rows_insert_from_schema(self):

        schema_execute(self.schema_file)

        database = Database('fitness')

        with database:
            tbl_rows_insert_from_schema(database, self.schema_file, 'workout')

        database = Database('fitness', remove_flag=True)

        with database:
            tbl_col_name, tbl_rows, _ = tbl_rows_get(database, 'workout')
            self.assertListEqual(tbl_rows,
                                 [[250772, 'cycling'], [260772, 'rowing']])

        # this is there to force the delete of the 2nd db created but does
        database = Database('diet', True)
        with database:
            pass
    def test_str(self):

        expected_results = [[123, u'version'], ["def", u'current']]

        with self.database:
            self.dbg.persist()
            origid = self.dbg.id

            self.dbg.update('col1', "\"def\"")

            _, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest',
                                          ['col1', '__version'])

        # check the value has been updated
        self.assertEqual(self.dbg.col1, "\"def\"")

        #check the id should have been updated
        newid = self.dbg.id
        self.assertNotEqual(newid, origid)

        # check the db representation
        self.assertListEqual(expected_results, tbl_rows)
    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)
Пример #24
0
    def test_schema_insert_rows(self):

        datarows = {'tbl_col_name': [], 'tbl_rows': []}

        schema_data_get(self.schema_file, 'workout', datarows)

        database = Database('fitness')

        with database:
            tbl_rows_insert(database, 'workout', datarows['tbl_col_name'],
                            datarows['tbl_rows'])

        database = Database('fitness', True)

        with database:
            colnames, rows, _ = tbl_rows_get(database, 'workout',
                                             ['date', 'type'])
            self.assertListEqual(rows,
                                 [[250772, u'cycling'], [260772, u'rowing']])

        database = Database('diet', True)
        with database:
            pass