Exemplo n.º 1
0
 def test_should_have_correct_poke_columns(self):
     my_set_sheet = PokemonSetSheet.create(
         test_pokemon_set, 'tests/data/test_pokemon_excel_sheet.xlsx')
     assert_column_is_in_sheet(PokeColumn('Card #', 1), my_set_sheet)
     assert_column_is_in_sheet(PokeColumn('4 Owned', 2), my_set_sheet)
     assert my_set_sheet.is_poke_column_in_columns(
         PokeColumn('CardZ #99 bloppp', 40)) is False
Exemplo n.º 2
0
 def test_update_missing_pokemon_metadata__calls_tcg_api(self, mock_get_cards_from_database):
     test_path = 'tests/data/test_update_missing_metadata.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set, excel_copy_path(test_path))
     update_missing_pokemon_metadata(my_set_sheet)
     mock_get_cards_from_database.assert_called_once_with(test_pokemon_set, [1, 2, 3, 4])
     os.remove(excel_copy_path(test_path))
Exemplo n.º 3
0
 def test_update_missing_pokemon_metadata__does_not_call_tcg_api_when_all_required_columns_are_filled \
                 (self, mock_get_cards_from_database):
     test_path = 'tests/data/test_update_missing_metadata__not_called__required_columns_filled.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set, excel_copy_path(test_path))
     update_missing_pokemon_metadata(my_set_sheet)
     mock_get_cards_from_database.assert_not_called_with(test_pokemon_set, [2])
     os.remove(excel_copy_path(test_path))
Exemplo n.º 4
0
 def test_get_card_numbers_in_sheet(self):
     test_path = "tests/data/test_get_card_numbers_in_sheet.xlsx"
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set,
                                           excel_copy_path(test_path))
     expected_card_numbers = [1, 3, 5, 7, 9]
     actual_card_numbers = my_set_sheet.get_card_numbers_in_sheet()
     assert expected_card_numbers == actual_card_numbers
Exemplo n.º 5
0
def _insert_or_update_sheet_with_index_cards(pokemon_set_sheet: PokemonSetSheet, index_cards: IndexCards,
                                             update_only=True):
    for i in range(0, index_cards.cards.__len__()):
        index_card: IndexCard = index_cards.cards[i]
        card_index = index_card.index
        if not update_only:
            pokemon_set_sheet.insert_card_number(card_index)
        pokemon_set_sheet.update_card_name_with_card_number(index_card.get_name(), card_index)
        pokemon_set_sheet.update_rarity_with_card_number(index_card.get_rarity(), card_index)
        pokemon_set_sheet.update_cell_with_card_number_and_column_name(index_card.get_first_type(), card_index, 'Type')
Exemplo n.º 6
0
 def test_should_have_correct_values(self):
     my_set_sheet = PokemonSetSheet.create(
         test_pokemon_set, 'tests/data/test_pokemon_excel_sheet.xlsx')
     col_1_expected_values = [1, 2, 3, 4]
     col_2_expected_values = ['Yes', 'Yes', 'Yes', 'Yes']
     assert_values_match_those_in_column(col_1_expected_values, 1,
                                         my_set_sheet)
     assert_values_match_those_in_column(col_2_expected_values, 2,
                                         my_set_sheet)
Exemplo n.º 7
0
 def test_update_missing_pokemon_metadata__calls_tcg_api_with_missing_card_numbers \
                 (self, mock_get_cards_from_database):
     test_path = 'tests/data/test_update_missing_metadata_v2.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     pokemon_excel_sheet_model.DEBUG_MODE = False
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set, excel_copy_path(test_path))
     update_missing_pokemon_metadata(my_set_sheet)
     mock_get_cards_from_database.assert_called_once_with(test_pokemon_set, [1, 3, 4])
     os.remove(excel_copy_path(test_path))
     pokemon_excel_sheet_model.DEBUG_MODE = True
