Changeset - 501bd251cbf3
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-03-19 19:04:53
brettcsmith@brettcsmith.org
tests: Turn tested hooks into fixtures.

This is in preparation for passing configuration to hooks.
That'll be a big change already, so I wanted this to be a
boring diff first.
3 files changed with 58 insertions and 69 deletions:
0 comments (0 inline, 0 general)
tests/test_meta_expense_allocation.py
Show inline comments
...
 
@@ -34,102 +34,99 @@ INVALID_VALUES = {
 
    'fundrasing',
 
    '',
 
}
 

	
 
TEST_KEY = 'expense-allocation'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_expense_allocation.MetaExpenseAllocation()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: src_value})
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_transactions(src_value, set_value):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
@pytest.mark.parametrize('account', [
 
    'Accrued:AccountsReceivable',
 
    'Assets:Cash',
 
    'Income:Donations',
 
    'Liabilities:CreditCard',
 
    'UnearnedIncome:Donations',
 
])
 
def test_non_expense_accounts_skipped(account):
 
def test_non_expense_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'program'}
 
    txn = testutil.Transaction(postings=[
 
        (account, -25),
 
        ('Expenses:General', 25, meta.copy()),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, meta)
 

	
 
@pytest.mark.parametrize('account,set_value', [
 
    ('Expenses:Services:Accounting', 'administration'),
 
    ('Expenses:Services:Administration', 'administration'),
 
    ('Expenses:Services:Advocacy', 'program'),
 
    ('Expenses:Services:Development', 'program'),
 
    ('Expenses:Services:Fundraising', 'fundraising'),
 
])
 
def test_default_values(account, set_value):
 
def test_default_values(hook, account, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Liabilites:CreditCard', -25),
 
        (account, 25),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('date,set_value', [
 
    (testutil.EXTREME_FUTURE_DATE, None),
 
    (testutil.FUTURE_DATE, 'program'),
 
    (testutil.FY_START_DATE, 'program'),
 
    (testutil.FY_MID_DATE, 'program'),
 
    (testutil.PAST_DATE, None),
 
])
 
def test_default_value_set_in_date_range(date, set_value):
 
def test_default_value_set_in_date_range(hook, date, set_value):
 
    txn = testutil.Transaction(date=date, postings=[
 
        ('Liabilites:CreditCard', -25),
 
        ('Expenses:General', 25),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    expect_meta = None if set_value is None else {TEST_KEY: set_value}
 
    testutil.check_post_meta(txn, None, expect_meta)
tests/test_meta_income_type.py
Show inline comments
...
 
@@ -34,70 +34,69 @@ INVALID_VALUES = {
 
    'UTBI',
 
    '',
 
}
 

	
 
TEST_KEY = 'income-type'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_income_type.MetaIncomeType()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
 
        ('Income:Other', -25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
 
        ('Income:Other', -25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: src_value})
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_transactions(src_value, set_value):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', 25),
 
        ('Income:Other', -25),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', 25),
 
        ('Income:Other', -25),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
@pytest.mark.parametrize('account', [
 
    'Accrued:AccountsReceivable',
 
    'Assets:Cash',
 
    'Expenses:General',
 
    'Liabilities:CreditCard',
 
])
 
def test_non_income_accounts_skipped(account):
 
def test_non_income_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'RBI'}
 
    txn = testutil.Transaction(postings=[
 
        (account, 25),
 
        ('Income:Other', -25, meta.copy()),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, meta)
 

	
 
@pytest.mark.parametrize('account,set_value', [
 
    ('Income:Donations', 'Donations'),
 
    ('Income:Honoraria', 'RBI'),
...
 
@@ -107,46 +106,43 @@ def test_non_income_accounts_skipped(account):
 
    ('Income:Sales', 'RBI'),
 
    ('Income:SoftwareDevelopment', 'RBI'),
 
    ('Income:TrademarkLicensing', 'RBI'),
 
    ('UnearnedIncome:Conferences:Registrations', 'RBI'),
 
    ('UnearnedIncome:MatchPledges', 'Donations'),
 
])
 
def test_default_values(account, set_value):
 
def test_default_values(hook, account, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
 
        (account, -25),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('account', [
 
    'Income:Other',
 
])
 
def test_no_default_value(account):
 
def test_no_default_value(hook, account):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
 
        (account, -25),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
@pytest.mark.parametrize('date,set_value', [
 
    (testutil.EXTREME_FUTURE_DATE, None),
 
    (testutil.FUTURE_DATE, 'Donations'),
 
    (testutil.FY_START_DATE, 'Donations'),
 
    (testutil.FY_MID_DATE, 'Donations'),
 
    (testutil.PAST_DATE, None),
 
])
 
def test_default_value_set_in_date_range(date, set_value):
 
def test_default_value_set_in_date_range(hook, date, set_value):
 
    txn = testutil.Transaction(date=date, postings=[
 
        ('Assets:Cash', 25),
 
        ('Income:Donations', -25),
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    expect_meta = None if set_value is None else {TEST_KEY: set_value}
 
    testutil.check_post_meta(txn, None, expect_meta)
tests/test_meta_tax_implication.py
Show inline comments
...
 
@@ -46,102 +46,98 @@ INVALID_VALUES = {
 
    'Payrol',
 
    '',
 
}
 

	
 
TEST_KEY = 'tax-implication'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_tax_implication.MetaTaxImplication()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25, {TEST_KEY: src_value}),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: src_value})
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_transactions(src_value, set_value):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
@pytest.mark.parametrize('account', [
 
    'Accrued:AccountsPayable',
 
    'Expenses:General',
 
    'Liabilities:CreditCard',
 
])
 
def test_non_asset_accounts_skipped(account):
 
def test_non_asset_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'USA-Corporation'}
 
    txn = testutil.Transaction(postings=[
 
        (account, 25),
 
        ('Assets:Cash', -25, meta.copy()),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, meta)
 

	
 
def test_prepaid_expenses_skipped():
 
def test_prepaid_expenses_skipped(hook, ):
 
    txn = testutil.Transaction(postings=[
 
        ('Expenses:General', 25),
 
        ('Assets:PrepaidExpenses', -25),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
def test_asset_credits_skipped():
 
def test_asset_credits_skipped(hook, ):
 
    txn = testutil.Transaction(postings=[
 
        ('Income:Donations', -25),
 
        ('Assets:Cash', 25),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, None)
 

	
 
@pytest.mark.parametrize('date,need_value', [
 
    (testutil.EXTREME_FUTURE_DATE, False),
 
    (testutil.FUTURE_DATE, True),
 
    (testutil.FY_START_DATE, True),
 
    (testutil.FY_MID_DATE, True),
 
    (testutil.PAST_DATE, False),
 
])
 
def test_validation_only_in_date_range(date, need_value):
 
def test_validation_only_in_date_range(hook, date, need_value):
 
    txn = testutil.Transaction(date=date, postings=[
 
        ('Liabilites:CreditCard', 25),
 
        ('Assets:Cash', -25),
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert bool(errors) == bool(need_value)
 
    testutil.check_post_meta(txn, None, None)
0 comments (0 inline, 0 general)