Example #1
0
 def test_execute_fetchone_sql(self):
     with mock.patch('sql.sqlite3') as mocksql:
         conn = mocksql.connect()
         mocksql.connect().cursor().fetchone.return_value = 'Success'
         response = sql.execute_fetchone_sql(
             conn, """SELECT username, password FROM accounts;""")
         self.assertEqual(response, 'Success')
Example #2
0
def wrong_item_count(con):
    store_item_count = 256
    cur_item_count = sql.execute_fetchone_sql(con, sql.query_row_count())
    cur_item_count = cur_item_count[0]
    if cur_item_count >= store_item_count:
        return False
    else:
        return True
Example #3
0
    def add_item_db(self, conn, item, acc_id, inv_id):
        url = sql.execute_fetchone_sql(conn, sql.query_store_item_url(), item)
        item_value = sql.execute_fetchone_sql(conn,
                                              sql.query_store_item_value(),
                                              item)

        item_info = {
            'acc_id': acc_id,
            'char_id': self.id,
            'inv_id': inv_id,
            'item': item,
            'api': url[0],
            'value': item_value[0],
            'quantity': 1
        }

        database.add_item_row(conn, sql.add_item_row(), item_info)
Example #4
0
def load_account_object(conn, username):
    char_info_list = sql.execute_fetchone_sql(conn, sql.query_account_row(),
                                              username)
    char_info_dict = {
        'acc_id': char_info_list[0],
        'username': char_info_list[1],
        'password': char_info_list[2]
    }
    acc = Account(char_info_dict['acc_id'], char_info_dict['username'],
                  char_info_dict['password'])
    return acc
Example #5
0
def load_character_object(conn, char_name):
    char_info_list = sql.execute_fetchone_sql(conn, sql.query_character_row(),
                                              char_name)
    char_info_dict = {
        'char_id': char_info_list[0],
        'name': char_info_list[1],
        'currency': char_info_list[2]
    }
    character = Character(char_info_dict['char_id'], char_info_dict['name'],
                          char_info_dict['currency'], [])
    return character
Example #6
0
 def new_tree_item(self, some_treeview, some_callback):
     item_name = some_treeview.item(some_callback[0])['text']
     item_value = sql.execute_fetchone_sql(self.conn,
                                           sql.query_store_item_value(),
                                           item_name)
     converted_value = static_functions.convert_currency(item_value[0])
     cur_type = static_functions.inspecto_gadget(converted_value)
     new_item = self.inventory_treeview.insert(
         '', 'end', text=some_treeview.item(some_callback[0])['text'])
     static_functions.img_tag(self.inventory_treeview, new_item, cur_type)
     self.new_inventory_quantity(new_item)
     self.new_inventory_unit_value(new_item, converted_value[cur_type])
Example #7
0
 def recent_select_value(self):
     item = recent_selection['selected']
     print(item)
     item_name = None
     for treeview in self.store_treeviews:
         try:
             item_name = treeview.item(item[0])['text']
         except TclError:
             pass
     item_value = sql.execute_fetchone_sql(self.conn,
                                           sql.query_store_item_value(),
                                           item_name)
     return item_value[0]
Example #8
0
def populate_tree(some_sql, conn, some_tree, some_store):
    for number in range(
            database.count_rows(conn, sql.count_table_rows(), 'items')):
        temp_dict = {}
        number += 1
        item_info_tuple = sql.execute_fetchone_sql(conn, some_sql, str(number),
                                                   some_store)
        try:
            temp_dict['id'] = item_info_tuple[0]
            temp_dict['name'] = item_info_tuple[1]
            temp_dict['value'] = item_info_tuple[2]
            converted_value = convert_currency(temp_dict['value'])
            cur_type = inspecto_gadget(converted_value)
            some_tree.insert('',
                             'end',
                             temp_dict['id'],
                             text=temp_dict['name'])
            img_tag(some_tree, temp_dict['id'], cur_type)
            some_tree.set(temp_dict['id'], 'price', converted_value[cur_type])

        # TODO: Consider better error handling. This is a silent pass. Not good.
        except TypeError:
            continue
Example #9
0
def count_rows(conn, some_sql, some_table):
    new_sql = some_sql.format(some_table)
    count_tuple = sql.execute_fetchone_sql(conn, new_sql)
    return count_tuple[0]