Skip to content

Commit

Permalink
Crypto currencies refactoring (#6)
Browse files Browse the repository at this point in the history
* added `state` and `launched_in` attributes

* updated the list of available crypto currencies
  • Loading branch information
duketemon committed May 6, 2023
1 parent 463a978 commit e66d1db
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 177 deletions.
240 changes: 151 additions & 89 deletions currency_codes/assets/crypto.py

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion currency_codes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class Currency:
name (str): currency name
code (str): three-letter code
None if a currency never went public
state (str): what current state of the currency
launched_in (int): currency launch year
numeric_code (str): three-digit numeric code
minor_units (int): shows the relationship between the minor unit and the currency itself
"""

name: str
code: Optional[str]
numeric_code: Optional[str]
minor_units: Optional[int]
state: str = "active"
launched_in: Optional[int] = None
numeric_code: Optional[str] = None
114 changes: 57 additions & 57 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "currency_codes"
version = "23.04.23"
version = "23.05.06"
description = "All currency codes in one package"
authors = ["Artem Kuchumov <duketemon@gmail.com>"]
keywords = ["ISO 4217", "ISO-4217", "Currency Codes", "Currencies", "fiat", "crypto", "commodity"]
Expand Down
21 changes: 19 additions & 2 deletions tests/assets/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
def assert_no_code_duplicates_found(currencies: Iterable[Currency]) -> None:
codes = set()
for currency in currencies:
assert currency.code not in codes
codes.add(currency.code)
if currency.code is not None:
assert currency.code not in codes
codes.add(currency.code)


def test_when_no_code_duplicates_found_for_cryptos(crypto_currencies) -> None:
Expand All @@ -18,6 +19,10 @@ def test_when_no_code_duplicates_found_for_fiats(fiat_currencies) -> None:
assert_no_code_duplicates_found(fiat_currencies)


def test_when_no_code_duplicates_found_for_others(other_currencies) -> None:
assert_no_code_duplicates_found(other_currencies)


def assert_no_numeric_code_duplicates_found(currencies: Iterable[Currency]) -> None:
codes = set()
for currency in currencies:
Expand All @@ -27,3 +32,15 @@ def assert_no_numeric_code_duplicates_found(currencies: Iterable[Currency]) -> N

def test_when_no_numeric_code_duplicates_found_for_fiats(fiat_currencies) -> None:
assert_no_numeric_code_duplicates_found(fiat_currencies)


def assert_no_name_duplicates_found(currencies: Iterable[Currency]) -> None:
names = set()
for currency in currencies:
if currency.name is not None:
assert currency.name not in names
names.add(currency.name)


def test_when_no_name_duplicates_found_for_others(other_currencies) -> None:
assert_no_name_duplicates_found(other_currencies)
2 changes: 1 addition & 1 deletion tests/assets/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_get_crypto_currencies() -> None:

# Then
assert isinstance(currencies, Iterable)
assert len(currencies) == 89
assert len(currencies) == 103


def test_when_no_crypto_currencies_have_numeric_code(crypto_currencies) -> None:
Expand Down
58 changes: 32 additions & 26 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@
)

crypto_test_cases = (
# name, code, minor units
("Solana", "SOL", 9),
("Binance Coin", "BNB", 18),
("Algorand", "ALGO", 6),
("Siacoin", "SC", 24),
# name, code, state, minor units
("Solana", "SOL", "active", 8),
("Binance Coin", "BNB", "active", 18),
("Algorand", "ALGO", "active", 6),
)


fiat_test_cases = (
# name, code, numeric_code, minor_units
("Euro", "EUR", "978", 2),
("Bahraini Dinar", "BHD", "048", 3),
("Chilean Peso", "CLP", "152", 0),
# name, code, numeric_code, state, minor_units
("Euro", "EUR", "978", "active", 2),
("Bahraini Dinar", "BHD", "048", "active", 3),
("Chilean Peso", "CLP", "152", "active", 0),
)


other_test_cases = (
# name, code, numeric_code
("Palladium", "XPD", "964", None),
("Silver", "XAG", "961", None),
("Uruguay Peso en Unidades Indexadas (UI)", "UYI", "940", 0),
("WIR Euro", "CHE", "947", 2),
("Unidad de Fomento", "CLF", "990", 4),
# name, code, state, numeric_code
("Palladium", "XPD", "964", "active", None),
("Silver", "XAG", "961", "active", None),
("Uruguay Peso en Unidades Indexadas (UI)", "UYI", "940", "active", 0),
("WIR Euro", "CHE", "947", "active", 2),
("Unidad de Fomento", "CLF", "990", "active", 4),
)


Expand All @@ -42,7 +41,7 @@ def test_get_all_currencies() -> None:

# Then
assert isinstance(currencies, Iterable)
assert len(currencies) == 268
assert len(currencies) == 282


def test_get_currency_by_code_when_currency_is_not_found() -> None:
Expand Down Expand Up @@ -72,49 +71,54 @@ def test_get_currency_by_code_when_currency_is_not_found_because_of_case_sensiti
@pytest.mark.parametrize(
ids=(c[0] for c in crypto_test_cases),
argvalues=crypto_test_cases,
argnames="name, code, minor_units",
argnames="name, code, state, minor_units",
)
def test_get_currency_by_code_when_currency_is_crypto(name, code, minor_units) -> None:
def test_get_currency_by_code_when_currency_is_crypto(name, code, state, minor_units) -> None:
# When
currency = get_currency_by_code(code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.state == state
assert currency.minor_units == minor_units
assert currency.numeric_code is None


@pytest.mark.parametrize(
ids=(c[0] for c in fiat_test_cases),
argvalues=fiat_test_cases,
argnames="name, code, numeric_code, minor_units",
argnames="name, code, numeric_code, state, minor_units",
)
def test_get_currency_by_code_when_currency_is_fiat(name, code, numeric_code, minor_units) -> None:
def test_get_currency_by_code_when_currency_is_fiat(
name, code, numeric_code, state, minor_units
) -> None:
# When
currency = get_currency_by_code(code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.state == state
assert currency.numeric_code == numeric_code
assert currency.minor_units == minor_units


@pytest.mark.parametrize(
ids=(c[0] for c in other_test_cases),
argvalues=other_test_cases,
argnames="name, code, numeric_code, minor_units",
argnames="name, code, numeric_code, state, minor_units",
)
def test_get_currency_by_code_when_currency_is_other(
name, code, numeric_code, minor_units
name, code, numeric_code, state, minor_units
) -> None:
# When
currency = get_currency_by_code(code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.state == state
assert currency.numeric_code == numeric_code
if minor_units is None:
assert currency.minor_units is minor_units
Expand All @@ -137,35 +141,37 @@ def test_get_currency_by_numeric_code_when_currency_is_not_found() -> None:
@pytest.mark.parametrize(
ids=(c[0] for c in fiat_test_cases),
argvalues=fiat_test_cases,
argnames="name, code, numeric_code, minor_units",
argnames="name, code, numeric_code, state, minor_units",
)
def test_get_currency_by_numeric_code_when_currency_is_fiat(
name, code, numeric_code, minor_units
name, code, numeric_code, state, minor_units
) -> None:
# When
currency = get_currency_by_numeric_code(numeric_code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.state == state
assert currency.numeric_code == numeric_code
assert currency.minor_units == minor_units


@pytest.mark.parametrize(
ids=(c[0] for c in other_test_cases),
argvalues=other_test_cases,
argnames="name, code, numeric_code, minor_units",
argnames="name, code, numeric_code, state, minor_units",
)
def test_get_currency_by_numeric_code_when_currency_is_other(
name, code, numeric_code, minor_units
name, code, numeric_code, state, minor_units
) -> None:
# When
currency = get_currency_by_numeric_code(numeric_code)

# Then
assert currency.name == name
assert currency.code == code
assert currency.state == state
assert currency.numeric_code == numeric_code
if minor_units is None:
assert currency.minor_units is minor_units
Expand Down

0 comments on commit e66d1db

Please sign in to comment.