Ejemplo n.º 1
0
    def test_import_data(self):
        """testing import for three cases, empty, correct, repetitive"""
        database.clear()
        #test that the file not found error works for all three fake files
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'prod_none.csv',
                                                       'cust_none.csv',
                                                       'rental_none.csv')
        self.assertEqual(test_count, (0, 0, 0))
        self.assertEqual(test_errors, (1, 1, 1))
        #test the actual files are imported properly without errors
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'products.csv',
                                                       'customers.csv',
                                                       'rentals.csv')

        self.assertEqual(test_count, (5, 10, 10))
        self.assertEqual(test_errors, (0, 0, 0))

        #database not cleared and same files are imported, should raise duplicate errors
        #as long as the original file
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'products.csv',
                                                       'customers.csv',
                                                       'rentals.csv')

        self.assertEqual(test_errors, (5, 10, 10))
        database.clear()
Ejemplo n.º 2
0
    def test_show_available_products(self):
        """Test show_available_products"""
        # Clear the database
        database.clear()
        expected_data = {
            'prd001': {
                'description': 'table',
                'product_type': 'diningroom',
                'quantity_available': '2'
            },
            'prd002': {
                'description': 'lamp',
                'product_type': 'office',
                'quantity_available': '3'
            },
            'prd003': {
                'description': 'desk',
                'product_type': 'office',
                'quantity_available': '1'
            },
            'prd005': {
                'description': 'shovel',
                'product_type': 'yard',
                'quantity_available': '5'
            }
        }

        database.import_data(os.getcwd(), 'products.csv', 'customers.csv',
                             'rentals.csv')
        return_dict = database.show_available_products()
        self.assertEqual(expected_data, return_dict)
        database.clear()
Ejemplo n.º 3
0
def refresh_data(sport=None):
    if sport:        
        database.clear('roster', sport)
        
        url = urllib.request.urlopen(URL['ATHLETICS_URL']
                                   + URL['SCHEDULE_PATH'] + sport)
        content = url.read().decode('utf8')
        url.close()

        soup = BeautifulSoup(content)
        schedule = soup.find_all("div", "schedule_game")
        
        scheduled_games = []
        
        for game in schedule:
            scheduled_game = ScheduledGame()
            if (game.find("div", "schedule_game_opponent_name")):
                scheduled_game.setSport(sport)
                if game.find("div", "schedule_game_opponent_name").a.span:
                    scheduled_game.setTeam(game.find("div", "schedule_game_opponent_name").a.span.string)
                else:
                    scheduled_game.setTeam(game.find("div", "schedule_game_opponent_name").get_text())
                scheduled_game.setDate(game.find("div", "schedule_game_opponent_date").string)
                scheduled_game.setTime(game.find("div", "schedule_game_opponent_time").string)
                scheduled_game.setLocation(game.find("div", "schedule_game_middle").get_text())
                scheduled_game.setTeam(game.find("div", "schedule_game_opponent_name").get_text())
                scheduled_game.setImage(game.find("div", "schedule_game_opponent_logo").img['src'])
                
                if (game.find("div", "schedule_game_results")):
                    scheduled_game.setScore(game.find("div", "schedule_game_results").contents[1].get_text())
                
                database.save(scheduled_game)
Ejemplo n.º 4
0
    def run(self):
        #database.lock(self.data['SOURCEIP'])
        varBinds, err = snmp.get(self.conn, snmp.sysObjectID)
        if err:
            database.release(self.data['SOURCEIP'])
            return False
        else:
            sprint("Start Thread for device", self.data['SOURCEIP'],
                   varBinds[0][1].prettyPrint())
            if varBinds[0][1][6] == 9:
                backup_class = BackupDeviceCISCO
            elif varBinds[0][1][6] == 890:
                backup_class = BackupDeviceZyXEL
            else:
                eprint("Unknown device vendor", self.data['SOURCEIP'],
                       varBinds[0][1].prettyPrint())
                database.update_vendor_oid(self.data['SOURCEIP'],
                                           str(varBinds[0][1].prettyPrint()))
                database.release(self.data['SOURCEIP'])
                return False

        with backup_class(varBinds, self.data, self.conn) as backup:
            if backup.run():
                if backup.save() and config.compare:
                    backup.compare()
                database.clear(self.data['SOURCEIP'])
            else:
                eprint("Backup", self.data['SOURCEIP'], "error")
        database.release(self.data['SOURCEIP'])
Ejemplo n.º 5
0
 def test_db():
     try:
         database.clear()
         print('Table Cleared')
         database.add(t1)
         print(f'{t1} has been added to the UserInfo Table')
         click_sound.play()
     except:
         print('Error Found')
