Example #1
0
    def test_summarize_new_trans_one_item_keeps_category(self):
        original_trans = transaction(
            amount='$40.00',
            merchant='Amazon',
            note='Test note')

        item1 = transaction(
            amount='$15.00',
            merchant='Giant paper shredder',
            category='Office Supplies')
        shipping = transaction(
            amount='$5.00',
            merchant='Shipping')
        free_shipping = transaction(
            amount='$5.00',
            merchant='Promotion(s)')

        actual_summary = mint.summarize_new_trans(
            original_trans,
            [item1, shipping, free_shipping],
            'Amazon.com: ')[0]

        self.assertEqual(actual_summary.amount, original_trans.amount)
        self.assertEqual(actual_summary.category, 'Office Supplies')
        self.assertEqual(actual_summary.merchant,
                         'Amazon.com: Giant paper shredder')
        self.assertTrue('Giant paper shredder' in actual_summary.note)
        self.assertTrue('Shipping' in actual_summary.note)
        self.assertTrue('Promotion(s)' in actual_summary.note)
Example #2
0
    def test_summarize_new_trans(self):
        original_trans = transaction(
            amount='$40.00',
            merchant='Amazon',
            note='Test note')

        item1 = transaction(
            amount='$15.00',
            merchant='Item 1')
        item2 = transaction(
            amount='$25.00',
            merchant='Item 2')
        shipping = transaction(
            amount='$5.00',
            merchant='Shipping')
        free_shipping = transaction(
            amount='$5.00',
            merchant='Promotion(s)')

        actual_summary = mint.summarize_new_trans(
            original_trans,
            [item1, item2, shipping, free_shipping],
            'Amazon.com: ')[0]

        self.assertEqual(actual_summary.amount, original_trans.amount)
        self.assertEqual(
            actual_summary.category, category.DEFAULT_MINT_CATEGORY)
        self.assertEqual(actual_summary.merchant, 'Amazon.com: Item 1, Item 2')
        self.assertTrue('Item 1' in actual_summary.note)
        self.assertTrue('Item 2' in actual_summary.note)
        self.assertTrue('Shipping' in actual_summary.note)
        self.assertTrue('Promotion(s)' in actual_summary.note)
Example #3
0
    def test_get_compare_tuple(self):
        trans = transaction(merchant='Simple Title', amount='$1.00')
        self.assertEqual(trans.get_compare_tuple(),
                         ('Simple Title', '$1.00', 'Personal Care'))

        trans2 = transaction(merchant='Simple Refund',
                             amount='$2.01',
                             is_debit=False)
        self.assertEqual(trans2.get_compare_tuple(True),
                         ('Simple Refund', '-$2.01'))
Example #4
0
    def test_sum_amounts(self):
        self.assertEqual(Transaction.sum_amounts([]), 0)

        trans1 = transaction(amount='$2.34')
        self.assertEqual(Transaction.sum_amounts([trans1]), 2340000)

        trans2 = transaction(amount='$8.00')
        self.assertEqual(Transaction.sum_amounts([trans1, trans2]), 10340000)

        credit = transaction(amount='$20.20', is_debit=False)
        self.assertEqual(Transaction.sum_amounts([trans1, credit, trans2]),
                         -9860000)
Example #5
0
    def test_itemize_new_trans(self):
        self.assertEqual(mint.itemize_new_trans([], 'Sweet: '), [])

        trans = [
            transaction(amount='$5.00', merchant='ABC'),
            transaction(amount='$15.00', merchant='CBA'),
        ]
        itemized_trans = mint.itemize_new_trans(trans, 'Sweet: ')
        self.assertEqual(itemized_trans[0].merchant, 'Sweet: CBA')
        self.assertEqual(itemized_trans[0].amount, 15000000)
        self.assertEqual(itemized_trans[1].merchant, 'Sweet: ABC')
        self.assertEqual(itemized_trans[1].amount, 5000000)
Example #6
0
    def test_constructor(self):
        trans = transaction()
        self.assertEqual(trans.amount, 11950000)
        self.assertTrue(trans.is_debit)
        self.assertEqual(trans.date, date(2014, 2, 28))
        self.assertFalse(trans.matched)
        self.assertEqual(trans.orders, [])
        self.assertEqual(trans.children, [])

        trans = transaction(amount='$423.12', is_debit=False)
        self.assertEqual(trans.amount, -423120000)
        self.assertFalse(trans.is_debit)
