예제 #1
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)
예제 #2
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)
예제 #3
0
    def test_merge_multi_orders(self):
        o1 = order()
        i1 = item()
        i2 = item()
        o1.set_items([i1, i2])

        o2 = order()
        i3 = item()
        o2.set_items([i3])

        o3 = order()
        i4 = item()
        i5 = item(title='Different!')
        o3.set_items([i4, i5])

        merged = Order.merge([o1, o2, o3])
        self.assertEqual(merged.total_charged, 35850000)
        self.assertEqual(merged.tax_charged, 3150000)
        self.assertEqual(merged.shipping_charge, 0)

        self.assertEqual(len(merged.items), 2)
        self.assertEqual(merged.items[0].quantity, 8)
        self.assertEqual(merged.items[0].item_total, 47800000)
        self.assertEqual(merged.items[1].quantity, 2)
        self.assertEqual(merged.items[1].item_total, 11950000)
예제 #4
0
    def test_get_title(self):
        i = item(title='The best item ever!')
        self.assertEqual(i.get_title(), '2x The best item ever')
        self.assertEqual(i.get_title(10), '2x The best')

        i2 = item(title='Something alright (]][', quantity=1)
        self.assertEqual(i2.get_title(), 'Something alright')
예제 #5
0
    def test_sum_subtotals_tax(self):
        self.assertEqual(Item.sum_subtotals_tax([]), 0)

        i1 = item(item_subtotal_tax='$0.43')
        self.assertEqual(Item.sum_subtotals_tax([i1]), 430000)

        i2 = item(item_subtotal_tax='$0.00')
        self.assertEqual(Item.sum_subtotals_tax([i1, i2]), 430000)
        self.assertEqual(Item.sum_subtotals_tax([i2, i1]), 430000)

        i3 = item(item_subtotal_tax='$2.11')
        self.assertEqual(Item.sum_subtotals_tax([i2, i1, i3]), 2540000)
예제 #6
0
    def test_merge_one_order(self):
        o1 = order()
        i1 = item()
        i2 = item()
        o1.set_items([i1, i2])

        merged = Order.merge([o1])
        self.assertTrue(merged is o1)

        self.assertEqual(len(merged.items), 1)
        self.assertEqual(merged.items[0].quantity, 4)
        self.assertEqual(merged.items[0].item_total, 23900000)
예제 #7
0
    def test_sum_totals(self):
        self.assertEqual(Item.sum_totals([]), 0)

        i1 = item(item_total='-$5.43')
        self.assertEqual(Item.sum_totals([i1]), -5430000)

        i2 = item(item_total='-$44.11')
        self.assertEqual(Item.sum_totals([i1, i2]), -49540000)
        self.assertEqual(Item.sum_totals([i2, i1]), -49540000)

        i3 = item(item_total='$2.11')
        self.assertEqual(Item.sum_totals([i2, i1, i3]), -47430000)
예제 #8
0
    def test_associate_items_with_orders_multiple_items_subtotal_match(self):
        oid1 = 'Order1'
        i1 = item(order_id=oid1, item_subtotal='$20.21', quantity=6)
        i2 = item(order_id=oid1, item_subtotal='$2.01', quantity=1)
        i3 = item(order_id=oid1, item_subtotal='$0.41')
        items = [i1, i2, i3]

        o1 = order(order_id=oid1, subtotal='$22.63')

        amazon.associate_items_with_orders([o1], items)

        self.assertTrue(o1.items_matched)
        self.assertEqual(o1.items, items)
예제 #9
0
    def test_associate_items_with_orders_none_match(self):
        i1 = item(order_id='1', item_subtotal='$100.00')
        i2 = item(order_id='2')
        i3 = item(order_id='3')
        i4 = item(order_id='4')

        oa = order(order_id='A')
        o1 = order(order_id='1', subtotal='$5.00')

        amazon.associate_items_with_orders([oa, o1], [i1, i2, i3, i4])

        self.assertFalse(oa.items_matched)
        self.assertEqual(oa.items, [])
        self.assertFalse(o1.items_matched)
        self.assertEqual(o1.items, [])
예제 #10
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)
예제 #11
0
    def test_associate_items_with_orders_single_item_subtotal_match(self):
        i1 = item()
        o1 = order()

        amazon.associate_items_with_orders([o1], [i1])

        self.assertTrue(o1.items_matched)
        self.assertEqual(o1.items, [i1])
