def test_groups_intervals_of_same_category(self): same_day = datetime.today() a, b, c = ( tests.give_interval(same_day, tags=["on-site", "coding"]), tests.give_interval(same_day, tags=["coding", "off-site"]), tests.give_interval(tags=["coding", "cafe"]), ) billw_config = BillWarriorConfigFake.build( {"coding": "Consulting & Research"}) invoice = Invoice([a, b, c], billw_config) items = invoice.items() expected = ItemCategory( "Consulting & Research", { same_day.date(): [a, b], c.get_date().date(): [c] }, 0.0, ) self.assertEqual(len(items), 1) # one category self.assertEqual(str(items[0]), str(expected))
def test_alpha_orders_categories(self): a, b = ( tests.give_interval(tags=["meeting"]), tests.give_interval(tags=["coding", "stories"]), ) category_a = "Consulting & Research" category_b = "Software Development" billw_config = BillWarriorConfigFake.build( {"coding": category_b, "meeting": category_a}, {category_a: 12.02, category_b: 9.34}, ) invoice = Invoice([b, a], billw_config) items = invoice.items() expected_a, expected_b = ( ItemCategory( "Consulting & Research", {a.get_date().date(): [a]}, billw_config.rate_for(category_a), ), ItemCategory( "Software Development", {b.get_date().date(): [b]}, billw_config.rate_for(category_b), ), ) self.assertEqual(len(items), 2) self.assertEqual(str(expected_a), str(items[0])) self.assertEqual(str(expected_b), str(items[1]))
def test_creates_different_categories_from_interval_tags_and_mapping(self): a, b = ( tests.give_interval(tags=["videocall", "meeting"]), tests.give_interval(tags=["flight", "nyc"]), ) billw_config = BillWarriorConfigFake.build( {"meeting": "Consulting & Research", "flight": "Travel"} ) invoice = Invoice([a, b], billw_config) items = invoice.items() expected_a, expected_b = ( ItemCategory("Consulting & Research", {a.get_date().date(): [a]}, 0.0), ItemCategory("Travel", {b.get_date().date(): [b]}, 0.0), ) self.assertEqual(len(items), 2) self.assertEqual(str(expected_a), str(items[0])) self.assertEqual(str(expected_b), str(items[1]))
def test_sets_unit_price_for_item_category(self): a, b = ( tests.give_interval(tags=["meeting"]), tests.give_interval(tags=["coding", "stories"]), ) category_a = "Consulting & Research" category_b = "Software Development" billw_config = BillWarriorConfigFake.build( { "meeting": category_a, "coding": category_b }, { category_a: 9.34, category_b: 12.02 }, ) invoice = Invoice([a, b], billw_config) items = invoice.items() expected_a, expected_b = ( ItemCategory( "Consulting & Research", {a.get_date().date(): [a]}, billw_config.rate_for(category_a), ), ItemCategory( "Software Development", {b.get_date().date(): [b]}, billw_config.rate_for(category_b), ), ) self.assertEqual(len(items), 2) self.assertIn(str(expected_a), [str(item) for item in items]) self.assertIn(str(expected_b), [str(item) for item in items])