Example #7
0
    def test_get_mint_updates_no_itemize_arg_three_items(self):
        i1 = item(title='Really cool watch',
                  quantity=1,
                  item_subtotal='$10.00',
                  item_subtotal_tax='$1.00',
                  item_total='$11.00')
        i2 = item(title='Organic water',
                  quantity=1,
                  item_subtotal='$6.00',
                  item_subtotal_tax='$0.00',
                  item_total='$6.00')
        o1 = order(subtotal='$16.00',
                   tax_charged='$1.00',
                   total_charged='$17.00')
        t1 = transaction(amount='$17.00')

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1, i2], [], [t1],
                                          get_args(no_itemize=True), stats)

        self.assertEqual(len(updates), 1)
        orig_t, new_trans = updates[0]
        self.assertTrue(orig_t is t1)
        self.assertEqual(len(new_trans), 1)
        self.assertEqual(new_trans[0].merchant,
                         'Amazon.com: Really cool watch, Organic water')
        self.assertEqual(new_trans[0].category, 'Shopping')
        self.assertEqual(new_trans[0].amount, 17000000)
Example #8
0
    def test_get_mint_updates_verbose_itemize_arg(self):
        i1 = item()
        o1 = order(shipping_charge='$3.99', total_promotions='$3.99')
        t1 = transaction()

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1],
                                          get_args(verbose_itemize=True),
                                          stats)

        self.assertEqual(len(updates), 1)
        orig_t, new_trans = updates[0]
        self.assertTrue(orig_t is t1)
        self.assertEqual(len(new_trans), 3)
        self.assertEqual(new_trans[0].merchant, 'Amazon.com: Promotion(s)')
        self.assertEqual(new_trans[0].category, 'Shipping')
        self.assertEqual(new_trans[0].amount, -3990000)
        self.assertFalse(new_trans[0].is_debit)
        self.assertEqual(new_trans[1].merchant, 'Amazon.com: Shipping')
        self.assertEqual(new_trans[1].category, 'Shipping')
        self.assertEqual(new_trans[1].amount, 3990000)
        self.assertEqual(new_trans[2].merchant, 'Amazon.com: 2x Duracell AAs')
        self.assertEqual(new_trans[2].category, 'Shopping')
        self.assertEqual(new_trans[2].amount, 11950000)

        self.assertEqual(stats['new_tag'], 1)
Example #9
0
    def test_match(self):
        trans = transaction()
        orders = [1, 2, 3]
        trans.match(orders)

        self.assertTrue(trans.matched)
        self.assertEqual(trans.orders, orders)
    def test_get_mint_updates_simple_match_refund(self):
        r1 = refund(
            title='Cool item',
            refund_amount='$10.95',
            refund_tax_amount='$1.00',
            refund_date='3/12/14')
        t1 = transaction(amount='$11.95', is_debit=False, date='3/12/14')

        stats = Counter()
        updates, _ = tagger.get_mint_updates(
            [], [], [r1],
            [t1],
            get_args(), stats)

        self.assertEqual(len(updates), 1)
        orig_t, new_trans = updates[0]
        self.assertTrue(orig_t is t1)
        self.assertEqual(len(new_trans), 1)
        self.assertEqual(new_trans[0].merchant, 'Amazon.com: 2x Cool item')
        self.assertEqual(new_trans[0].category, 'Clothing')
        self.assertEqual(new_trans[0].amount, -11950000)
        self.assertFalse(new_trans[0].is_debit)
        self.assertFalse(new_trans[0].is_child)

        self.assertEqual(stats['new_tag'], 1)
