Ejemplo n.º 1
0
    def test_try_to_make_table_if_database_is_not_setup(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        tablename = 'test_table'
        columns = "column1, column2, column3"
        createdColumns = db.create_table(tablename, columns)
        self.assertEqual(len(createdColumns), 0)
Ejemplo n.º 2
0
    def test_appending_data_when_database_not_created(self):

        newtablename = 'notImportant'
        db = SQHelper('/usr/test_db.sql')  # Bad db name
        data = [123456]
        inserted = db.insert(newtablename, data)
        self.assertIs(inserted, False)
Ejemplo n.º 3
0
    def test_getting_last_timestamp_entry_from_database_which_is_not_created(
            self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name

        lastStoredEntry = db.get_last_time_entry("bad_table_name")
        expectedEntry = None
        self.assertEqual(lastStoredEntry, expectedEntry)
Ejemplo n.º 4
0
    def test_getting_dataframe_from_table_no_database_made(self):

        newtablename = 'notImportant'
        db = SQHelper('/usr/test_db.sql')  # Bad db name

        df = db.table_to_df(newtablename)

        self.assertIs(df, None)
Ejemplo n.º 5
0
 def __setup_database(self):
     fileLocation = os.path.join(self.__workingDirectory,
                                 settings.data_file_directory,
                                 settings.database_file_name)
     database = SQHelper(fileLocation)
     if not database.exists():
         log.critical("Failed to create required database file, exiting")
         raise
     return database
Ejemplo n.º 6
0
    def test_print_table_with_no_database(self):

        newtablename = 'notImportant'
        db = SQHelper('/usr/test_db.sql')  # Bad db name

        old_stdout = sys.stdout
        sys.stdout = printOutput = StringIO()
        db.print_table(newtablename)
        sys.stdout = old_stdout

        expectedOutput = ''
        self.assertEqual(expectedOutput, printOutput.getvalue().strip('\n'))
Ejemplo n.º 7
0
    def test_get_range_of_rows_with_no_created_database(self):

        newtablename = 'notImportant'
        db = SQHelper('/usr/test_db.sql')  # Bad db name
        df = db.get_row_range(newtablename, 'value', 12, 89)
        self.assertIs(df, None)
Ejemplo n.º 8
0
 def test_creating_database_and_test_if_exits_in_nested_directory(self):
     db = SQHelper('non/existant/directory/db_name.sql')
     exists = db.exists()
     self.assertIs(exists, False)
Ejemplo n.º 9
0
    def test_remove_row_range_database_doesnt_exist(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        removed = db.remove_row_range('not_important', 'value', 63.3, 63.3)
        self.assertEqual(removed, False)
Ejemplo n.º 10
0
 def test_creating_database_and_test_if_exits_bad_name_database_already_exists(
         self):
     db = SQHelper('tests')  # Same name as tests directory
     exists = db.exists()
     self.assertIs(exists, False)
Ejemplo n.º 11
0
    def test_removing_a_table_with_no_database_created_does_nothing(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        removed = db.remove_table('some_name')
        self.assertIs(removed, False)
Ejemplo n.º 12
0
    def test_getting_columns_names_with_no_database_created(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        columns = db.get_column_names('some_table')
        self.assertEqual(columns, [])
Ejemplo n.º 13
0
    def test_getting_table_names_if_no_database_exists(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        tableNames = db.get_table_names()
        self.assertEqual(tableNames, [])
Ejemplo n.º 14
0
 def setUp(self):
     self.db = SQHelper(test_db_name)
     pass
Ejemplo n.º 15
0
    def test_get_row_matching_value_when_table_doesnt_exist(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name

        df = db.get_row("doesnt_exist", 'value', '43.3')
        self.assertIs(df, None)
Ejemplo n.º 16
0
 def test_creating_database_and_test_if_exits_bad_permissions(self):
     db = SQHelper('/usr/test_db.sql')
     exists = db.exists()
     self.assertIs(exists, False)
Ejemplo n.º 17
0
    def test_get_last_rows_database_doesnt_exist(self):

        db = SQHelper('/usr/test_db.sql')  # Bad db name
        self.insertFourUniqueEntries('not_important')
        df = db.get_last_rows('not_important', 1)
        self.assertEqual(df, None)