Ejemplo n.º 6
0
def index(sport=None):
    if sport:
        database.clear('schedule', sport, CACHE_LEN['SCHEDULE'])
        schedule = database.getSchedule(sport)
        if not schedule:
            refresh_data(sport)
            schedule = database.getSchedule(sport)
        schedule_json = [event.toJSON() for event in schedule]
        return {'events' : schedule_json}
Ejemplo n.º 7
0
def index(sport=None):
    if sport:
        database.clear('teampic', sport, CACHE_LEN['TEAM_PIC'])
        
        team_pic = database.getTeamPic(sport)
        if not team_pic:
            pic_url = refresh_data(sport)
            return {'url' : pic_url}
        else:
            return {'url' : team_pic}
Ejemplo n.º 8
0
 def test_show_rentals(self):
     """Test show_rentals function"""
     # Clear the database
     database.clear()
     expected_data = {'cust003': {'name': 'Kim', 'address': '2132 Back St',
                                  'phone_number': '3432019212', 'email': '*****@*****.**'},
                      'cust008': {'name': 'Lisa', 'address': '929 Court Rd',
                                  'phone_number': '7474738902', 'email': '*****@*****.**'}}
     database.import_data(os.getcwd(), 'products.csv', 'customers.csv', 'rentals.csv')
     return_dict = database.show_rentals('prd001')
     self.assertEqual(expected_data, return_dict)
     database.clear()
Ejemplo n.º 9
0
def index(sport=None):
    if sport:
        database.clear('roster', sport, CACHE_LEN['ROSTER'])
        
        players = database.getRoster(sport)
        
        if not players:
            print("Pulling fresh data")
            refresh_data(sport)
            players = database.getRoster(sport)
        players_json = [p.toJSON() for p in players]
        return {'players' : players_json}
Ejemplo n.º 10
0
def refresh_data(sport=None):
    if sport:
        database.clear('roster', sport)
        
        url = urllib.request.urlopen(URL['ATHLETICS_URL']
                                   + URL['ROSTER_PATH'] + sport)
        content = url.read().decode('utf8')
        url.close()

        soup = BeautifulSoup(content)
        
        team_pic = TeamPic()
        team_pic.setSport(sport)
        if soup.find(id=ID['TEAM_PIC_ID']):
            team_pic.setUrl(soup.find(id=ID['TEAM_PIC_ID'])['src'])
            database.save(team_pic)
    
            return team_pic.getPic()
    return None
Ejemplo n.º 11
0
def refresh_data(sport=None):
    if sport:
        database.clear('roster', sport)
        
        url = urllib.request.urlopen(URL['ATHLETICS_URL']
                                   + URL['ROSTER_PATH'] + sport)
        content = url.read().decode('utf8')
        url.close()

        soup = BeautifulSoup(content)
        player_table = soup.find(id=ID['ROSTER_TABLE_ID'])
        player_rows = player_table.find_all('tr')

        for row in player_rows:
            player = process_player_row(row.find_all('td'), sport)
            if player:
                database.save(player)

        return index(sport);
    return False
Ejemplo n.º 12
0
#! This program can keep your passwords encrypted
""" With this program, you can keep all your passwords in safety.

    Commands: help, add, remove, find, change, showall, clear """

import database as data

while True:
    task = str(input("Enter a command here: "))
    if task == 'help':
        print(__doc__)
    elif task == 'add':  # Добавления данных в словарь
        a = input(str("Enter resource: "))
        b = input(str("Enter password: "******"Enter a key: "))
        data.remove(a)
    elif task == 'find':  # Поиск данных в словаре
        a = input(str("Enter a key:"))
        data.find(a)
    elif task == 'change':  # Изменение данных в словаре
        a = input(str("Enter a key you want to rename: "))
        data.change(a)
    elif task == 'showall':  # Показать все данные в словаре
        data.showall()
    elif task == 'clear':
        data.clear()
    else:
        print("No such command %30s" % task)
Ejemplo n.º 13
0
def run_around_tests():
    database.clear()
    yield
