def test_calculate_daily_wage(self): """ Test that the daily wage is correctly calculated Tests: -regular with perfect in out -regular day with slightly over in out -day with over time -sunday with no overtime -sunday with overtime """ #Regular day with perfect in out a = Attendance(employee=self.employee, start_time=datetime(2014, 7, 1, 8, 0), end_time=datetime(2014, 7, 1, 17, 0)) wage = self.employee._calculate_daily_wages(a) self.assertEqual(wage, 550) #Regular day with slightly imperfect in out a = Attendance(employee=self.employee, start_time=datetime(2014, 7, 1, 8, 0), end_time=datetime(2014, 7, 1, 17, 14)) wage = self.employee._calculate_daily_wages(a) self.assertEqual(wage, 550) #Day with over time a = Attendance(employee=self.employee, start_time=datetime(2014, 7, 1, 8, 0), end_time=datetime(2014, 7, 1, 20, 0)) self.assertEqual(a.total_time, 11) self.assertEqual(a.overtime, 3) self.assertEqual(a.regular_time, 8) wage = self.employee._calculate_daily_wages(a) self.assertEqual(wage, 859.375) #Sunday with no overtime a = Attendance(employee=self.employee, start_time=datetime(2014, 7, 6, 8, 0), end_time=datetime(2014, 7, 6, 17, 0)) self.assertEqual(a.total_time, 8) self.assertEqual(a.overtime, 0) self.assertEqual(a.regular_time, 8) wage = self.employee._calculate_daily_wages(a) self.assertEqual(wage, 1100) #Sunday with over time a = Attendance(employee=self.employee, start_time=datetime(2014, 7, 6, 8, 0), end_time=datetime(2014, 7, 6, 20, 0)) self.assertEqual(a.total_time, 11) self.assertEqual(a.overtime, 3) self.assertEqual(a.regular_time, 8) wage = self.employee._calculate_daily_wages(a) self.assertEqual(wage, 1718.75)
def test_end_time_property(self): """Test that the getter and setter for start time work properly """ a = Attendance(employee=self.employee, date=date(2016, 3, 21)) d1 = datetime(2016, 3, 21, 15, 29, 0) # Test start time without timezone a.end_time = d1 self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1)) # Test start time with timezone a.end_time = self.tz.localize(d1) self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1))
def setUp(self): """ Set up the Testing class: -self.employee = salary worker -self.employee = daily worker -self.employee3 = daily worker with no legal status """ super(Employee3Test, self).setUp() self.employee = Employee(**employee3_data) self.employee.save() for day in xrange(1, 15): hour = 20 if day % 2 > 0 else 17 a = Attendance(employee=self.employee, start_time=datetime(2014, 7, day, 8, 0), end_time=datetime(2014, 7, day, hour, 0)) a.save()
def setUp(self): """ Set up the Testing class: -self.employee = salary worker -self.employee = daily worker -self.employee3 = daily worker with no legal status """ super(Employee3Test, self).setUp() self.employee = Employee(**employee3_data) self.employee.save() for day in xrange(1, 15): hour = 20 if day % 2 > 0 else 17 a = Attendance( employee=self.employee, start_time=datetime(2014, 7, day, 8, 0), end_time=datetime(2014, 7, day, hour, 0), ) a.save()
def setUp(self): """ Set up the Testing clas: """ super(AttendanceTest, self).setUp() #self.client.client.login(username='******', password='******') self.shift = Shift(start_time=time(8, 0), end_time=time(17, 0)) self.shift.save() self.employee = Employee(shift=self.shift, **employee2_data) self.employee.save() # Regular attendance self.attendance = Attendance( date=date(2014, 7, 1), start_time=timezone('Asia/Bangkok').localize( datetime(2014, 7, 1, 7, 30, 0)), end_time=timezone('Asia/Bangkok').localize( datetime(2014, 7, 1, 23, 33, 0)), employee=self.employee, shift=self.shift) self.attendance.save() # Sunday attendance self.sunday_attendance = Attendance( date=date(2016, 2, 7), start_time=timezone('Asia/Bangkok').localize( datetime(2016, 2, 7, 8, 02, 0)), end_time=timezone('Asia/Bangkok').localize( datetime(2016, 2, 7, 23, 15, 0)), employee=self.employee, shift=self.shift) self.sunday_attendance.save() self.tz = timezone('Asia/Bangkok')
def setUp(self): """ Set up the Testing clas: """ super(AttendanceTest, self).setUp() # self.client.client.login(username='******', password='******') self.shift = Shift(start_time=time(8, 0), end_time=time(17, 0)) self.shift.save() self.employee = Employee(shift=self.shift, **employee2_data) self.employee.save() # Regular attendance self.attendance = Attendance( date=date(2014, 7, 1), start_time=timezone("Asia/Bangkok").localize(datetime(2014, 7, 1, 7, 30, 0)), end_time=timezone("Asia/Bangkok").localize(datetime(2014, 7, 1, 23, 33, 0)), employee=self.employee, shift=self.shift, ) self.attendance.save() # Sunday attendance self.sunday_attendance = Attendance( date=date(2016, 2, 7), start_time=timezone("Asia/Bangkok").localize(datetime(2016, 2, 7, 8, 02, 0)), end_time=timezone("Asia/Bangkok").localize(datetime(2016, 2, 7, 23, 15, 0)), employee=self.employee, shift=self.shift, ) self.sunday_attendance.save() self.tz = timezone("Asia/Bangkok")
class AttendanceTest(APITestCase): """ Testing class for attendance """ def setUp(self): """ Set up the Testing clas: """ super(AttendanceTest, self).setUp() #self.client.client.login(username='******', password='******') self.shift = Shift(start_time=time(8, 0), end_time=time(17, 0)) self.shift.save() self.employee = Employee(shift=self.shift, **employee2_data) self.employee.save() # Regular attendance self.attendance = Attendance( date=date(2014, 7, 1), start_time=timezone('Asia/Bangkok').localize( datetime(2014, 7, 1, 7, 30, 0)), end_time=timezone('Asia/Bangkok').localize( datetime(2014, 7, 1, 23, 33, 0)), employee=self.employee, shift=self.shift) self.attendance.save() # Sunday attendance self.sunday_attendance = Attendance( date=date(2016, 2, 7), start_time=timezone('Asia/Bangkok').localize( datetime(2016, 2, 7, 8, 02, 0)), end_time=timezone('Asia/Bangkok').localize( datetime(2016, 2, 7, 23, 15, 0)), employee=self.employee, shift=self.shift) self.sunday_attendance.save() self.tz = timezone('Asia/Bangkok') def test_start_time_property(self): """Test that the getter and setter for start time work properly """ a = Attendance(employee=self.employee, date=date(2016, 3, 21)) d1 = datetime(2016, 3, 21, 8, 11, 0) # Test start time without timezone a.start_time = d1 self.assertEqual(a._start_time, self.tz.localize(d1)) self.assertEqual(a.start_time, self.tz.localize(d1)) # Test start time with timezone a.start_time = self.tz.localize(d1) self.assertEqual(a._start_time, self.tz.localize(d1)) self.assertEqual(a.start_time, self.tz.localize(d1)) def test_end_time_property(self): """Test that the getter and setter for start time work properly """ a = Attendance(employee=self.employee, date=date(2016, 3, 21)) d1 = datetime(2016, 3, 21, 15, 29, 0) # Test start time without timezone a.end_time = d1 self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1)) # Test start time with timezone a.end_time = self.tz.localize(d1) self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1)) def test_regular_attedance_regular_hours(self): """Test the regular hours of a regular attedance """ self.attendance.calculate_times() self.assertEqual(self.attendance.regular_time, Decimal('8.0')) self.assertEqual(self.attendance.overtime, Decimal('0')) def test_regular_attedance_with_overtime_enabled(self): """Test the regular hours of a regular attedance """ self.attendance.enable_overtime = True self.attendance.calculate_times() self.assertEqual(self.attendance.regular_time, Decimal('8.0')) self.assertEqual(self.attendance.overtime, Decimal('6.5')) def test_regular_attendance_gross_wage(self): """Test the gross wage of a regular attendance """ self.attendance.calculate_times() self.attendance.calculate_gross_wage() self.assertEqual(self.attendance.regular_pay, Decimal('550')) self.assertEqual(self.attendance.overtime_pay, Decimal('0')) self.assertEqual(self.attendance.lunch_pay, Decimal('0')) self.assertEqual(self.attendance.gross_wage, Decimal('550')) def test_regular_attendance_gross_wage_with_overtime_enabled(self): """Test the gross wage of a regular attendance with overtime enabled """ self.attendance.enable_overtime = True self.attendance.calculate_times() self.attendance.calculate_gross_wage() self.assertEqual(self.attendance.regular_pay, Decimal('550')) # Calculate expected overtime pay ot_rate = (Decimal('550') / Decimal('8')) * Decimal('1.5') self.assertEqual(self.attendance.overtime_pay, ot_rate * Decimal('6.5')) self.assertEqual(self.attendance.lunch_pay, Decimal('0')) # Test gross wage self.assertEqual(self.attendance.gross_wage, Decimal('550') + (ot_rate * Decimal('6.5'))) def test_regular_attendance_net_wage(self): """Test the gross wage of a regular attendance """ self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.gross_wage, Decimal('550')) self.assertEqual(self.attendance.reimbursement, Decimal('30')) self.assertEqual(self.attendance.net_wage, Decimal('580')) def test_regular_attendance_net_wage_with_lunch(self): """Test the gross wage of a regular attendance """ self.attendance.receive_lunch_overtime = True self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.gross_wage, Decimal('653.125')) self.assertEqual(self.attendance.reimbursement, Decimal('60')) self.assertEqual(self.attendance.net_wage, Decimal('713.125')) def test_regular_attendance_net_wage_where_clockin_late(self): """Test the net wage where an employee is late """ logger.debug( "\n\n\n\nTesting late clocking for regular attendance\n\n\n") # Change start time so employee is late self.attendance.start_time = self.tz.localize( datetime(2014, 7, 1, 8, 15, 0)) self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.regular_time, Decimal('7.5')) self.assertEqual(self.attendance.reimbursement, Decimal('0')) self.assertEqual(self.attendance.net_wage, Decimal('515.625')) def test_sunday_attendance_regular_hours(self): """Test the regular hours of a regular attedance """ logger.debug("\n\n\n\nTesting Sunday Regular attendance hours\n\n\n") self.sunday_attendance.calculate_times() self.assertEqual(self.sunday_attendance.regular_time, Decimal('8.0')) self.assertEqual(self.sunday_attendance.overtime, Decimal('0')) def test_sunday_attendance_with_overtime_enabled(self): """Test the regular hours of a regular attedance """ self.sunday_attendance.enable_overtime = True self.sunday_attendance.calculate_times() self.assertEqual(self.sunday_attendance.regular_time, Decimal('8.0')) self.assertEqual(self.sunday_attendance.overtime, Decimal('6')) def test_sunday_attendance_gross_wage(self): """Test the gross wage of a sunday attendance """ self.sunday_attendance.calculate_times() self.sunday_attendance.calculate_gross_wage() self.assertEqual(self.sunday_attendance.regular_pay, Decimal('1100')) self.assertEqual(self.sunday_attendance.overtime_pay, Decimal('0')) self.assertEqual(self.sunday_attendance.lunch_pay, Decimal('0')) self.assertEqual(self.sunday_attendance.gross_wage, Decimal('1100')) def test_sunday_attendance_gross_wage_with_overtime_enabled(self): """Test the gross wage of a sunday attendance """ self.sunday_attendance.enable_overtime = True self.sunday_attendance.calculate_times() self.sunday_attendance.calculate_gross_wage() self.assertEqual(self.sunday_attendance.regular_pay, Decimal('1100')) # Calculate expected overtime pay ot_rate = (Decimal('550') / Decimal('8')) * Decimal('3') self.assertEqual(self.sunday_attendance.overtime_pay, ot_rate * Decimal('6')) self.assertEqual(self.sunday_attendance.lunch_pay, Decimal('0')) # Test gross wage self.assertEqual(self.sunday_attendance.gross_wage, Decimal('1100') + (ot_rate * Decimal('6')))
class AttendanceTest(APITestCase): """ Testing class for attendance """ def setUp(self): """ Set up the Testing clas: """ super(AttendanceTest, self).setUp() # self.client.client.login(username='******', password='******') self.shift = Shift(start_time=time(8, 0), end_time=time(17, 0)) self.shift.save() self.employee = Employee(shift=self.shift, **employee2_data) self.employee.save() # Regular attendance self.attendance = Attendance( date=date(2014, 7, 1), start_time=timezone("Asia/Bangkok").localize(datetime(2014, 7, 1, 7, 30, 0)), end_time=timezone("Asia/Bangkok").localize(datetime(2014, 7, 1, 23, 33, 0)), employee=self.employee, shift=self.shift, ) self.attendance.save() # Sunday attendance self.sunday_attendance = Attendance( date=date(2016, 2, 7), start_time=timezone("Asia/Bangkok").localize(datetime(2016, 2, 7, 8, 02, 0)), end_time=timezone("Asia/Bangkok").localize(datetime(2016, 2, 7, 23, 15, 0)), employee=self.employee, shift=self.shift, ) self.sunday_attendance.save() self.tz = timezone("Asia/Bangkok") def test_start_time_property(self): """Test that the getter and setter for start time work properly """ a = Attendance(employee=self.employee, date=date(2016, 3, 21)) d1 = datetime(2016, 3, 21, 8, 11, 0) # Test start time without timezone a.start_time = d1 self.assertEqual(a._start_time, self.tz.localize(d1)) self.assertEqual(a.start_time, self.tz.localize(d1)) # Test start time with timezone a.start_time = self.tz.localize(d1) self.assertEqual(a._start_time, self.tz.localize(d1)) self.assertEqual(a.start_time, self.tz.localize(d1)) def test_end_time_property(self): """Test that the getter and setter for start time work properly """ a = Attendance(employee=self.employee, date=date(2016, 3, 21)) d1 = datetime(2016, 3, 21, 15, 29, 0) # Test start time without timezone a.end_time = d1 self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1)) # Test start time with timezone a.end_time = self.tz.localize(d1) self.assertEqual(a._end_time, self.tz.localize(d1)) self.assertEqual(a.end_time, self.tz.localize(d1)) def test_regular_attedance_regular_hours(self): """Test the regular hours of a regular attedance """ self.attendance.calculate_times() self.assertEqual(self.attendance.regular_time, Decimal("8.0")) self.assertEqual(self.attendance.overtime, Decimal("0")) def test_regular_attedance_with_overtime_enabled(self): """Test the regular hours of a regular attedance """ self.attendance.enable_overtime = True self.attendance.calculate_times() self.assertEqual(self.attendance.regular_time, Decimal("8.0")) self.assertEqual(self.attendance.overtime, Decimal("6.5")) def test_regular_attendance_gross_wage(self): """Test the gross wage of a regular attendance """ self.attendance.calculate_times() self.attendance.calculate_gross_wage() self.assertEqual(self.attendance.regular_pay, Decimal("550")) self.assertEqual(self.attendance.overtime_pay, Decimal("0")) self.assertEqual(self.attendance.lunch_pay, Decimal("0")) self.assertEqual(self.attendance.gross_wage, Decimal("550")) def test_regular_attendance_gross_wage_with_overtime_enabled(self): """Test the gross wage of a regular attendance with overtime enabled """ self.attendance.enable_overtime = True self.attendance.calculate_times() self.attendance.calculate_gross_wage() self.assertEqual(self.attendance.regular_pay, Decimal("550")) # Calculate expected overtime pay ot_rate = (Decimal("550") / Decimal("8")) * Decimal("1.5") self.assertEqual(self.attendance.overtime_pay, ot_rate * Decimal("6.5")) self.assertEqual(self.attendance.lunch_pay, Decimal("0")) # Test gross wage self.assertEqual(self.attendance.gross_wage, Decimal("550") + (ot_rate * Decimal("6.5"))) def test_regular_attendance_net_wage(self): """Test the gross wage of a regular attendance """ self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.gross_wage, Decimal("550")) self.assertEqual(self.attendance.reimbursement, Decimal("30")) self.assertEqual(self.attendance.net_wage, Decimal("580")) def test_regular_attendance_net_wage_with_lunch(self): """Test the gross wage of a regular attendance """ self.attendance.receive_lunch_overtime = True self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.gross_wage, Decimal("653.125")) self.assertEqual(self.attendance.reimbursement, Decimal("60")) self.assertEqual(self.attendance.net_wage, Decimal("713.125")) def test_regular_attendance_net_wage_where_clockin_late(self): """Test the net wage where an employee is late """ logger.debug("\n\n\n\nTesting late clocking for regular attendance\n\n\n") # Change start time so employee is late self.attendance.start_time = self.tz.localize(datetime(2014, 7, 1, 8, 15, 0)) self.attendance.calculate_times() self.attendance.calculate_net_wage() self.assertEqual(self.attendance.regular_time, Decimal("7.5")) self.assertEqual(self.attendance.reimbursement, Decimal("0")) self.assertEqual(self.attendance.net_wage, Decimal("515.625")) def test_sunday_attendance_regular_hours(self): """Test the regular hours of a regular attedance """ logger.debug("\n\n\n\nTesting Sunday Regular attendance hours\n\n\n") self.sunday_attendance.calculate_times() self.assertEqual(self.sunday_attendance.regular_time, Decimal("8.0")) self.assertEqual(self.sunday_attendance.overtime, Decimal("0")) def test_sunday_attendance_with_overtime_enabled(self): """Test the regular hours of a regular attedance """ self.sunday_attendance.enable_overtime = True self.sunday_attendance.calculate_times() self.assertEqual(self.sunday_attendance.regular_time, Decimal("8.0")) self.assertEqual(self.sunday_attendance.overtime, Decimal("6")) def test_sunday_attendance_gross_wage(self): """Test the gross wage of a sunday attendance """ self.sunday_attendance.calculate_times() self.sunday_attendance.calculate_gross_wage() self.assertEqual(self.sunday_attendance.regular_pay, Decimal("1100")) self.assertEqual(self.sunday_attendance.overtime_pay, Decimal("0")) self.assertEqual(self.sunday_attendance.lunch_pay, Decimal("0")) self.assertEqual(self.sunday_attendance.gross_wage, Decimal("1100")) def test_sunday_attendance_gross_wage_with_overtime_enabled(self): """Test the gross wage of a sunday attendance """ self.sunday_attendance.enable_overtime = True self.sunday_attendance.calculate_times() self.sunday_attendance.calculate_gross_wage() self.assertEqual(self.sunday_attendance.regular_pay, Decimal("1100")) # Calculate expected overtime pay ot_rate = (Decimal("550") / Decimal("8")) * Decimal("3") self.assertEqual(self.sunday_attendance.overtime_pay, ot_rate * Decimal("6")) self.assertEqual(self.sunday_attendance.lunch_pay, Decimal("0")) # Test gross wage self.assertEqual(self.sunday_attendance.gross_wage, Decimal("1100") + (ot_rate * Decimal("6")))