Example #11
0
    def test_to_mint_transactions_free_shipping(self):
        orig_trans = transaction(amount='$20.00')

        o = order(total_charged='$20.00',
                  shipping_charge='$3.99',
                  total_promotions='$3.99')
        i1 = item(title='Item 1', item_total='$6.00', quantity='1')
        i2 = item(title='Item 2', item_total='$14.00', quantity='3')
        o.set_items([i1, i2])

        mint_trans_ship = o.to_mint_transactions(orig_trans,
                                                 skip_free_shipping=False)
        self.assertEqual(len(mint_trans_ship), 4)
        self.assertEqual(mint_trans_ship[0].merchant, '3x Item 2')
        self.assertEqual(mint_trans_ship[0].amount, 14000000)
        self.assertEqual(mint_trans_ship[1].merchant, 'Item 1')
        self.assertEqual(mint_trans_ship[1].amount, 6000000)
        self.assertEqual(mint_trans_ship[2].merchant, 'Shipping')
        self.assertEqual(mint_trans_ship[2].category, 'Shipping')
        self.assertEqual(mint_trans_ship[2].amount, 3990000)
        self.assertEqual(mint_trans_ship[3].merchant, 'Promotion(s)')
        self.assertEqual(mint_trans_ship[3].category, 'Shipping')
        self.assertEqual(mint_trans_ship[3].amount, -3990000)
        self.assertFalse(mint_trans_ship[3].is_debit)

        mint_trans_noship = o.to_mint_transactions(orig_trans,
                                                   skip_free_shipping=True)
        self.assertEqual(len(mint_trans_noship), 2)
        self.assertEqual(mint_trans_noship[0].merchant, '3x Item 2')
        self.assertEqual(mint_trans_noship[0].amount, 14000000)
        self.assertEqual(mint_trans_noship[1].merchant, 'Item 1')
        self.assertEqual(mint_trans_noship[1].amount, 6000000)
Example #12
0
 def test_split(self):
     trans = transaction()
     strans = trans.split(1234, 'Shopping', 'Some new item', 'Test note')
     self.assertNotEqual(trans, strans)
     self.assertEqual(strans.amount, 1234)
     self.assertEqual(strans.category, 'Shopping')
     self.assertEqual(strans.merchant, 'Some new item')
     self.assertEqual(strans.note, 'Test note')
Example #13
0
    def test_get_mint_updates_multi_orders_trans_same_date_and_amount(self):
        i1 = item(order_id='A')
        o1 = order(order_id='A')
        i2 = item(order_id='B')
        o2 = order(order_id='B')
        t1 = transaction()
        t2 = transaction()

        stats = Counter()
        updates = tagger.get_mint_updates([o1, o2], [i1, i2], [], [t1, t2],
                                          get_args(), stats)

        self.assertEqual(len(updates), 2)

        updates2 = tagger.get_mint_updates([o1, o2], [i1, i2], [], [t1, t2],
                                           get_args(num_updates=1), stats)

        self.assertEqual(len(updates2), 1)
Example #14
0
    def test_bastardize(self):
        child = transaction(pid=123)
        self.assertTrue(child.is_child)
        self.assertEqual(child.pid, 123)

        child.bastardize()

        self.assertFalse(child.is_child)
        self.assertFalse(hasattr(child, 'pid'))
Example #15
0
    def test_dry_run_str(self):
        trans = transaction()

        self.assertTrue('2/28/14' in trans.dry_run_str())
        self.assertTrue('$11.95' in trans.dry_run_str())
        self.assertTrue('Personal Care' in trans.dry_run_str())
        self.assertTrue('Amazon' in trans.dry_run_str())

        self.assertTrue('--IGNORED--' in trans.dry_run_str(True))
        self.assertFalse('Personal Care' in trans.dry_run_str(True))
Example #16
0
    def test_to_mint_transaction(self):
        r = refund(title='Duracell Procell AA 24 Pack')
        t = transaction(amount='$11.95', is_debit=False)

        new_trans = r.to_mint_transaction(t)

        self.assertEqual(new_trans.id, t.id)
        self.assertEqual(new_trans.amount, t.amount)
        self.assertEqual(new_trans.merchant, '2x Duracell Procell AA 24 Pack')
        self.assertFalse(new_trans.is_debit)
Example #17
0
    def test_match(self):
        r = refund()

        self.assertFalse(r.matched)
        self.assertEqual(r.trans_id, None)

        r.match(transaction(id='ABC'))

        self.assertTrue(r.matched)
        self.assertEqual(r.trans_id, 'ABC')
