Exemple #1
0
 def test_refunds (self):
     user1 = User.fetch("user1")
     user2 = User.fetch("user2")
     project1 = Project.fetch("project1")
     project2 = Project.fetch("project2")
     res1 = Resource.fetch("res1")
     res2 = Resource.fetch("res2")
     start = datetime(2000, 1, 1)
     end = start + timedelta(weeks=1)
     a1 = Allocation(project1, res1, 10, start, end)
     a2 = Allocation(project1, res1, 20, start, end)
     a3 = Allocation(project2, res1, 30, start, end)
     a4 = Allocation(project2, res2, 35, start, end)
     c1 = Charge(a1, 10)
     c2 = Charge(a2, 15)
     c3 = Charge(a2, 5)
     c4 = Charge(a4, 9)
     c5 = Charge(a4, 8)
     for charge in (c1, c2, c3, c4, c5):
         charge.datetime = datetime(2000, 1, 1)
     Refund(c1, 4)
     Refund(c2, 3)
     Refund(c2, 5)
     Refund(c5, 8)
     Session.add_all([a1, a2, a3, a4])
     Session.flush()
     stdout, stderr = capture(lambda:
         print_charges_list([c1, c2, c3, c4, c5]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         1      2000-01-01 res1     project1                  6.0
         2      2000-01-01 res1     project1                  7.0
         3      2000-01-01 res1     project1                  5.0
         4      2000-01-01 res2     project2                  9.0
         5      2000-01-01 res2     project2                  0.0
         """))
     assert_equal_multiline(stderr.getvalue(), dedent("""\
         #      Date       Resource Project               Charged
         ------ ---------- -------- --------------- -------------
                                                    -------------
                                                             27.0
         Units are undefined.
         """))
Exemple #2
0
 def test_holds (self):
     project1 = Project.fetch("project1")
     project2 = Project.fetch("project2")
     res1 = Resource.fetch("res1")
     res2 = Resource.fetch("res2")
     start = datetime(2000, 1, 1)
     end = start + timedelta(weeks=1)
     a1 = Allocation(project1, res1, 10, start, end)
     a2 = Allocation(project1, res1, 20, start, end)
     a3 = Allocation(project2, res1, 30, start, end)
     a4 = Allocation(project2, res2, 35, start, end)
     h1 = Hold(a1, 10)
     h2 = Hold(a2, 15)
     h3 = Hold(a2, 5)
     h4 = Hold(a4, 9)
     h5 = Hold(a4, 8)
     for hold in (h1, h2, h3, h4, h5):
         hold.datetime = datetime(2000, 1, 1)
     Session.add_all([a1, a2, a3, a4])
     Session.flush()
     stdout, stderr = capture(lambda:
         print_holds_list([h1, h2, h3, h4, h5]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         1      2000-01-01 res1     project1                 10.0
         2      2000-01-01 res1     project1                 15.0
         3      2000-01-01 res1     project1                  5.0
         4      2000-01-01 res2     project2                  9.0
         5      2000-01-01 res2     project2                  8.0
         """))
     assert_equal_multiline(stderr.getvalue(), dedent("""\
         #      Date       Resource Project                  Held
         ------ ---------- -------- --------------- -------------
                                                    -------------
                                                             47.0
         Units are undefined.
         """))