tests: Specify types in importers.yml, rather than munging them manually.
This commit is contained in:
parent
c98f0d9ff3
commit
fb0e4f2235
2 changed files with 46 additions and 71 deletions
|
@ -2,62 +2,62 @@
|
||||||
importer: patreon.IncomeImporter
|
importer: patreon.IncomeImporter
|
||||||
expect:
|
expect:
|
||||||
- payee: Alex Jones
|
- payee: Alex Jones
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "150.00"
|
amount: !!python/object/apply:decimal.Decimal ["150.00"]
|
||||||
currency: USD
|
currency: USD
|
||||||
- payee: Dakota Doe
|
- payee: Dakota Doe
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "12.00"
|
amount: !!python/object/apply:decimal.Decimal ["12.00"]
|
||||||
currency: USD
|
currency: USD
|
||||||
|
|
||||||
- source: PatreonEarnings.csv
|
- source: PatreonEarnings.csv
|
||||||
importer: patreon.PatreonFeeImporter
|
importer: patreon.PatreonFeeImporter
|
||||||
expect:
|
expect:
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "61.73"
|
amount: !!python/object/apply:decimal.Decimal ["61.73"]
|
||||||
currency: USD
|
currency: USD
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 10, 1]
|
date: !!python/object/apply:datetime.date [2017, 10, 1]
|
||||||
amount: "117.03"
|
amount: !!python/object/apply:decimal.Decimal ["117.03"]
|
||||||
currency: USD
|
currency: USD
|
||||||
|
|
||||||
- source: PatreonEarnings.csv
|
- source: PatreonEarnings.csv
|
||||||
importer: patreon.CardFeeImporter
|
importer: patreon.CardFeeImporter
|
||||||
expect:
|
expect:
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "52.47"
|
amount: !!python/object/apply:decimal.Decimal ["52.47"]
|
||||||
currency: USD
|
currency: USD
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 10, 1]
|
date: !!python/object/apply:datetime.date [2017, 10, 1]
|
||||||
amount: "99.47"
|
amount: !!python/object/apply:decimal.Decimal ["99.47"]
|
||||||
currency: USD
|
currency: USD
|
||||||
|
|
||||||
- source: PatreonVat.csv
|
- source: PatreonVat.csv
|
||||||
importer: patreon.VATImporter
|
importer: patreon.VATImporter
|
||||||
expect:
|
expect:
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "2.00"
|
amount: !!python/object/apply:decimal.Decimal ["2.00"]
|
||||||
currency: USD
|
currency: USD
|
||||||
country_code: AT
|
country_code: AT
|
||||||
country_name: Austria
|
country_name: Austria
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 9, 1]
|
date: !!python/object/apply:datetime.date [2017, 9, 1]
|
||||||
amount: "3.30"
|
amount: !!python/object/apply:decimal.Decimal ["3.30"]
|
||||||
currency: USD
|
currency: USD
|
||||||
country_code: BE
|
country_code: BE
|
||||||
country_name: Belgium
|
country_name: Belgium
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 10, 1]
|
date: !!python/object/apply:datetime.date [2017, 10, 1]
|
||||||
amount: "0.40"
|
amount: !!python/object/apply:decimal.Decimal ["0.40"]
|
||||||
currency: USD
|
currency: USD
|
||||||
country_code: BG
|
country_code: BG
|
||||||
country_name: Bulgaria
|
country_name: Bulgaria
|
||||||
- payee: Patreon
|
- payee: Patreon
|
||||||
date: [2017, 10, 1]
|
date: !!python/object/apply:datetime.date [2017, 10, 1]
|
||||||
amount: "6.05"
|
amount: !!python/object/apply:decimal.Decimal ["6.05"]
|
||||||
currency: USD
|
currency: USD
|
||||||
country_code: CZ
|
country_code: CZ
|
||||||
country_name: Czech Republic
|
country_name: Czech Republic
|
||||||
|
@ -66,18 +66,18 @@
|
||||||
importer: stripe.PaymentImporter
|
importer: stripe.PaymentImporter
|
||||||
expect:
|
expect:
|
||||||
- payee: Dakota Smith
|
- payee: Dakota Smith
|
||||||
date: [2017, 11, 8]
|
date: !!python/object/apply:datetime.date [2017, 11, 8]
|
||||||
amount: "100.00"
|
amount: !!python/object/apply:decimal.Decimal ["100.00"]
|
||||||
fee: "3.0"
|
fee: !!python/object/apply:decimal.Decimal ["3"]
|
||||||
tax: "0.0"
|
tax: !!python/object/apply:decimal.Decimal ["0"]
|
||||||
currency: USD
|
currency: USD
|
||||||
payment_id: ch_oxuish6phae2Raighooghi3U
|
payment_id: ch_oxuish6phae2Raighooghi3U
|
||||||
description: "Payment for invoice #102"
|
description: "Payment for invoice #102"
|
||||||
- payee: Dakota Jones
|
- payee: Dakota Jones
|
||||||
date: [2017, 10, 28]
|
date: !!python/object/apply:datetime.date [2017, 10, 28]
|
||||||
amount: "50.00"
|
amount: !!python/object/apply:decimal.Decimal ["50.00"]
|
||||||
fee: "1.4"
|
fee: !!python/object/apply:decimal.Decimal ["1.4"]
|
||||||
tax: "0.0"
|
tax: !!python/object/apply:decimal.Decimal ["0"]
|
||||||
currency: USD
|
currency: USD
|
||||||
payment_id: ch_hHee9ef1aeyee1ruo7ochee9
|
payment_id: ch_hHee9ef1aeyee1ruo7ochee9
|
||||||
description: "Payment for invoice #100"
|
description: "Payment for invoice #100"
|
||||||
|
@ -86,12 +86,12 @@
|
||||||
importer: nbpy2017.Payment2017Importer
|
importer: nbpy2017.Payment2017Importer
|
||||||
expect:
|
expect:
|
||||||
- payee: Python Person A
|
- payee: Python Person A
|
||||||
date: [2017, 10, 19]
|
date: !!python/object/apply:datetime.date [2017, 10, 19]
|
||||||
amount: "80.00"
|
amount: !!python/object/apply:decimal.Decimal ["80.00"]
|
||||||
tickets_sold: "1.0"
|
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
|
||||||
ticket_rate: "21.25"
|
ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
|
||||||
shirts_sold: "1.0"
|
shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
|
||||||
shirt_rate: "25.50"
|
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
|
||||||
currency: USD
|
currency: USD
|
||||||
invoice_id: "83"
|
invoice_id: "83"
|
||||||
payment_id: ch_ahr0ue8lai1ohqu4Gei4Biem
|
payment_id: ch_ahr0ue8lai1ohqu4Gei4Biem
|
||||||
|
@ -101,12 +101,12 @@
|
||||||
importer: nbpy2017.Payment2017Importer
|
importer: nbpy2017.Payment2017Importer
|
||||||
expect:
|
expect:
|
||||||
- payee: Python Person B
|
- payee: Python Person B
|
||||||
date: [2017, 12, 3]
|
date: !!python/object/apply:datetime.date [2017, 12, 3]
|
||||||
amount: "50.00"
|
amount: !!python/object/apply:decimal.Decimal ["50.00"]
|
||||||
tickets_sold: "1.0"
|
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
|
||||||
ticket_rate: "42.50"
|
ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
|
||||||
shirts_sold: "0.0"
|
shirts_sold: !!python/object/apply:decimal.Decimal ["0"]
|
||||||
shirt_rate: "25.50"
|
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
|
||||||
currency: USD
|
currency: USD
|
||||||
payment_id: ch_eishei9aiY8aiqu4lieYiu9i
|
payment_id: ch_eishei9aiY8aiqu4lieYiu9i
|
||||||
stripe_id: ch_eishei9aiY8aiqu4lieYiu9i
|
stripe_id: ch_eishei9aiY8aiqu4lieYiu9i
|
||||||
|
@ -116,12 +116,12 @@
|
||||||
importer: nbpy2017.Payment2017Importer
|
importer: nbpy2017.Payment2017Importer
|
||||||
expect:
|
expect:
|
||||||
- payee: Python Person C
|
- payee: Python Person C
|
||||||
date: [2017, 10, 5]
|
date: !!python/object/apply:datetime.date [2017, 10, 5]
|
||||||
amount: "55.00"
|
amount: !!python/object/apply:decimal.Decimal ["55.00"]
|
||||||
tickets_sold: "1.0"
|
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
|
||||||
ticket_rate: "21.25"
|
ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
|
||||||
shirts_sold: "1.0"
|
shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
|
||||||
shirt_rate: "25.50"
|
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
|
||||||
currency: USD
|
currency: USD
|
||||||
payment_id: ch_daer0ahwoh9oDeiqu2eimoD7
|
payment_id: ch_daer0ahwoh9oDeiqu2eimoD7
|
||||||
stripe_id: ch_daer0ahwoh9oDeiqu2eimoD7
|
stripe_id: ch_daer0ahwoh9oDeiqu2eimoD7
|
||||||
|
|
|
@ -12,23 +12,6 @@ from import2ledger import importers
|
||||||
from . import DATA_DIR
|
from . import DATA_DIR
|
||||||
|
|
||||||
class TestImporters:
|
class TestImporters:
|
||||||
def _value_converter(value):
|
|
||||||
try:
|
|
||||||
is_decimal = re.match(r'^[-+]?\d+\.\d+$', value)
|
|
||||||
except TypeError:
|
|
||||||
is_decimal = False
|
|
||||||
if is_decimal:
|
|
||||||
return decimal.Decimal
|
|
||||||
else:
|
|
||||||
return lambda x: x
|
|
||||||
|
|
||||||
def _date(parts_list):
|
|
||||||
return datetime.date(*parts_list)
|
|
||||||
|
|
||||||
KEY_CONVERTERS = {
|
|
||||||
'date': _date,
|
|
||||||
}
|
|
||||||
|
|
||||||
with pathlib.Path(DATA_DIR, 'imports.yml').open() as yaml_file:
|
with pathlib.Path(DATA_DIR, 'imports.yml').open() as yaml_file:
|
||||||
test_data = yaml.load(yaml_file)
|
test_data = yaml.load(yaml_file)
|
||||||
for test in test_data:
|
for test in test_data:
|
||||||
|
@ -38,14 +21,6 @@ class TestImporters:
|
||||||
module = importlib.import_module('.' + module_name, 'import2ledger.importers')
|
module = importlib.import_module('.' + module_name, 'import2ledger.importers')
|
||||||
test['importer'] = getattr(module, class_name)
|
test['importer'] = getattr(module, class_name)
|
||||||
|
|
||||||
for expect_result in test['expect']:
|
|
||||||
for key, value in expect_result.items():
|
|
||||||
try:
|
|
||||||
convert_func = KEY_CONVERTERS[key]
|
|
||||||
except KeyError:
|
|
||||||
convert_func = _value_converter(value)
|
|
||||||
expect_result[key] = convert_func(value)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('source_path,importer', [
|
@pytest.mark.parametrize('source_path,importer', [
|
||||||
(t['source'], t['importer']) for t in test_data
|
(t['source'], t['importer']) for t in test_data
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue