Example #1
0
def initialize_database():
    ''' Delete and initialize tables for app to work properly
    '''
    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)
 def test_find_all_replace_data_entries_works(self):
     program_service.create_replace_data(self._filename,
                                         self._user_input_data,
                                         self._placeholder)
     program_service.create_replace_data(self._filename2,
                                         self._user_input_data2,
                                         self._placeholder2)
     program_service.create_replace_data(self._filename,
                                         self._user_input_data2,
                                         self._placeholder2)
     replace_data_entries = program_service.find_all_replace_data_entries()
     self.assertEqual(self._filename2, replace_data_entries[0].filename)
     self.assertEqual(self._user_input_data2,
                      replace_data_entries[0].user_input_data)
     self.assertEqual(self._placeholder2,
                      replace_data_entries[0].placeholder)
     self.assertEqual(self._filename, replace_data_entries[1].filename)
     self.assertEqual(self._user_input_data,
                      replace_data_entries[1].user_input_data)
     self.assertEqual(self._placeholder,
                      replace_data_entries[1].placeholder)
     self.assertEqual(self._filename, replace_data_entries[2].filename)
     self.assertEqual(self._user_input_data2,
                      replace_data_entries[2].user_input_data)
     self.assertEqual(self._placeholder2,
                      replace_data_entries[2].placeholder)
     drop_tables(get_database_connection())
Example #3
0
def initialise_database():
    # Create a database connection
    print("Creating database connection")
    connection = get_database_connection()

    # Create tables
    create_tables(connection)
 def test_create_replace_data_works(self):
     replace_data = program_service.create_replace_data(
         self._filename, self._user_input_data, self._placeholder)
     self.assertEqual(self._filename, replace_data.filename)
     self.assertEqual(self._user_input_data, replace_data.user_input_data)
     self.assertEqual(self._placeholder, replace_data.placeholder)
     drop_tables(get_database_connection())
 def recycle_list_all(self):
     '''getting the amount of items recycled by all users'''
     connection = get_database_connection()
     get_recycle_all = connection.execute(
         'select sum(bottles_cans), sum(cardboard), sum(electronics), sum(glass), sum(metal), sum(plastic), sum(paper), sum(batteries), sum(clothes) from recycle'
     ).fetchone()
     return get_recycle_all
def initialize_database():
    """Funktio, joka suorittaa tietokannan alustuksen
    """
    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)
def initialize_database():
    connection = get_database_connection()

    drop_tables(connection)
    tracker_service.delete_courses()
    tracker_service.delete_notes()
    create_tables(connection)
def initialize_database():
    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)

    connection.close()
Example #9
0
def initialize_database():
    """Luo tietokantayhteyden sekä poistaa siellä mahdollisesti olevat taulut ja luo uudet.
    """

    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)
def initialize_database():
    """Alustaa tietokantataulut.
    """

    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)
 def test_document_exists_works(self):
     program_service.create_replace_data(self._filename,
                                         self._user_input_data,
                                         self._placeholder)
     self.assertEqual(program_service.document_exists(self._filename2),
                      True)
     self.assertEqual(program_service.document_exists("kana"), False)
     drop_tables(get_database_connection())
def initialize_database():
    """Initializes the database by establishing a connection
    to SQL-database, and then creating new data tables.
    """

    connection = get_database_connection()

    drop_tables(connection)
    create_tables(connection)
 def setUp(self):
     drop_tables(get_database_connection())
     initialize_database()
     self._filename = "viranhaltijapäätös_määräalan_myynti_pohja"
     self._filename2 = "Testipohja"
     self._user_input_data = "Kiinteistötunnus"
     self._user_input_data2 = "Ostaja"
     self._placeholder = "[kiinteistötunnus]"
     self._placeholder2 = "[ostaja]"
Example #14
0
    def initialize_database(self):
        """Tuhoaa nykyiset taulut tietokannasta, 
        jonka jälkeen luo ne uudelleen ja lisää testikäyttäjän.
        """
        connection = get_database_connection()
        connection.isolation_level = None

        self.drop_tables(connection)
        self.create_tables(connection)
        self.insert_test_user(connection)