Example #18
0
    def test_match(self):
        o = order()

        self.assertFalse(o.matched)
        self.assertEqual(o.trans_id, None)

        o.match(transaction(id='abc'))

        self.assertTrue(o.matched)
        self.assertEqual(o.trans_id, 'abc')
Example #19
0
    def test_old_and_new_are_identical(self):
        trans1 = transaction(amount='$5.00', merchant='ABC')
        trans2 = transaction(amount='$5.00',
                             merchant='ABC',
                             category='Shipping')

        self.assertTrue(Transaction.old_and_new_are_identical(
            trans1, [trans1]))
        self.assertFalse(
            Transaction.old_and_new_are_identical(trans1, [trans2]))
        self.assertTrue(
            Transaction.old_and_new_are_identical(trans1, [trans2], True))

        new_trans = [
            transaction(amount='$2.50', merchant='ABC'),
            transaction(amount='$2.50', merchant='ABC'),
        ]
        trans1.children = new_trans
        self.assertTrue(
            Transaction.old_and_new_are_identical(trans1, new_trans))
Example #20
0
    def test_get_mint_updates_retag_arg(self):
        i1 = item()
        o1 = order()
        t1 = transaction(merchant='Amazon.com: already tagged')

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1],
                                          get_args(retag_changed=True), stats)

        self.assertEqual(len(updates), 1)
        self.assertEqual(stats['retag'], 1)
    def test_get_mint_updates_multi_domains_no_retag(self):
        i1 = item()
        o1 = order()
        t1 = transaction(merchant='Amazon.co.uk: already tagged')

        stats = Counter()
        updates, _ = tagger.get_mint_updates(
            [o1], [i1], [],
            [t1],
            get_args(), stats)

        self.assertEqual(len(updates), 0)
Example #22
0
    def test_get_mint_updates_no_update_for_identical(self):
        i1 = item()
        o1 = order()
        t1 = transaction(merchant='Amazon.com: 2x Duracell AAs',
                         category='Shopping')

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1],
                                          get_args(retag_changed=True), stats)

        self.assertEqual(len(updates), 0)
        self.assertEqual(stats['already_up_to_date'], 1)
Example #23
0
    def test_get_mint_updates_no_tag_categories_arg(self):
        i1 = item()
        o1 = order()
        t1 = transaction(merchant='Amazon.com: 2x Duracell AAs')

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1],
                                          get_args(no_tag_categories=True),
                                          stats)

        self.assertEqual(len(updates), 0)
        self.assertEqual(stats['already_up_to_date'], 1)
Example #24
0
    def test_get_mint_updates_skip_already_tagged(self):
        i1 = item()
        o1 = order()
        t1 = transaction(merchant='SomeRandoCustomPrefix: already tagged')

        stats = Counter()
        updates = tagger.get_mint_updates(
            [o1], [i1], [], [t1],
            get_args(description_prefix='SomeRandoCustomPrefix: '), stats)

        self.assertEqual(len(updates), 0)
        self.assertEqual(stats['no_retag'], 1)
Example #25
0
    def test_update_category_id(self):
        trans = transaction()
        # Give it a mismatch initially:
        trans.category_id = 99
        trans.update_category_id(category.DEFAULT_MINT_CATEGORIES_TO_IDS)
        self.assertEqual(trans.category_id, 4)

        trans.category = 'SOME INVALID CAT'
        with self.assertRaises(AssertionError):
            trans.update_category_id(category.DEFAULT_MINT_CATEGORIES_TO_IDS)

        trans.category = 'Shopping'
        trans.update_category_id(category.DEFAULT_MINT_CATEGORIES_TO_IDS)
        self.assertEqual(trans.category_id, 2)
Example #26
0
    def test_get_mint_updates_no_itemize_arg_single_item(self):
        i1 = item()
        o1 = order(total_charged='$15.94', shipping_charge='$3.99')
        t1 = transaction(amount='$15.94')

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1],
                                          get_args(no_itemize=True), stats)

        self.assertEqual(len(updates), 1)
        orig_t, new_trans = updates[0]
        self.assertTrue(orig_t is t1)
        self.assertEqual(len(new_trans), 1)
        self.assertEqual(new_trans[0].merchant, 'Amazon.com: 2x Duracell AAs')
        self.assertEqual(new_trans[0].category, 'Shopping')
        self.assertEqual(new_trans[0].amount, 15940000)
