Esempio n. 1
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]))
Esempio n. 2
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))
Esempio n. 3
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)
Esempio n. 4
0
    def test_happy_path(self):
        with mock.patch("builtins.open", mock.mock_open(read_data=INI_FILE)):
            config = BillWarriorConfig()

        timewparser = TimeWarriorParser(StringIO(TIMEW_REPORT))

        invoice = Invoice(timewparser.get_intervals(), config)

        self.assertEqual(str(invoice), EXPECTED_OUTPUT)
Esempio n. 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]))
Esempio n. 6
0
    def test_raises_exception_when_an_interval_does_not_belong_to_any_category(self):
        a, b = (
            tests.give_interval(tags=["meeting"]),
            tests.give_interval(tags=["coding", "stories"]),
        )

        billw_config = BillWarriorConfigFake.build(
            {"flight": "Travel", "coding": "Software Development"}
        )

        with self.assertRaisesRegex(
            ValueError,
            "These intervals with the following tags don't belong to any category: .",
        ) as e:
            Invoice([a, b], billw_config)
Esempio n. 7
0
    def test_raises_exception_when_interval_sorts_into_more_than_one_category(self):
        a, b = (
            tests.give_interval(tags=["videocall", "meeting"]),
            tests.give_interval(tags=["flight", "videocall", "other tag"]),
        )

        a_category = "Consulting & Research"
        tag_mapping = {
            "meeting": a_category,
            "videocall": a_category,
            "flight": "Travel",
        }

        billw_config = BillWarriorConfigFake.build(tag_mapping)

        with self.assertRaisesRegex(
            ValueError,
            "Intervals with the following tags belongs to more than one category: .",
        ) as e:
            Invoice([a, b], billw_config)