예제 #12
0
    def test_attribute_itemized_diff_to_shipping_tax_matches(self):
        o = order(total_charged='$10.00',
                  subtotal='$6.01',
                  tax_charged='$0.00',
                  shipping_charge='$3.99')
        i = item(item_total='$6.01')
        o.set_items([i])

        self.assertFalse(o.attribute_itemized_diff_to_shipping_tax())
예제 #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)
예제 #14
0
    def test_merge(self):
        i1 = item()
        i2 = item()
        i3 = item(title='Something diff')

        merged = Item.merge([i1, i2, i3])

        self.assertEqual(len(merged), 2)

        self.assertEqual(merged[0].quantity, 4)
        self.assertEqual(merged[0].item_subtotal, 21800000)
        self.assertEqual(merged[0].item_subtotal_tax, 2100000)
        self.assertEqual(merged[0].item_total, 23900000)

        self.assertEqual(merged[1].quantity, 2)
        self.assertEqual(merged[1].item_subtotal, 10900000)
        self.assertEqual(merged[1].item_subtotal_tax, 1050000)
        self.assertEqual(merged[1].item_total, 11950000)
예제 #15
0
    def test_associate_items_with_orders_multi_single_matches(self):
        i1 = item(order_id='1')
        o1 = order(order_id='1')
        i2 = item(order_id='2')
        o2 = order(order_id='2')
        i3 = item(order_id='3')
        o3 = order(order_id='3')

        amazon.associate_items_with_orders([o1, o2, o3], [i3, i2, i1])

        self.assertTrue(o1.items_matched)
        self.assertEqual(o1.items, [i1])

        self.assertTrue(o2.items_matched)
        self.assertEqual(o2.items, [i2])

        self.assertTrue(o3.items_matched)
        self.assertEqual(o3.items, [i3])
예제 #16
0
    def test_split_by_quantity(self):
        i = item()
        items = i.split_by_quantity()

        self.assertEqual(len(items), 2)
        for it in items:
            self.assertEqual(it.quantity, 1)
            self.assertEqual(it.item_subtotal, 5450000)
            self.assertEqual(it.item_subtotal_tax, 525000)
            self.assertEqual(it.item_total, 5975000)
예제 #17
0
    def test_attribute_itemized_diff_to_per_item_tax_correct(self):
        o = order(total_charged='$10.00',
                  subtotal='$9.00',
                  tax_charged='$1.00')
        i = item(item_total='$10.00',
                 item_subtotal='$9.00',
                 item_subtotal_tax='$1.00')
        o.set_items([i])

        self.assertFalse(o.attribute_itemized_diff_to_per_item_tax())
예제 #18
0
    def test_associate_items_with_orders_multi_orders_and_items_by_track(self):
        # All items and orders have the same order id, but they shipped in
        # different packages.
        oid = 'ABC'
        i1 = item(order_id=oid, item_subtotal='$20.21', tracking='A')
        i2 = item(order_id=oid, item_subtotal='$2.01', tracking='A')
        i3 = item(order_id=oid, item_subtotal='$0.41', tracking='B')
        a_items = [i1, i2]
        b_items = [i3]

        o1 = order(order_id=oid, subtotal='$22.22', tracking='A')
        o2 = order(order_id=oid, subtotal='$0.41', tracking='B')

        amazon.associate_items_with_orders([o1, o2], a_items + b_items)

        self.assertTrue(o1.items_matched)
        self.assertEqual(o1.items, a_items)

        self.assertTrue(o2.items_matched)
        self.assertEqual(o2.items, b_items)
예제 #19
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)
예제 #20
0
    def test_set_items(self):
        o = order()
        self.assertFalse(o.items_matched)
        self.assertEqual(o.items, [])

        i1 = item()
        i2 = item()
        self.assertFalse(i1.matched)
        self.assertEqual(i1.order, None)
        self.assertFalse(i2.matched)
        self.assertEqual(i2.order, None)

        o.set_items([i1, i2])
        self.assertTrue(o.items_matched)
        self.assertEqual(o.items, [i1, i2])

        self.assertTrue(i1.matched)
        self.assertEqual(i1.order, o)
        self.assertTrue(i2.matched)
        self.assertEqual(i2.order, o)
