Exemple #1
0
    def test_prints_invoice_categories_and_items(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},
        )
        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),
            ),
        )

        invoice = Invoice([a, b], billw_config)
        printed_invoice = str(invoice)

        self.assertIn(str(expected_a), printed_invoice)
        self.assertIn(str(expected_b), printed_invoice)
Exemple #2
0
    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]))
Exemple #3
0
    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))
Exemple #4
0
    def test_str_should_display_header_line_items_and_subtotal_as_latex_output(
            self):
        a, b = tests.give_interval(), tests.give_interval()
        entries = {a.get_date().date(): [a], b.get_date().date(): [b]}

        category = ItemCategory("arbitrary category", entries, 0.0)

        expected = "".join([
            "\\feetype{%s}\n" % category.header,
            "".join([
                "%s\n" % LineItem(i.get_date(), i.get_duration(), 0.0)
                for i in sorted([a, b], key=lambda x: x.get_date())
            ]),
            "\\subtotal\n",
            "%------------------------------------------------",
        ])

        self.assertEqual(category.__str__(), expected)
Exemple #5
0
    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]))
Exemple #6
0
    def test_line_items_should_be_populated_with_entries_per_day(self):
        a_day = datetime.today()
        entries = [
            [tests.give_interval(a_day + timedelta(days=1))],
            [tests.give_interval(a_day + timedelta(days=2))],
            [tests.give_interval(a_day + timedelta(days=3))],
        ]
        intervals_by_day = {entry[0].get_date().date(): entry for entry in entries}

        category = ItemCategory("arbitray category", intervals_by_day, 0.0)

        self.assertEqual(len(category.line_items), len(entries))
Exemple #7
0
    def test_line_items_should_be_sorted_by_date(self):
        entries = [
            [tests.give_interval()],
            [tests.give_interval()],
            [tests.give_interval()],
        ]
        dates = [entry[0].get_date().date() for entry in entries]

        category = ItemCategory("arbitray category", dict(zip(dates, entries)), 0.0)

        sorted_date_list = sorted([entry[0].get_date().date() for entry in entries])
        self.assertListEqual(
            [
                datetime.strptime(line_item.date, "%B %d, %Y").date()
                for line_item in category.line_items
            ],
            sorted_date_list,
        )
Exemple #8
0
 def test_items_omitted_when_unit_price_is_negative(self):
     category = ItemCategory("invisible work", {}, -1)
     self.assertEqual(str(category), "")
Exemple #9
0
 def test_header_should_display_formatted_tag_name_as_category_string(self):
     category = ItemCategory(" unclean tag   name ", {}, 0.0)
     self.assertEqual(category.header, "Unclean tag name")