Example #15
0
def main():
    """Function for running the application"""
    config = Config(CONFIG_PATH)

    screen = Screen(config.window_width, config.window_height,
                    config.font_size)
    event_handler = EventHandler()
    database_connection = get_database_connection(config.database_path)
    main_menu = create_main_menu(screen, event_handler, config,
                                 database_connection)
    main_menu.run()
 def recycle_list(self):
     '''getting the amount of items recycled from the database matching with the current user'''
     connection = get_database_connection()
     username = self._user.username
     username_id = connection.execute(
         'select id from users where username = ?',
         (username, )).fetchone()[0]
     get_recycle = connection.execute(
         'select bottles_cans, cardboard, electronics, glass, metal, plastic, paper, batteries, clothes from recycle where username_id = ?',
         (username_id, )).fetchone()
     return get_recycle
Example #17
0
def init_database(database_path):
    """Initializes a database at `database_path`.

    Arguments:
        `database_path`: Path
            Should be either an existing file or a non-existing
            file in an existing directory
    """
    connection = get_database_connection(database_path)

    drop_tables(connection)
    create_tables(connection)
Example #18
0
def trigger(user_id, friend_id):
    connection, cursor = database_connection.get_database_connection()

    cursor.execute("LISTEN status_changed;")

    while True:
        select.select([connection], [], [])
        connection.poll()

        while connection.notifies:
            cursor.execute("SELECT state FROM users WHERE id = " +
                           str(user_id))
            return {"state": cursor.fetchall()[0][0]}
 def recycle_list_update(self, amount, what_to_update):
     '''update amount of material recycled'''
     connection = get_database_connection()
     username = self._user.username
     username_id = connection.execute(
         'select id from users where username = ?',
         (username, )).fetchone()[0]
     connection.execute(
         'update recycle set {} = ({}+?) where username_id = ?'.format(
             what_to_update, what_to_update), (
                 amount,
                 username_id,
             ))
     connection.commit()
 def test_find_all_document_names_works(self):
     program_service.create_replace_data(self._filename,
                                         self._user_input_data,
                                         self._placeholder)
     program_service.create_replace_data(self._filename2,
                                         self._user_input_data2,
                                         self._placeholder2)
     program_service.create_replace_data(self._filename,
                                         self._user_input_data2,
                                         self._placeholder2)
     document_names = program_service.find_all_document_names()
     self.assertEqual(self._filename, document_names[0])
     self.assertEqual(self._filename2, document_names[1])
     drop_tables(get_database_connection())
 def test_placeholder_duplicate_exists_works(self):
     program_service.create_replace_data(self._filename,
                                         self._user_input_data,
                                         self._placeholder)
     self.assertEqual(
         program_service.placeholder_duplicate_exists(
             self._filename, self._placeholder), True)
     self.assertEqual(
         program_service.placeholder_duplicate_exists(
             "Nikko", self._placeholder), False)
     self.assertEqual(
         program_service.placeholder_duplicate_exists(
             self._filename, "Auto"), False)
     self.assertEqual(
         program_service.placeholder_duplicate_exists("Nikko", "Auto"),
         False)
     drop_tables(get_database_connection())
Example #22
0
 def __init__(self, username):
     """Luokan konstruktori. Luo päävalikon valinnat
     Args:
         username: kirjautuneen käyttäjän nimi
     """
     self._actions = {
         "x": "x Lopeta",
         "1": "1 Uusi kurssi",
         "2": "2 Hae kurssit",
         "3": "3 Poista kurssi",
         "4": "4 Muuta tietoja",
         "5": "5 Syötä tenttipäivämäärä",
         "6": "6 Ilmoittaudu kurssille",
         "7": "7 Tulevat tenttini"
     }
     self._headers = ["Kurssi", "Opintopisteet"]
     self._ui = UI()
     self._repository = CourseRepository(get_database_connection())
     self._username = username
