-
Notifications
You must be signed in to change notification settings - Fork 169
New feature: currency code validations #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import pytest | ||
|
|
||
| from validators import iso_4217, ValidationFailure | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('value, case_sensitive', [ | ||
| ('USD', True), | ||
| ('usd', False), | ||
| ]) | ||
| def test_returns_true_on_valid_iso_4217(value, case_sensitive): | ||
| assert iso_4217(value, case_sensitive) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('value, case_sensitive', [ | ||
| ('XTB', True), | ||
| ('usd', True), | ||
| ]) | ||
| def test_returns_failed_on_valid_iso_4217(value, case_sensitive): | ||
| assert isinstance(iso_4217(value, case_sensitive), ValidationFailure) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| from .utils import validator | ||
|
|
||
|
|
||
| @validator | ||
| def iso_4217(value, case_sensitive=True): | ||
| """ | ||
| Return whether or not given value is a valid ISO 4217 currency code. | ||
|
|
||
| This validator is based on ISO 4217. | ||
|
|
||
| Examples:: | ||
|
|
||
| >>> iso_4217('USD') | ||
| True | ||
|
|
||
| >>> iso_4217('usd') | ||
| ValidationFailure(func=iso_4217, ...) | ||
|
|
||
| >>> iso_4217('usd', case_sensitive=False) | ||
| True | ||
|
|
||
| >>> iso_4217('XBT') | ||
| ValidationFailure(func=iso_4217, ...) | ||
|
|
||
| .. versionadded:: 0.16.0 | ||
|
|
||
| :param value: ISO 4217 currency code string to validate | ||
| """ | ||
|
|
||
| if not case_sensitive: | ||
| value = value.upper() | ||
|
|
||
| return value in [ | ||
| 'AED', | ||
| 'AFN', | ||
| 'ALL', | ||
| 'AMD', | ||
| 'ANG', | ||
| 'AOA', | ||
| 'ARS', | ||
| 'AUD', | ||
| 'AWG', | ||
| 'AZN', | ||
| 'BAM', | ||
| 'BBD', | ||
| 'BDT', | ||
| 'BGN', | ||
| 'BHD', | ||
| 'BIF', | ||
| 'BMD', | ||
| 'BND', | ||
| 'BOB', | ||
| 'BOV', | ||
| 'BRL', | ||
| 'BSD', | ||
| 'BTN', | ||
| 'BWP', | ||
| 'BYR', | ||
| 'BZD', | ||
| 'CAD', | ||
| 'CDF', | ||
| 'CHE', | ||
| 'CHF', | ||
| 'CHW', | ||
| 'CLF', | ||
| 'CLP', | ||
| 'CNY', | ||
| 'COP', | ||
| 'COU', | ||
| 'CRC', | ||
| 'CUC', | ||
| 'CUP', | ||
| 'CVE', | ||
| 'CZK', | ||
| 'DJF', | ||
| 'DKK', | ||
| 'DOP', | ||
| 'DZD', | ||
| 'EGP', | ||
| 'ERN', | ||
| 'ETB', | ||
| 'EUR', | ||
| 'FJD', | ||
| 'FKP', | ||
| 'GBP', | ||
| 'GEL', | ||
| 'GHS', | ||
| 'GIP', | ||
| 'GMD', | ||
| 'GNF', | ||
| 'GTQ', | ||
| 'GYD', | ||
| 'HKD', | ||
| 'HNL', | ||
| 'HRK', | ||
| 'HTG', | ||
| 'HUF', | ||
| 'IDR', | ||
| 'ILS', | ||
| 'INR', | ||
| 'IQD', | ||
| 'IRR', | ||
| 'ISK', | ||
| 'JMD', | ||
| 'JOD', | ||
| 'JPY', | ||
| 'KES', | ||
| 'KGS', | ||
| 'KHR', | ||
| 'KMF', | ||
| 'KPW', | ||
| 'KRW', | ||
| 'KWD', | ||
| 'KYD', | ||
| 'KZT', | ||
| 'LAK', | ||
| 'LBP', | ||
| 'LKR', | ||
| 'LRD', | ||
| 'LSL', | ||
| 'LTL', | ||
| 'LVL', | ||
| 'LYD', | ||
| 'MAD', | ||
| 'MDL', | ||
| 'MGA', | ||
| 'MKD', | ||
| 'MMK', | ||
| 'MNT', | ||
| 'MOP', | ||
| 'MRO', | ||
| 'MUR', | ||
| 'MVR', | ||
| 'MWK', | ||
| 'MXN', | ||
| 'MXV', | ||
| 'MYR', | ||
| 'MZN', | ||
| 'NAD', | ||
| 'NGN', | ||
| 'NIO', | ||
| 'NOK', | ||
| 'NPR', | ||
| 'NZD', | ||
| 'OMR', | ||
| 'PAB', | ||
| 'PEN', | ||
| 'PGK', | ||
| 'PHP', | ||
| 'PKR', | ||
| 'PLN', | ||
| 'PYG', | ||
| 'QAR', | ||
| 'RON', | ||
| 'RSD', | ||
| 'RUB', | ||
| 'RWF', | ||
| 'SAR', | ||
| 'SBD', | ||
| 'SCR', | ||
| 'SDG', | ||
| 'SEK', | ||
| 'SGD', | ||
| 'SHP', | ||
| 'SLL', | ||
| 'SOS', | ||
| 'SRD', | ||
| 'SSP', | ||
| 'STD', | ||
| 'SVC', | ||
| 'SYP', | ||
| 'SZL', | ||
| 'THB', | ||
| 'TJS', | ||
| 'TMT', | ||
| 'TND', | ||
| 'TOP', | ||
| 'TRY', | ||
| 'TTD', | ||
| 'TWD', | ||
| 'TZS', | ||
| 'UAH', | ||
| 'UGX', | ||
| 'USD', | ||
| 'USN', | ||
| 'USS', | ||
| 'UYI', | ||
| 'UYU', | ||
| 'UZS', | ||
| 'VEF', | ||
| 'VND', | ||
| 'VUV', | ||
| 'WST', | ||
| 'XAF', | ||
| 'XAG', | ||
| 'XAU', | ||
| 'XBA', | ||
| 'XBB', | ||
| 'XBC', | ||
| 'XBD', | ||
| 'XCD', | ||
| 'XDR', | ||
| 'XFU', | ||
| 'XOF', | ||
| 'XPD', | ||
| 'XPF', | ||
| 'XPT', | ||
| 'XSU', | ||
| 'XTS', | ||
| 'XUA', | ||
| 'XXX', | ||
| 'YER', | ||
| 'ZAR', | ||
| 'ZMW', | ||
| 'ZWL', | ||
| ] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we'd just call this validator
currency_codeinstead ofiso_4217. We could keep the comment block as it is describing that the currency code validator is based on ISO 4217