def test_jobs (self): project_1 = Project.cached("1") project_2 = Project.cached("2") resource_1 = Resource.cached("1") resource_2 = Resource.cached("1") start = datetime(2000, 1, 1) end = start + timedelta(weeks=1) allocation_1 = Allocation(project_1, resource_1, 0, start, end) allocation_2 = Allocation(project_2, resource_2, 0, start, end) job_1 = Job("1.1") job_2 = Job("1.2") job_3 = Job("1.3") job_4 = Job("2.1") job_5 = Job("2.2") charge_1 = Charge(allocation_1, 0) charge_2 = Charge(allocation_1, 0) charge_3 = Charge(allocation_1, 0) charge_4 = Charge(allocation_2, 0) charge_5 = Charge(allocation_2, 0) charge_1.job = job_1 charge_2.job = job_2 charge_3.job = job_3 charge_4.job = job_4 charge_5.job = job_5 job_1.account = project_1 job_2.account = project_1 job_3.account = project_1 job_4.account = project_2 job_5.account = project_2 Session.add_all([job_1, job_2, job_3, job_4, job_5]) assert_equal(list(project_summary([project_1, project_2])), [("1", 3, 0, 0), ("2", 2, 0, 0)])
def test_effective_amount (self): charge = Charge(None, 10) assert_equal(charge.effective_amount(), 10) refund_1 = Mock(['amount']) refund_1.amount = 1 charge.refunds.append(refund_1) assert_equal(charge.effective_amount(), 9) refund_2 = Mock(['amount']) refund_2.amount = 2 charge.refunds.append(refund_2) assert_equal(charge.effective_amount(), 7)
def test_amount_refunded (self): charge = Charge(None, None) assert_equal(charge.amount_refunded(), 0) refund_1 = Mock(['amount']) refund_1.amount = 1 charge.refunds.append(refund_1) assert_equal(charge.amount_refunded(), 1) refund_2 = Mock(['amount']) refund_2.amount = 2 charge.refunds.append(refund_2) assert_equal(charge.amount_refunded(), 3)
def test_users_filter (self): project_1 = Project.cached("1") project_2 = Project.cached("2") resource_1 = Resource.cached("1") resource_2 = Resource.cached("2") user_1 = User.cached("1") user_2 = User.cached("2") start = datetime(2000, 1, 1) end = start + timedelta(weeks=1) allocation_1 = Allocation(project_1, resource_1, 10, start, end) allocation_2 = Allocation(project_1, resource_1, 20, start, end) allocation_3 = Allocation(project_2, resource_1, 30, start, end) allocation_4 = Allocation(project_2, resource_2, 35, start, end) charge_1 = Charge(allocation_1, 10) charge_2 = Charge(allocation_2, 15) charge_3 = Charge(allocation_2, 5) charge_4 = Charge(allocation_4, 9) charge_5 = Charge(allocation_4, 8) Refund(charge_1, 4) Refund(charge_2, 3) Refund(charge_2, 5) Refund(charge_5, 8) Hold(allocation_4, 9) hold_2 = Hold(allocation_4, 8) hold_2.active = False charge_1.job = Job("1.1") charge_2.job = Job("1.2") charge_3.job = Job("1.3") charge_4.job = Job("2.1") charge_5.job = Job("2.2") charge_1.job.user = user_1 charge_2.job.user = user_2 charge_3.job.user = user_1 charge_4.job.user = user_1 charge_5.job.user = user_2 allocations = [allocation_1, allocation_2, allocation_3, allocation_4] Session.add_all(allocations) Session.flush() assert_equal( list(allocation_summary(allocations, users=[user_1])), [(allocation_1, 1, 6, 4), (allocation_2, 1, 5, 8), (allocation_3, 0, 0, 30), (allocation_4, 1, 9, 17)])
def test_default_refund (self): charge = Charge(None, 10) charge.refunds.append(Refund(charge, 3)) charge.refund() cbank.model.entities.Refund.assert_called_with( charge, 7)
def test_refund_too_much (self): charge = Charge(None, 0) refund = charge.refund(1)
def test_refund (self): charge = Charge(None, 0) refund = charge.refund(0) cbank.model.entities.Refund.assert_called_with( charge, 0) assert_equal(refund, sentinel.refund)
def test_refund_more_than_charge (self): charge = Charge(None, 0) refund = charge.refund(1)