Пример #1
0
 def test_init(self):
     id = IncomesDatabase()
     id.update_income("xyz", "ABC", 10, 100, IncomesState.waiting)
     ik = IncomesKeeper()
     self.assertIsInstance(ik, IncomesKeeper)
     self.assertEqual(len(ik.incomes), 1)
     self.assertEqual(ik.incomes["xyz"]["expected_value"], 100)
Пример #2
0
 def test_get_income_value(self):
     id = IncomesDatabase()
     with self.assertLogs(logger, level=1) as l:
         self.assertEquals((0, 0), id.get_income_value("xyz", "DEF"))
     self.assertTrue(any("not exist" in log for log in l.output))
     id.update_income("xyz", "DEF", 20, 30, "SOMESTATE")
     self.assertEquals((20, 30), id.get_income_value("xyz", "DEF"))
     id.update_income("xyz", "DEF", 20, 30, "SOMESTATE")
Пример #3
0
    def test_get_newest_incomes(self):
        id = IncomesDatabase()
        for i in range(10):
            id.update_income("xyz{}".format(i), "DEF", i, i, "s")

        incomes = [income for income in id.get_newest_incomes(3)]
        self.assertEqual(len(incomes), 3)
        self.assertEqual(incomes[0].task, "xyz9")
        self.assertEqual(incomes[2].task, "xyz7")
        for i in range(20, 11, -1):
            id.update_income("xyz{}".format(i), "DEF", i, i, "s")
        incomes = [income for income in id.get_newest_incomes(3)]
        self.assertEqual(len(incomes), 3)
        self.assertEqual(incomes[0].task, "xyz12")
        self.assertEqual(incomes[2].task, "xyz14")
Пример #4
0
 def test_init(self):
     id = IncomesDatabase()
     self.assertIsInstance(id, IncomesDatabase)
Пример #5
0
 def test_update_income(self):
     id = IncomesDatabase()
     id.update_income("xyz", "DEF", 30, 20, "SOMESTATE")
     self.assertEqual(id.get_income_value("xyz", "DEF"), (30, 20))
     id.update_income("xyz", "DEF", 10, 30, "SOMESTATE", add_income=True)
     self.assertEqual(id.get_income_value("xyz", "DEF"), (40, 50))
     id.update_income("xyz", "DEF", 20, 50, "SOMESTATE", add_income=True)
     self.assertEqual(id.get_income_value("xyz", "DEF"), (60, 100))
     id.update_income("xyz", "DEF", 10, 10, "SOMESTATE")
     self.assertEqual(id.get_income_value("xyz", "DEF"), (10, 10))
Пример #6
0
 def test_get_state(self):
     id = IncomesDatabase()
     self.assertIsNone(id.get_state("xyz", "DEF"))
     id.update_income("xyz", "DEF", 30, 20, "SOMESTATE")
     self.assertEqual(id.get_state("xyz", "DEF"), "SOMESTATE")
Пример #7
0
    def test_change_state(self):
        id = IncomesDatabase()
        id.change_state("xyz", "DEF", "DIFFSTATE")
        id.update_income("xyz", "DEF", 20, 30, "SOMESTATE")
        id.update_income("abc", "DEF", 20, 30, "SOMEOTHERSTATE")
        id.update_income("xyz", "GHI", 20, 30, "SOMEOTHERSTATE")

        incomes = [income for income in id.get_newest_incomes()]
        self.assertEquals(len(incomes), 3)
        self.assertEqual(id.get_state("xyz", "DEF"), "SOMESTATE")
        id.change_state("xyz", "DEF", "DIFFSTATE")
        incomes = [(income.from_node_id, income.state, income.task)
                   for income in id.get_newest_incomes()]
        self.assertEquals(len(incomes), 3)
        self.assertEqual(id.get_state("xyz", "DEF"), "DIFFSTATE")
        self.assertEqual(id.get_state("abc", "DEF"), "SOMEOTHERSTATE")
        self.assertEqual(id.get_state("xyz", "GHI"), "SOMEOTHERSTATE")

        id.change_state("abc", "DEF", "DIFFSTATE2")
        id.change_state("xyz", "GHI", "DIFFSTATE3")
        incomes = [income for income in id.get_newest_incomes()]
        self.assertEquals(len(incomes), 3)
        self.assertEqual(id.get_state("xyz", "DEF"), "DIFFSTATE")
        self.assertEqual(id.get_state("abc", "DEF"), "DIFFSTATE2")
        self.assertEqual(id.get_state("xyz", "GHI"), "DIFFSTATE3")