Example #27
0
    def test_get_mint_updates_simple_match(self):
        i1 = item()
        o1 = order()
        t1 = transaction()

        stats = Counter()
        updates = tagger.get_mint_updates([o1], [i1], [], [t1], get_args(),
                                          stats)

        self.assertEqual(len(updates), 1)
        orig_t, new_trans = updates[0]
        self.assertTrue(orig_t is t1)
        self.assertEqual(len(new_trans), 1)
        self.assertEqual(new_trans[0].merchant, 'Amazon.com: 2x Duracell AAs')
        self.assertEqual(new_trans[0].category, 'Shopping')
        self.assertEqual(new_trans[0].amount, 11950000)
        self.assertTrue(new_trans[0].is_debit)
        self.assertFalse(new_trans[0].is_child)

        self.assertEqual(stats['new_tag'], 1)
Example #28
0
    def test_unsplit(self):
        self.assertEqual(Transaction.unsplit([]), [])

        not_child1 = transaction(
            amount='$1.00')
        self.assertEqual(Transaction.unsplit([not_child1]), [not_child1])

        not_child2 = transaction(
            amount='$2.00')
        self.assertEqual(
            Transaction.unsplit([not_child1, not_child2]),
            [not_child1, not_child2])

        child1_to_1 = transaction(
            amount='$3.00',
            pid=1)
        child2_to_1 = transaction(
            amount='$4.00',
            pid=1)
        child3_to_1 = transaction(
            amount='$8.00',
            is_debit=False,
            pid=1)
        child1_to_99 = transaction(
            amount='$5.00',
            pid=99)

        one_child_actual = Transaction.unsplit([child1_to_1])
        self.assertEqual(one_child_actual[0].amount, child1_to_1.amount)
        self.assertFalse(one_child_actual[0].is_child)
        self.assertEqual(one_child_actual[0].id, 1)
        self.assertEqual(one_child_actual[0].children, [child1_to_1])

        three_children = [child1_to_1, child2_to_1, child3_to_1]
        three_child_actual = Transaction.unsplit(three_children)
        self.assertEqual(three_child_actual[0].amount, -1000000)
        self.assertFalse(three_child_actual[0].is_child)
        self.assertEqual(three_child_actual[0].id, 1)
        self.assertEqual(three_child_actual[0].children, three_children)

        crazy_actual = Transaction.unsplit(
            [not_child1, not_child2] + three_children + [child1_to_99])
        self.assertEqual(crazy_actual[0], not_child1)
        self.assertEqual(crazy_actual[1], not_child2)
        self.assertEqual(crazy_actual[2].id, 1)
        self.assertEqual(crazy_actual[2].children, three_children)
        self.assertEqual(crazy_actual[3].id, 99)
        self.assertEqual(crazy_actual[3].children, [child1_to_99])
Example #29
0
    def test_to_mint_transactions_ship_promo_mismatch(self):
        orig_trans = transaction(amount='$20.00')

        o = order(total_charged='$20.00',
                  shipping_charge='$3.99',
                  total_promotions='$1.00')
        i = item(title='Item 1', item_total='$20.00', quantity='4')
        o.set_items([i])

        mint_trans_ship = o.to_mint_transactions(orig_trans,
                                                 skip_free_shipping=True)
        self.assertEqual(len(mint_trans_ship), 3)
        self.assertEqual(mint_trans_ship[0].merchant, '4x Item 1')
        self.assertEqual(mint_trans_ship[0].amount, 20000000)
        self.assertEqual(mint_trans_ship[1].merchant, 'Shipping')
        self.assertEqual(mint_trans_ship[1].category, 'Shipping')
        self.assertEqual(mint_trans_ship[1].amount, 3990000)
        self.assertEqual(mint_trans_ship[2].merchant, 'Promotion(s)')
        self.assertEqual(mint_trans_ship[2].category, 'Shopping')
        self.assertEqual(mint_trans_ship[2].amount, -1000000)
        self.assertFalse(mint_trans_ship[2].is_debit)