예제 #21
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)
예제 #22
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)
예제 #23
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)
    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)
예제 #25
0
    def test_attribute_itemized_diff_to_per_item_tax_not_just_tax(self):
        o = order(total_charged='$10.00',
                  subtotal='$9.00',
                  tax_charged='$1.00')
        # The difference in the order total and the itemized total ($.50) is
        # _not_ equal to the difference in order total tax and itemized total
        # tax ($0.25).
        i = item(item_total='$9.50',
                 item_subtotal='$9.00',
                 item_subtotal_tax='$0.75')
        o.set_items([i])

        self.assertFalse(o.attribute_itemized_diff_to_per_item_tax())
예제 #26
0
    def test_attribute_itemized_diff_to_shipping_tax_mismatch(self):
        o = order(total_charged='$10.00',
                  subtotal='$5.50',
                  tax_charged='$1.40',
                  tax_before_promotions='$1.40',
                  shipping_charge='$3.99')
        i = item(item_total='$5.50')
        o.set_items([i])

        self.assertTrue(o.attribute_itemized_diff_to_shipping_tax())
        self.assertEqual(o.shipping_charge, 4500000)
        self.assertEqual(o.tax_charged, 890000)
        self.assertEqual(o.tax_before_promotions, 890000)
예제 #27
0
    def test_attribute_itemized_diff_to_per_item_tax_itemize_due_to_tax(self):
        o = order(total_charged='$10.00',
                  subtotal='$9.00',
                  tax_charged='$1.00')
        i = item(item_total='$9.99',
                 item_subtotal='$9.00',
                 item_subtotal_tax='$0.99')
        o.set_items([i])

        self.assertTrue(o.attribute_itemized_diff_to_per_item_tax())
        self.assertEqual(i.item_total, 10000000)
        self.assertEqual(i.item_subtotal, 9000000)
        self.assertEqual(i.item_subtotal_tax, 1000000)
예제 #28
0
    def test_total_by_items(self):
        o1 = order(subtotal='$5.55')
        self.assertEqual(o1.total_by_items(), 0)

        o1.set_items([
            item(item_total='$4.44'),
        ])
        self.assertEqual(o1.total_by_items(), 4440000)

        o2 = order(subtotal='$5.55')
        o2.set_items([
            item(item_total='$4.44'),
            item(item_total='$0.01'),
            item(item_total='$60.00'),
        ])
        self.assertEqual(o2.total_by_items(), 64450000)

        o3 = order(subtotal='$5.55',
                   shipping_charge='$4.99',
                   total_promotions='$4.99')
        o3.set_items([
            item(item_total='$6.44'),
        ])
        self.assertEqual(o3.total_by_items(), 6440000)
예제 #29
0
    def test_set_quantity(self):
        i = item()
        i.set_quantity(3)

        self.assertEqual(i.quantity, 3)
        self.assertEqual(i.item_subtotal, 16350000)
        self.assertEqual(i.item_subtotal_tax, 1575000)
        self.assertEqual(i.item_total, 17925000)

        i.set_quantity(1)

        self.assertEqual(i.quantity, 1)
        self.assertEqual(i.item_subtotal, 5450000)
        self.assertEqual(i.item_subtotal_tax, 525000)
        self.assertEqual(i.item_total, 5975000)
예제 #30
0
    def test_attribute_subtotal_diff_to_misc_charge(self):
        o = order(total_charged='$10.00',
                  subtotal='$6.01',
                  tax_charged='$0.00')
        i = item(item_total='$6.01')
        o.set_items([i])

        self.assertTrue(o.attribute_subtotal_diff_to_misc_charge())
        self.assertEqual(o.subtotal, 10000000)
        self.assertEqual(len(o.items), 2)
        self.assertEqual(o.items[1].item_total, 3990000)
        self.assertEqual(o.items[1].item_subtotal, 3990000)
        self.assertEqual(o.items[1].item_subtotal_tax, 0)
        self.assertEqual(o.items[1].quantity, 1)
        self.assertEqual(o.items[1].category, 'Shopping')
        self.assertEqual(o.items[1].title, 'Misc Charge (Gift wrap, etc)')