def test_delete_employee(self): emp_id = EmpId(3) transaction = AddCommissionedEmployee(emp_id, 'Lance', 'Home', salary=2500, commission_rate=3.2) transaction.execute() employee = g_payroll_database.get_employee(emp_id) self.assertTrue(employee) transaction = DeleteEmployeeTransaction(emp_id) transaction.execute() employee = g_payroll_database.get_employee(emp_id) self.assertIsNone(employee)
def execute(self): employee = g_payroll_database.get_employee(self._emp_id) if employee: classification = employee.get_classification() if isinstance(classification, HourlyClassification): classification.add_timecard(Timecard(self._date, self._hours)) else: raise Exception( 'Tried to add timecard to non-hourly employee.') else: raise Exception('No such employee.')
def execute(self): emp_ids = g_payroll_database.get_all_employee_ids() for emp_id in emp_ids: employee = g_payroll_database.get_employee(emp_id) if employee.is_pay_date(self._pay_date): paycheck = Paycheck( employee.get_period_start_date(self._pay_date), self._pay_date, ) self._paychecks[emp_id] = paycheck employee.payday(paycheck)
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 execute(self): employee = g_payroll_database.get_employee(self._emp_id) if employee: classification = employee.get_classification() if isinstance(classification, CommissionedClassification): classification.add_sales_receipt( SalesReceipt(self._date, self._amount)) else: raise Exception( 'Tried to add sales receipt to non-commissioned employee.') else: raise Exception('No such employee.')
def test_change_hold_transaction(self): emp_id = EmpId(1) transaction = AddSalariedEmployee(emp_id, 'Bob', 'Home', salary=1000.00) transaction.execute() transaction = ChangeHoldTransaction(emp_id, address='test address') transaction.execute() method = g_payroll_database.get_employee(emp_id).get_method() self.assertIsInstance(method, HoldMethod) self.assertEqual('test address', method.get_address())
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_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_change_hourly_transaction(self): emp_id = EmpId(3) transaction = AddCommissionedEmployee(emp_id, 'Lance', 'Home', salary=2500, commission_rate=3.2) transaction.execute() transaction = ChangeHourlyTransaction(emp_id, hourly_rate=27.52) transaction.execute() employee = g_payroll_database.get_employee(emp_id) classification = employee.get_classification() self.assertIsInstance(classification, HourlyClassification) self.assertEqual(27.52, classification.get_hourly_rate()) self.assertIsInstance(employee.get_schedule(), WeeklySchedule)
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_change_direct_transaction(self): emp_id = EmpId(1) transaction = AddSalariedEmployee(emp_id, 'Bob', 'Home', salary=1000.00) transaction.execute() transaction = ChangeDirectTransaction(emp_id, bank='VTB', account=1234123412341234) transaction.execute() method = g_payroll_database.get_employee(emp_id).get_method() self.assertIsInstance(method, DirectMethod) self.assertEqual('VTB', method.get_bank()) self.assertEqual(1234123412341234, method.get_account())
def test_change_commissioned_transaction(self): emp_id = EmpId(1) transaction = AddSalariedEmployee(emp_id, 'Bob', 'Home', salary=1000.00) transaction.execute() transaction = ChangeCommissionedTransaction(emp_id, salary=2500, commission_rate=3.2) transaction.execute() employee = g_payroll_database.get_employee(emp_id) classification = employee.get_classification() self.assertIsInstance(classification, CommissionedClassification) self.assertEqual(2500, classification.get_salary()) self.assertEqual(3.2, classification.get_commission_rate()) self.assertIsInstance(employee.get_schedule(), BiweeklySchedule)
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_add_salaried_employee(self): emp_id = EmpId(1) transaction = AddSalariedEmployee(emp_id, 'Bob', 'Home', salary=1000.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(1000.00, classification.get_salary()) self.assertIsInstance(classification, SalariedClassification) self.assertIsInstance(employee.get_schedule(), MonthlySchedule) self.assertIsInstance(employee.get_method(), HoldMethod)
def test_sales_receipt_transaction(self): emp_id = EmpId(3) transaction = AddCommissionedEmployee(emp_id, 'Lance', 'Home', salary=2500, commission_rate=3.2) transaction.execute() transaction = SalesReceiptTransaction(emp_id, date=20011031, amount=3500) transaction.execute() employee = g_payroll_database.get_employee(emp_id) classification = employee.get_classification() sales_receipt = classification.get_sales_receipt(date=20011031) self.assertTrue(sales_receipt) self.assertEqual(3500, sales_receipt.get_amount())
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 execute(self): employee = g_payroll_database.get_employee(self._emp_id) if employee: self.change(employee)