Skip to content

Commit

Permalink
digits also possible - fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubom committed Sep 17, 2024
1 parent 2d9d3b9 commit d0aa2a3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
from requests.exceptions import RequestException
from iata_code_fetcher.fetcher import (
generate_codes,
fetch_and_process_data,
process_and_save_data,
CodeType,
Expand Down Expand Up @@ -165,5 +166,47 @@ def test_process_and_save_data_airport(mock_get, mock_file, airport_response_moc
)


def test_generate_codes_for_two_letter_codes():
"""
Test to ensure the function generates two-character codes correctly
"""
length = 2 # Test with two-character codes (letters and digits)
codes = list(generate_codes(length))
expected_number_of_codes = (26 + 10)**2 # 26 letters + 10 digits, so (26 + 10)^2 combinations

# Check if all codes have the correct length
assert all(len(code) == length for code in codes), "All codes must have the specified length of 2"

# Check the total number of generated codes
assert (
len(codes) == expected_number_of_codes
), f"The number of generated two-character codes should be {expected_number_of_codes}"

# Check specific codes to ensure correct sequence (first and last with updated rules)
assert codes[0] == "00", "The first code should be '00'"
assert codes[-1] == "ZZ", "The last code should be 'ZZ'"


def test_generate_codes_for_three_letter_codes():
"""
Test to ensure the function generates three-character codes correctly
"""
length = 3 # Test with three-character codes (letters and digits)
codes = list(generate_codes(length))
expected_number_of_codes = (26 + 10)**3 # 26 letters + 10 digits, so (26 + 10)^3 combinations

# Check if all codes have the correct length
assert all(len(code) == length for code in codes), "All codes must have the specified length of 3"

# Check the total number of generated codes
assert (
len(codes) == expected_number_of_codes
), f"The number of generated three-character codes should be {expected_number_of_codes}"

# Check specific codes to ensure correct sequence (first and last with updated rules)
assert codes[0] == "000", "The first code should be '000'"
assert codes[-1] == "ZZZ", "The last code should be 'ZZZ'"


if __name__ == "__main__":
pytest.main()

0 comments on commit d0aa2a3

Please sign in to comment.