def test_hourly_union_member_service_charge(self): emp_id = EmpId(1) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.24) transaction.execute() member_id = MemberId(7734) transaction = ChangeMemberTransaction(emp_id, member_id, dues=9.42) transaction.execute() pay_date = date(2001, 11, 9) transaction = ServiceChargeTransaction(member_id, pay_date, charge=19.42) transaction.execute() transaction = TimecardTransaction(emp_id, pay_date, hours=8.0) transaction.execute() transaction = PaydayTransaction(pay_date) transaction.execute() paycheck = transaction.get_paycheck(emp_id) self.assertEqual(pay_date, paycheck.get_period_end_date()) self.assertEqual(8 * 15.24, paycheck.get_gross_pay()) self.assertEqual('Hold', paycheck.get_field('Disposition')) self.assertEqual(9.42 + 19.42, paycheck.get_deductions()) self.assertEqual(8 * 15.24 - (9.42 + 19.42), paycheck.get_net_pay())
def test_changing_name_of_an_employee(): db = MemoryDB() empId = AddHourlyEmployee("wrong", "Home", 1, db).execute() cnt = ChangeName(empId, "Bill", db) cnt.execute() e = db.get_employee(empId) assert e.name == "Bill"
def test_changing_an_address_of_an_employee(): db = MemoryDB() empId = AddHourlyEmployee("Bohn", "wrong", 1, db).execute() cat = ChangeAddress(empId, "Home", db) cat.execute() e = db.get_employee(empId) assert e is not None assert e.address == "Home"
def test_change_address_transaction(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() transaction = ChangeAddressTransaction(emp_id, 'Garage') transaction.execute() employee = g_payroll_database.get_employee(emp_id) self.assertEqual('Garage', employee.get_address())
def test_change_name_transaction(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() transaction = ChangeNameTransaction(emp_id, 'Bob') transaction.execute() employee = g_payroll_database.get_employee(emp_id) self.assertEqual('Bob', employee.get_name())
def test_paying_nothing_to_an_hourly_employee_with_no_timecards(): db = MemoryDB() empId = AddHourlyEmployee("Bob", "Home", 15.25, db).execute() pay_date = datetime.date(2001, 11, 9) pt = Payday(pay_date, db) pt.execute() pc = pt.get_paycheck(empId) assert pc.pay_date == datetime.date(2001, 11, 9) assert pc.gross_pay == 0 assert pc.deductions == 0 assert pc.net_pay == 0
def test_not_paying_an_hourly_employee_on_wrong_date(): db = MemoryDB() empId = AddHourlyEmployee("Bob", "Home", 15.25, db).execute() pay_date = datetime.date(2001, 11, 29) pt = Payday(pay_date, db) pt.execute() try: pt.get_paycheck(empId) raise "pay on wrong date" except KeyError: pass
def test_pay_single_hourly_employee_no_time_cards(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() pay_date = date(2001, 11, 9) # Friday transaction = PaydayTransaction(pay_date) transaction.execute() self.validate_paycheck(transaction, emp_id, pay_date, 0.0)
def test_deleting_an_employee(): db = MemoryDB() empId = AddHourlyEmployee("Jim", "Home", 32.25, db).execute() db.get_employee(empId) dt = DeleteEmployee(empId, db) dt.execute() try: db.get_employee(empId) raise "employee not deleted" except KeyError: pass
def test_pay_single_hourly_employee_one_wrong_date(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() pay_date = date(2001, 11, 8) # Thursday transaction = TimecardTransaction(emp_id, pay_date, hours=9.0) transaction.execute() transaction = PaydayTransaction(pay_date) transaction.execute() self.assertFalse(transaction.get_paycheck(emp_id))
def test_paying_an_hourly_employee_for_over_time(): db = MemoryDB() empId = AddHourlyEmployee("Bob", "Home", 10.0, db).execute() pay_date = datetime.date(2001, 11, 9) AddTimeCard(empId, pay_date, 10.0, db).execute() pt = Payday(pay_date, db) pt.execute() pc = pt.get_paycheck(empId) assert pc.pay_date == datetime.date(2001, 11, 9) print pc.gross_pay assert pc.gross_pay == 110 assert pc.deductions == 0 assert pc.net_pay == 110
def test_paying_an_hourly_employee_only_in_one_period(): db = MemoryDB() empId = AddHourlyEmployee("Bob", "Home", 15.25, db).execute() pay_date = datetime.date(2001, 11, 9) AddTimeCard(empId, pay_date, 2.0, db).execute() AddTimeCard(empId, datetime.date(2001, 11, 1), 2.0, db).execute() pt = Payday(pay_date, db) pt.execute() pc = pt.get_paycheck(empId) assert pc.pay_date == datetime.date(2001, 11, 9) assert pc.gross_pay == 30.5 assert pc.deductions == 0 assert pc.net_pay == 30.5
def test_changing_an_employee_to_be_in_a_union_affiliation(): db = MemoryDB() empId = AddHourlyEmployee("Jim", "Home", 12.25, db).execute() cut = ChangeUnionMember(empId, 99.42, db) cut.execute() e = db.get_employee(empId) af = e.affiliation assert af is not None assert af.dues == 99.42 member = db.get_union_member(e.memberId) assert member is e
def test_change_salaried_transaction(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() transaction = ChangeSalariedTransaction(emp_id, salary=1000) transaction.execute() employee = g_payroll_database.get_employee(emp_id) classification = employee.get_classification() self.assertIsInstance(classification, SalariedClassification) self.assertEqual(1000, classification.get_salary()) self.assertIsInstance(employee.get_schedule(), MonthlySchedule)
def test_removing_affiliations_from_employee(): db = MemoryDB() empId = AddHourlyEmployee("Jim", "Home", 12.25, db).execute() ChangeUnionMember(empId, 99.42, db).execute() cut = ChangeUnaffiliated(empId, db) cut.execute() e = db.get_employee(empId) assert isinstance(e.affiliation, NoAffiliation) try: db.get_union_member(e.memberId) raise "member not deleted" except KeyError: pass
def test_timecard_transaction(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() transaction = TimecardTransaction(emp_id, date=20011031, hours=8.0) transaction.execute() employee = g_payroll_database.get_employee(emp_id) classification = employee.get_classification() timecard = classification.get_timecard(date=20011031) self.assertTrue(timecard) self.assertEqual(8.0, timecard.get_hours())
def test_changing_an_address_of_an_employee(): db = MemoryDB() empId = AddHourlyEmployee("Bohn", "wrong", 1, db).execute() cc = ChangeCommissioned(empId, 2.5, 1000, db) cc.execute() e = db.get_employee(empId) pc = e.classification assert isinstance(pc, CommissionedClassification) assert pc.baseRate == 1000 assert pc.commission == 2.5 ps = e.schedule assert isinstance(ps, BiWeeklySchedule)
def test_change_member_transaction(self): emp_id = EmpId(2) member_id = MemberId(7734) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() transaction = ChangeMemberTransaction(emp_id, member_id, dues=99.42) transaction.execute() employee = g_payroll_database.get_employee(emp_id) affiliation = employee.get_affiliation() self.assertIsInstance(affiliation, UnionAffiliation) self.assertEqual(99.42, affiliation.get_dues()) self.assertIs(employee, g_payroll_database.get_union_member(member_id))
def test_adding_an_hourly_paid_employee(): db = MemoryDB() at = AddHourlyEmployee("John", "Home", 15.75, db) empId = at.execute() e = db.get_employee(empId) assert e is not None assert e.id == empId assert e.name == "John" assert e.address == "Home" pc = e.classification assert isinstance(pc, HourlyClassification) assert pc.hourly_rate == 15.75 ps = e.schedule assert isinstance(ps, WeeklySchedule) pm = e.method assert isinstance(pm, HoldMethod)
def test_adding_a_time_card(): db = MemoryDB() t = AddHourlyEmployee("Bill", "Home", 15.25, db) empId = t.execute() date = datetime.date(2005, 3, 30) tct = AddTimeCard(empId, date, 8.0, db) tct.execute() e = db.get_employee(empId) assert e is not None pc = e.classification assert isinstance(pc, HourlyClassification) tc = pc.get_time_card(date) assert tc.hours == 8.0 assert tc.date == date
def test_add_hourly_employee(self): emp_id = EmpId(1) transaction = AddHourlyEmployee(emp_id, 'Bob', 'Home', hourly_rate=10.00) transaction.execute() employee = g_payroll_database.get_employee(emp_id) self.assertEqual('Bob', employee.get_name()) self.assertEqual('Home', employee.get_address()) classification = employee.get_classification() self.assertEqual(10.00, classification.get_hourly_rate()) self.assertIsInstance(classification, HourlyClassification) self.assertIsInstance(employee.get_schedule(), WeeklySchedule) self.assertIsInstance(employee.get_method(), HoldMethod)
def test_pay_single_hourly_employee_with_time_cards_spanning_two_pay_periods( self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() pay_date = date(2001, 11, 9) # Friday date_in_previous_pay_period = date(2001, 11, 2) transaction = TimecardTransaction(emp_id, pay_date, hours=2.0) transaction.execute() transaction = TimecardTransaction(emp_id, date_in_previous_pay_period, hours=5.0) transaction.execute() transaction = PaydayTransaction(pay_date) transaction.execute() self.validate_paycheck(transaction, emp_id, pay_date, 2.0 * 15.25)
def test_add_service_charge(self): emp_id = EmpId(2) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.25) transaction.execute() employee = g_payroll_database.get_employee(emp_id) union_affiliation = UnionAffiliation() employee.set_affiliation(union_affiliation) member_id = MemberId(86) # Maxwell Smart g_payroll_database.add_union_member(member_id, employee) transaction = ServiceChargeTransaction(member_id, date=20011101, charge=12.95) transaction.execute() service_charge = union_affiliation.get_service_charge(20011101) self.assertTrue(service_charge) self.assertEqual(12.95, service_charge.get_amount())
def test_service_charge_spanning_multiple_pay_periods(self): emp_id = EmpId(1) transaction = AddHourlyEmployee(emp_id, 'Bill', 'Home', hourly_rate=15.24) transaction.execute() member_id = MemberId(7734) transaction = ChangeMemberTransaction(emp_id, member_id, dues=9.42) transaction.execute() early_date = date(2001, 11, 2) # previous Friday pay_date = date(2001, 11, 9) late_date = date(2001, 11, 16) # next Friday transaction = ServiceChargeTransaction(member_id, pay_date, charge=19.42) transaction.execute() transaction = ServiceChargeTransaction(member_id, early_date, charge=100) transaction.execute() transaction = ServiceChargeTransaction(member_id, late_date, charge=200) transaction.execute() transaction = TimecardTransaction(emp_id, pay_date, hours=8.0) transaction.execute() transaction = PaydayTransaction(pay_date) transaction.execute() paycheck = transaction.get_paycheck(emp_id) self.assertEqual(pay_date, paycheck.get_period_end_date()) self.assertEqual(8 * 15.24, paycheck.get_gross_pay()) self.assertEqual('Hold', paycheck.get_field('Disposition')) self.assertEqual(9.42 + 19.42, paycheck.get_deductions()) self.assertEqual(8 * 15.24 - (9.42 + 19.42), paycheck.get_net_pay())