class SortCategoryEntriesTestCase(unittest.TestCase): def setUp(self): self.listing = Listing() for c, v in zip("ab", [20, 10]): self.listing.add_entry(BaseEntry("foo", v, "01-01"), c) def test_sort_by_name(self): self.assertEqual( self.listing.prettify(category_sort="name"), '\n'.join([ "{1:^{0}}".format(CategoryEntry.TOTAL_LENGTH, "Listing"), "Name Value Date ID ", "A 20.00" + 10 * " ", " Foo 20.00 01-01 0", "B 10.00" + 10 * " ", " Foo 10.00 01-01 0", ])) def test_sort_by_value(self): self.assertEqual( self.listing.prettify(), '\n'.join([ "{1:^{0}}".format(CategoryEntry.TOTAL_LENGTH, "Listing"), "Name Value Date ID ", "B 10.00" + 10 * " ", " Foo 10.00 01-01 0", "A 20.00" + 10 * " ", " Foo 20.00 01-01 0", ]))
class AddBaseEntryTestCase(unittest.TestCase): def setUp(self): self.listing = Listing() self.item_name = "Aldi" self.item_value = 66.6 self.item_date = "11-08" self.item_category = "Groceries" self.listing.add_entry( BaseEntry(self.item_name, self.item_value, self.item_date), self.item_category) def test_str(self): self.assertEqual( self.listing.prettify(), '\n'.join([ "{1:^{0}}".format(CategoryEntry.TOTAL_LENGTH, "Listing"), "Name Value Date ID ", "Groceries 66.60" + 10 * " ", " Aldi 66.60 11-08 0" ])) def test_str_no_eid(self): BaseEntry.SHOW_EID = False self.assertEqual( self.listing.prettify(), '\n'.join([ "{1:^{0}}".format(CategoryEntry.TOTAL_LENGTH, "Listing"), "Name Value Date ", # TODO: fix this; category entry line has to be shorter "Groceries 66.60 ", " Aldi 66.60 11-08" ])) BaseEntry.SHOW_EID = True def test_add_invalid_entry(self): self.assertRaises(TypeError, self.listing.add_entry, None)
class AddNegativeBaseEntryTestCase(unittest.TestCase): def setUp(self): self.listing = Listing() self.item_name = "Aldi" self.item_value = -66.6 self.item_date = "11-08" self.item_category = "Groceries" self.listing.add_entry( BaseEntry(self.item_name, self.item_value, self.item_date), self.item_category) def test_str(self): self.assertEqual( self.listing.prettify(), '\n'.join([ "{1:^{0}}".format(CategoryEntry.TOTAL_LENGTH, "Listing"), "Name Value Date ID ", "Groceries 66.60" + 10 * " ", " Aldi 66.60 11-08 0" ]))