def __show_interface(self, database: Database) -> bool: """ Function shows a command line for this app. On receiving a command from user, it passes query to Database entity, which tries to proceed it. If Database got an Error, function prints this error. In other case, it prints a result. On \\q command from user, it simply returns False. :param database: Database :return: bool """ command = input(self.__present_command_line(database.get_name())) if command == '\q': return False database.proceed_query(command) if database.has_error(): print(database.get_error()) return True if database.get_query().get_aggregate_function() != '': print(database.get_query().get_result()[0]) else: for row in database.get_query().get_result(): join_str = ', ' print(join_str.join(row)) return True
def test_database_default(self): query = Query() database = Database('database_name', query) self.assertEqual(database.get_name(), 'database_name') self.assertEqual(database.get_tables(), {}) self.assertEqual(database.get_error(), '') self.assertEqual(database.has_error(), False) self.assertEqual(database.get_query(), query)
def test_database_setters(self): query = Query() query.set_table('tada') table = Table('table_name', []) error_text = 'some error' database = Database('database_name', query) database.add_table(table) database.set_error(error_text) self.assertEqual(database.get_name(), 'database_name') self.assertEqual(database.get_tables(), {'table_name': table}) self.assertEqual(database.get_error(), error_text) self.assertEqual(database.has_error(), True) self.assertEqual(database.get_query(), query)