Exemplo n.º 8
0
 def test_move_existing_columns_to_proper_index(self):
     test_path = 'tests/data/test_pokemon_excel_sheet.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set,
                                           excel_copy_path(test_path))
     my_set_sheet.move_existing_columns_out_of_way()
     my_set_sheet.move_existing_columns_to_proper_index()
     poke_column_config = get_poke_columns_config()
     col_config_length = poke_column_config.__len__()
     for i in range(0, col_config_length):
         if poke_column_config[i].name == "4 Owned" or poke_column_config[
                 i].name == "Card #":
             assert_column_is_in_sheet(poke_column_config[i], my_set_sheet)
     os.remove(excel_copy_path(test_path))
Exemplo n.º 9
0
 def test_insert_complete_set_metadata__adds_cards_to_sheet(self, mock_get_cards_not_in_list):
     test_path = 'tests/data/test_insert_complete_set_metadata__adds_cards_to_sheet.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set, excel_copy_path(test_path))
     index_cards = IndexCards()
     index_cards.cards = [index_card(2, 'Eldegoss V', 'Ultra Rare', 'Grass')]
     mock_get_cards_not_in_list.return_value = index_cards
     insert_complete_set_metadata(my_set_sheet)
     col_1_expected_values = [None, "Eldegoss V"]
     col_4_expected_values = [None, "Ultra Rare"]
     col_5_expected_values = [None, "Grass"]
     assert_values_match_those_in_column(col_1_expected_values, 1, my_set_sheet)
     assert_values_match_those_in_column(col_4_expected_values, 4, my_set_sheet)
     assert_values_match_those_in_column(col_5_expected_values, 5, my_set_sheet)
     os.remove(excel_copy_path(test_path))
Exemplo n.º 10
0
def update_excel_sheet(set_abbr: str, get_complete_set_info=False):
    my_sets = get_sets()
    my_set = find_set_in_sets(set_abbr, my_sets)
    excel_file_path = 'C:\\Users\\User\\OneDrive\\Pokemon TCG Cards Owned.xlsx'
    alternate_excel_file_path = 'C:\\Users\\jmath\\OneDrive\\Pokemon TCG Cards Owned.xlsx'
    if not file_exists(excel_file_path) and file_exists(
            alternate_excel_file_path):
        excel_file_path = alternate_excel_file_path
    # Remove previous back-up if existing
    remove_backup(excel_file_path)
    # Make back-up file for user
    shutil.copy2(excel_file_path, backup_excel_sheet_filename(excel_file_path))
    my_pokemon_sheet = PokemonSetSheet.create(my_set, excel_file_path)
    my_pokemon_sheet.save()
    update_missing_pokemon_metadata(my_pokemon_sheet)
    if get_complete_set_info:
        insert_complete_set_data(my_pokemon_sheet)
    my_pokemon_sheet.save()
Exemplo n.º 11
0
 def test_update_missing_pokemon_metadata__should_update_missing_data(self, mock_get_cards_from_database):
     index_cards = IndexCards()
     index_cards.cards = [index_card(1, "Pikachu", "Common", "Electric"),
                          index_card(2, "Raichu", "Uncommon", "Electric"),
                          index_card(3, "Pichu", "Uncommon", "Electric"),
                          index_card(4, "Jigglypuff", "Common", "Normal")]
     mock_get_cards_from_database.return_value = index_cards
     test_path = 'tests/data/test_update_missing_metadata.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set, excel_copy_path(test_path))
     update_missing_pokemon_metadata(my_set_sheet)
     col_1_expected_values = ["Pikachu", "Raichu", "Pichu", "Jigglypuff"]
     col_4_expected_values = ["Common", "Uncommon", "Uncommon", "Common"]
     col_5_expected_values = ["Electric", "Electric", "Electric", "Normal"]
     assert_values_match_those_in_column(col_1_expected_values, 1, my_set_sheet)
     assert_values_match_those_in_column(col_4_expected_values, 4, my_set_sheet)
     assert_values_match_those_in_column(col_5_expected_values, 5, my_set_sheet)
     os.remove(excel_copy_path(test_path))