Ejemplo n.º 14
0
def main_menu():
    def menumap(display):
        # Tile Map Rendering
        tile_rects = []
        heart_lst = []
        enemy_lst = []
        y = 0
        for row in t.menu_map:
            x = 0
            for tile in row:
                if tile == 1:
                    display.blit(t.dirt1_img.convert_alpha(),
                                 (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30))
                if tile == 2:
                    display.blit(t.grass_img.convert_alpha(),
                                 (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30))

                if tile == 3:
                    display.blit(t.dirt2_img.convert_alpha(),
                                 (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    sushi_rect = pg.Rect(x * 30, y * 30, 30, 30)
                    heart_lst.append(sushi_rect)
                    # pg.draw.rect(display, (255,0,0), sushi_rect, 2)

                if (tile == 4):
                    # display.blit(display, ((x * 30 - s.scroll[0], y * 30 - s.scroll[1])))
                    sushi_img = display.blit(
                        t.sushi.convert_alpha(),
                        (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    heart_rect = pg.Rect(x * 30 + 21, y * 30 + 30, 40, 40)
                    heart_lst.append(heart_rect)

                if tile == 5:
                    display.blit(t.enemy.convert_alpha(),
                                 (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    enemy_rect = pg.Rect(x * 30, y * 30 + 10, 35, 45)
                    enemy_lst.append(enemy_rect)

                    # pg.draw.rect(display, (255,255,0), enemy_rect, 2)
                    # Uncomment the below line to see tile rects
                    # pg.draw.rect(display, (255, 0, 0), pg.Rect(x * 30, y * 30, 30, 30), 2)
                if tile == 6:
                    display.blit(t.sand_img.convert_alpha(),
                                 (x * 30 - s.scroll[0], y * 30 - s.scroll[1]))
                    tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30))
                x += 1
            y += 1

    def button(screen, position, text, size):
        font = pg.font.SysFont("Cambria", size)
        text_render = font.render(text, True, (255, 0, 0))
        x, y, w, h = text_render.get_rect()
        x, y = position
        pg.draw.rect(screen, (120, 120, 200), (x - 5, y - 5, w + 10, h + 10))
        pg.draw.rect(screen, (140, 140, 200), (x, y, w, h))
        return screen.blit(text_render, (x, y))

    def Entry(text, x, y, base_font=pg.font.Font(None, 30)):
        rect = pg.Rect((x, y, 400, 32))
        color = (255, 0, 0)
        pg.draw.rect(screen, color, rect, 2)
        text_surface = base_font.render(text, True, (255, 255, 255))
        screen.blit(text_surface, (rect.x + 5, rect.y + 5))
        return rect

    def Label(text, x, y, base_font=pg.font.Font(None, 30)):
        text_surface = base_font.render(text, True, (255, 0, 0))
        screen.blit(text_surface, (x, y))

    screen = pg.display.set_mode((1000, 600))
    pg.display.set_caption(s.title)
    bg = pg.image.load('png files/Menu bg.png')
    bg = pg.transform.scale(bg, (1000, 600))
    type_sound = pg.mixer.Sound('Sounds/type2.wav')
    click_sound = pg.mixer.Sound('Sounds/Type.wav')
    icon = pg.image.load(
        'png files/Still Animation/Still Character Animation1.png')
    pg.display.set_icon(icon)

    if len(database.show()) == 0:
        t1 = ''
    else:
        t1 = (database.show()[0])[0]
    run = True
    while run:
        screen.blit(bg, (0, 0))
        menumap(screen)
        text_entry = Entry(t1, 300, 50)
        Label('Enter Name', 420, 100)
        b1 = button(screen, (350, 125), 'Start Game', 50)
        clear_btn = button(screen, (710, 55), 'Clear Text', 20)
        for event in pg.event.get():
            if event.type == pg.QUIT:
                pg.quit()
                sys.exit()
            if event.type == pg.MOUSEBUTTONDOWN:
                if b1.collidepoint(pg.mouse.get_pos()):
                    database.clear()
                    database.add(t1)
                    click_sound.play()
                    main_Game()

                if clear_btn.collidepoint(pg.mouse.get_pos()):
                    t1 = ''
                    type_sound.play()
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_BACKSPACE:
                    type_sound.play()
                    t1 = t1[0:-1]
                else:
                    type_sound.play()
                    t1 += event.unicode
        pg.display.update()
    pg.quit()
Ejemplo n.º 15
0
@app.route('/api/records/<record_id>', methods=['DELETE'])
def api_records_delete(record_id):
    database.delete(record_id)
    return ""


@app.route('/api/records', methods=['POST'])
def api_records_create():
    location = request.json['location']
    storedRecord = database.add(location)
    return jsonify(storedRecord), 201


if __name__ == '__main__':
    database.clear()

    # Initial last seen records
    database.add('Fenway Park')
    database.add('Faneuil Hall')
    database.add('Google Cambridge Office')

    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

    app.run(host='0.0.0.0',
            port=8080,
            debug=True,
            extra_files=[
                'templates/index.html', 'static/css/styles.css',
                'static/js/main.js', 'static/img/delete.png'
            ])
Ejemplo n.º 16
0
def test_clear_db():
    txt = '5G burns cookies!'
    database.add('key5', txt)
    database.clear()
    assert database.get('key5') is None
Ejemplo n.º 17
0
def clear_DB():
    database.clear()