tests: Specify types in importers.yml, rather than munging them manually.

This commit is contained in:
Brett Smith 2017-12-18 10:28:05 -05:00
parent c98f0d9ff3
commit fb0e4f2235
2 changed files with 46 additions and 71 deletions

View file

@ -2,62 +2,62 @@
importer: patreon.IncomeImporter
expect:
- payee: Alex Jones
date: [2017, 9, 1]
amount: "150.00"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["150.00"]
currency: USD
- payee: Dakota Doe
date: [2017, 9, 1]
amount: "12.00"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["12.00"]
currency: USD
- source: PatreonEarnings.csv
importer: patreon.PatreonFeeImporter
expect:
- payee: Patreon
date: [2017, 9, 1]
amount: "61.73"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["61.73"]
currency: USD
- payee: Patreon
date: [2017, 10, 1]
amount: "117.03"
date: !!python/object/apply:datetime.date [2017, 10, 1]
amount: !!python/object/apply:decimal.Decimal ["117.03"]
currency: USD
- source: PatreonEarnings.csv
importer: patreon.CardFeeImporter
expect:
- payee: Patreon
date: [2017, 9, 1]
amount: "52.47"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["52.47"]
currency: USD
- payee: Patreon
date: [2017, 10, 1]
amount: "99.47"
date: !!python/object/apply:datetime.date [2017, 10, 1]
amount: !!python/object/apply:decimal.Decimal ["99.47"]
currency: USD
- source: PatreonVat.csv
importer: patreon.VATImporter
expect:
- payee: Patreon
date: [2017, 9, 1]
amount: "2.00"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["2.00"]
currency: USD
country_code: AT
country_name: Austria
- payee: Patreon
date: [2017, 9, 1]
amount: "3.30"
date: !!python/object/apply:datetime.date [2017, 9, 1]
amount: !!python/object/apply:decimal.Decimal ["3.30"]
currency: USD
country_code: BE
country_name: Belgium
- payee: Patreon
date: [2017, 10, 1]
amount: "0.40"
date: !!python/object/apply:datetime.date [2017, 10, 1]
amount: !!python/object/apply:decimal.Decimal ["0.40"]
currency: USD
country_code: BG
country_name: Bulgaria
- payee: Patreon
date: [2017, 10, 1]
amount: "6.05"
date: !!python/object/apply:datetime.date [2017, 10, 1]
amount: !!python/object/apply:decimal.Decimal ["6.05"]
currency: USD
country_code: CZ
country_name: Czech Republic
@ -66,18 +66,18 @@
importer: stripe.PaymentImporter
expect:
- payee: Dakota Smith
date: [2017, 11, 8]
amount: "100.00"
fee: "3.0"
tax: "0.0"
date: !!python/object/apply:datetime.date [2017, 11, 8]
amount: !!python/object/apply:decimal.Decimal ["100.00"]
fee: !!python/object/apply:decimal.Decimal ["3"]
tax: !!python/object/apply:decimal.Decimal ["0"]
currency: USD
payment_id: ch_oxuish6phae2Raighooghi3U
description: "Payment for invoice #102"
- payee: Dakota Jones
date: [2017, 10, 28]
amount: "50.00"
fee: "1.4"
tax: "0.0"
date: !!python/object/apply:datetime.date [2017, 10, 28]
amount: !!python/object/apply:decimal.Decimal ["50.00"]
fee: !!python/object/apply:decimal.Decimal ["1.4"]
tax: !!python/object/apply:decimal.Decimal ["0"]
currency: USD
payment_id: ch_hHee9ef1aeyee1ruo7ochee9
description: "Payment for invoice #100"
@ -86,12 +86,12 @@
importer: nbpy2017.Payment2017Importer
expect:
- payee: Python Person A
date: [2017, 10, 19]
amount: "80.00"
tickets_sold: "1.0"
ticket_rate: "21.25"
shirts_sold: "1.0"
shirt_rate: "25.50"
date: !!python/object/apply:datetime.date [2017, 10, 19]
amount: !!python/object/apply:decimal.Decimal ["80.00"]
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
currency: USD
invoice_id: "83"
payment_id: ch_ahr0ue8lai1ohqu4Gei4Biem
@ -101,12 +101,12 @@
importer: nbpy2017.Payment2017Importer
expect:
- payee: Python Person B
date: [2017, 12, 3]
amount: "50.00"
tickets_sold: "1.0"
ticket_rate: "42.50"
shirts_sold: "0.0"
shirt_rate: "25.50"
date: !!python/object/apply:datetime.date [2017, 12, 3]
amount: !!python/object/apply:decimal.Decimal ["50.00"]
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
shirts_sold: !!python/object/apply:decimal.Decimal ["0"]
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
currency: USD
payment_id: ch_eishei9aiY8aiqu4lieYiu9i
stripe_id: ch_eishei9aiY8aiqu4lieYiu9i
@ -116,12 +116,12 @@
importer: nbpy2017.Payment2017Importer
expect:
- payee: Python Person C
date: [2017, 10, 5]
amount: "55.00"
tickets_sold: "1.0"
ticket_rate: "21.25"
shirts_sold: "1.0"
shirt_rate: "25.50"
date: !!python/object/apply:datetime.date [2017, 10, 5]
amount: !!python/object/apply:decimal.Decimal ["55.00"]
tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
currency: USD
payment_id: ch_daer0ahwoh9oDeiqu2eimoD7
stripe_id: ch_daer0ahwoh9oDeiqu2eimoD7

View file

@ -12,23 +12,6 @@ from import2ledger import importers
from . import DATA_DIR
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:
test_data = yaml.load(yaml_file)
for test in test_data:
@ -38,14 +21,6 @@ class TestImporters:
module = importlib.import_module('.' + module_name, 'import2ledger.importers')
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', [
(t['source'], t['importer']) for t in test_data
])