Exemplo n.º 12
0
    def test_move_existing_columns_out_of_way(self):
        test_path = 'tests/data/test_move_existing_columns_away.xlsx'
        shutil.copy2(test_path, excel_copy_path(test_path))
        my_set_sheet = PokemonSetSheet.create(test_pokemon_set,
                                              excel_copy_path(test_path))
        my_set_sheet.move_existing_columns_out_of_way()
        poke_column_config_size = get_poke_columns_config().__len__()
        expected_columns = [
            PokeColumn('Card #', 3 + poke_column_config_size),
            PokeColumn('4 Owned', 4 + poke_column_config_size)
        ]

        for i in range(
                poke_column_config_size + 3,
                poke_column_config_size + 3 + expected_columns.__len__()):
            expected_columns_index = i - 3 - poke_column_config_size
            assert my_set_sheet.is_poke_column_in_columns(
                expected_columns[expected_columns_index])
        os.remove(excel_copy_path(test_path))
Exemplo n.º 13
0
 def test_insert_missing_columns(self):
     test_path = 'tests/data/test_insert_missing_columns.xlsx'
     shutil.copy2(test_path, excel_copy_path(test_path))
     my_set_sheet = PokemonSetSheet.create(test_pokemon_set,
                                           excel_copy_path(test_path))
     col_2_expected_values = [1, 2, 3, 4]
     col_3_expected_values = ['Yes', 'Yes', 'Yes', 'Yes']
     assert_values_match_those_in_column(col_2_expected_values, 2,
                                         my_set_sheet)
     assert_values_match_those_in_column(col_3_expected_values, 3,
                                         my_set_sheet)
     my_set_sheet.insert_missing_columns()
     # Confirm columns with pre-existing values are unchanged
     assert_values_match_those_in_column(col_2_expected_values, 2,
                                         my_set_sheet)
     assert_values_match_those_in_column(col_3_expected_values, 3,
                                         my_set_sheet)
     poke_column_config = get_poke_columns_config()
     col_config_length = poke_column_config.__len__()
     for i in range(0, col_config_length):
         assert_column_is_in_sheet(poke_column_config[i], my_set_sheet)
     os.remove(excel_copy_path(test_path))
Exemplo n.º 14
0
 def test_create_should_call_get_excel_workbook_from_file(
         self, mock_get_excel_workbook_from_file):
     PokemonSetSheet.create(PokemonSet(None, None, None, None), None)
     assert mock_get_excel_workbook_from_file.called
Exemplo n.º 15
0
def assert_column_is_in_sheet(poke_column: PokeColumn,
                              poke_sheet: PokemonSetSheet):
    if not poke_sheet.is_poke_column_in_columns(poke_column):
        print('\n' + poke_column.__str__() + ' not found in given excel sheet')
    assert poke_sheet.is_poke_column_in_columns(poke_column)
Exemplo n.º 16
0
def insert_complete_set_metadata(pokemon_set_sheet: PokemonSetSheet):
    card_numbers = pokemon_set_sheet.get_card_numbers_in_sheet()
    index_cards = get_cards_not_in_list(pokemon_set_sheet.pokemon_set, card_numbers)
    _insert_or_update_sheet_with_index_cards(pokemon_set_sheet, index_cards, False)
Exemplo n.º 17
0
def update_missing_pokemon_metadata(pokemon_set_sheet: PokemonSetSheet):
    card_numbers = pokemon_set_sheet.get_card_numbers_with_missing_data()
    index_cards = get_cards_from_database(pokemon_set_sheet.pokemon_set, card_numbers)
    _insert_or_update_sheet_with_index_cards(pokemon_set_sheet, index_cards)