Example #23
0
    def __init__(self, display: Display, letters: list, status: int,
                 event_queue, word, level):
        """Luokan konstruktori, joka luo uuden pelin

        Args:
            display (Display): Display-olio, joka kuvaa pelialuetta
            letters (list): Kirjainten sijannit peliruudulla [x, y, letter, used (True/False)]
            status (int): Tämänhetkinen pelitilanne, kuinka monta kertaa käyttäjä arvannut väärin
            event_queue (EventQueue): EventQueue-olio, joka kuvaa pelin tapahtumia
            word (str): Arvattava sana
            level: Vaikeustaso
        """
        self.display = display
        self.letters = letters
        self.status = status
        self.guessed = []
        self.event_queue = event_queue
        self.word = word
        self.clock = Clock()
        self.level = level
        self.highscore = Highscore(get_database_connection())
def initialize_database():
    '''do everything needed for using the app'''
    connection = get_database_connection()
    drop_tables(connection)
    adminpass = input("Give a password for the admin account: ")
    create_tables(connection, adminpass)
        """
        cursor = self._connection.cursor()

        cursor.execute(
            "DELETE FROM Replace_data WHERE document_name = ? AND placeholder = ?",
            (
                filename,
                placeholder,
            ))

        self._connection.commit()

        cursor.execute(
            """
            SELECT document_name, placeholder
            FROM Replace_data
            WHERE document_name = ? AND placeholder = ?
            """, (
                filename,
                placeholder,
            ))

        result = cursor.fetchone()

        if result is None:
            return True
        return False


database_handler = DatabaseHandler(get_database_connection())
 def setUp(self):
     initialize_database()
     self._user = UserRepository(get_database_connection())
     configure()
Example #27
0
        '''
        cursor = self._connection.cursor()

        cursor.execute('SELECT * FROM Scores ORDER BY score DESC LIMIT 10')

        high_scores = cursor.fetchall()

        return high_scores

    def delete_all(self):
        '''Poistaa tiedot tietokannasta
        '''
        cursor = self._connection.cursor()

        cursor.execute('DELETE FROM Scores')

        self._connection.commit()

    def add_new_score(self, name, score):
        '''Kirjaa uuden pelituloksen ja pelaajanimen tietokantaan
        '''
        cursor = self._connection.cursor()

        cursor.execute(
            'INSERT INTO Scores (name, score) VALUES (?, ?)', (name, score))

        self._connection.commit()


score_repository = ScoreRepository(get_database_connection())
        cursor.execute(
            'select * from users where username = ?',
            (username,)
        )

        row = cursor.fetchone()

        return get_user_by_row(row)

    def create(self, user):
        cursor = self.connection.cursor()

        cursor.execute(
            'insert into users (username, password) values (?, ?)',
            (user.username, user.password)
        )

        self.connection.commit()

        return user

    def delete_all(self):
        cursor = self.connection.cursor()

        cursor.execute('delete from users')

        self.connection.commit()


user_repository = UserRepository(get_database_connection())
Example #29
0
    def __init__(self):
        """Konstruktori, alustaa tietokanta-yhteyden ja käytetyn cursor-objektin."""

        self.connection = get_database_connection()
        self.cursor = self.connection.cursor()
Example #30
0
        self._connection.commit()

    def find_all(self):
        """ Select all cubes from the cubes table.
        Return:
            rows: [List Tuple] List of tuples including the cubes.
        """

        cursor = self._connection.cursor()
        cursor.execute('SELECT * FROM cubes')
        rows = cursor.fetchall()
        return rows

    def find_by_user(self, username):
        """ Select cubes from the cubes table that belong to the given username.
        Args:
            username: [String] The username of a user.
        Return:
            rows: [List Tuple] List of tuples including the cubes.
        """

        user_sql = (username, )
        sql = """ SELECT * FROM cubes WHERE users = ?; """
        cursor = self._connection.cursor()
        cursor.execute(sql, user_sql)
        rows = cursor.fetchall()
        return rows


cube_repository = CubeRepository(get_database_connection())