def setUp(self): self.created_at = datetime.datetime.now() self.updated_at = datetime.datetime.now() self.employee = EmployeeEntity(id=1, name="Brol", employee_id="00002", hourly_rate=50.00, employee_type=2, is_a_leader=False, created_at=self.created_at, updated_at=self.updated_at, total_work_hours=32) self.team = TeamEntity( id=1, name="Flatwoods monster", description="Tall humanoid with a spade-shaped head.", created_at=self.created_at, updated_at=self.updated_at) self.work_arrangement = WorkArrangementEntity(id=1, percent=80, employee=self.employee, team=self.team, remarks="Blah bla ...") self.work_time = WorkTimeEntity(id=1, hours=32, employee=self.employee, work_arrangement=self.work_arrangement)
def to_work_time_entity(wt_model: WorkTime): return WorkTimeEntity( id=wt_model.id, hours=wt_model.hours, employee=DataConverters.to_employee_entity(wt_model.employee), work_arrangement=DataConverters.to_work_arrangement_entity( wt_model.work_arrangement))
def create(self, validated_data): """ Create and return complete instance of team Entity based on validated data :param validated_data: :return: """ return WorkTimeEntity(**validated_data)
class TestWorkTime(unittest.TestCase): """Test cases for WorkTimeEntity""" def setUp(self): self.created_at = datetime.datetime.now() self.updated_at = datetime.datetime.now() self.employee = EmployeeEntity(id=1, name="Brol", employee_id="00002", hourly_rate=50.00, employee_type=2, is_a_leader=False, created_at=self.created_at, updated_at=self.updated_at, total_work_hours=32) self.team = TeamEntity( id=1, name="Flatwoods monster", description="Tall humanoid with a spade-shaped head.", created_at=self.created_at, updated_at=self.updated_at) self.work_arrangement = WorkArrangementEntity(id=1, percent=80, employee=self.employee, team=self.team, remarks="Blah bla ...") self.work_time = WorkTimeEntity(id=1, hours=32, employee=self.employee, work_arrangement=self.work_arrangement) def test_id(self): """Tests that id give correct values""" self.assertEqual(self.work_time.id, 1) def test_hours(self): """Tests that hours give correct values""" self.assertEqual(self.work_time.hours, 32) def test_validates_hours(self): """Tests that validator validates well""" # valid boundary inputs self.assertEqual(self.work_time.validates_hours(0), 0) self.assertEqual(self.work_time.validates_hours(1), 1) self.assertEqual(self.work_time.validates_hours(20), 20) self.assertEqual(self.work_time.validates_hours(39), 39) self.assertEqual(self.work_time.validates_hours(40), 40) # Invalid boundary inputs with self.assertRaises(domain_validators.EmployeeWorkTimeOutOfRange): self.work_time.validates_hours(-1) with self.assertRaises(domain_validators.EmployeeWorkTimeOutOfRange): self.work_time.validates_hours(41) with self.assertRaises(TypeError): self.work_time.validates_hours("abc") def test_hours_setter(self): """Tests that hours setter setts correct values """ self.work_time.hours = 40 self.assertEqual(self.work_time.hours, 40) def test_employee(self): """tests that employee give correct value""" self.assertIsInstance(self.work_time.employee, EmployeeEntity) self.assertEqual(self.work_time.employee, self.employee) def test_employee_setter(self): """Tests that employee setter sets correct values""" employee = EmployeeEntity(id=1, name="Scox", employee_id="00003", hourly_rate=50.00, employee_type=2, is_a_leader=False, created_at=self.created_at, updated_at=self.updated_at, total_work_hours=20) self.work_time.employee = employee self.assertIsInstance(self.work_time.employee, EmployeeEntity) self.assertEqual(self.work_time.employee, employee) def test_work_arrangement(self): """Tests that work_arrangement gives correct values""" self.assertIsInstance(self.work_time.work_arrangement, WorkArrangementEntity) self.assertEqual(self.work_time.work_arrangement, self.work_arrangement)
def setUp(self): self.created_at = datetime.datetime.now() self.updated_at = datetime.datetime.now() self.created_at = datetime.datetime.now() self.updated_at = datetime.datetime.now() self.employee_1 = EmployeeEntity( id=1, name="Brol", employee_id="00001", hourly_rate=50.00, employee_type=2, is_a_leader=True, created_at=self.created_at, updated_at=self.updated_at, ) self.employee_2 = EmployeeEntity(id=2, name="Scox", employee_id="00001", hourly_rate=50.00, employee_type=2, is_a_leader=False, created_at=self.created_at, updated_at=self.updated_at, total_work_hours=20) self.team_1 = TeamEntity( id=1, name="Flatwoods monster", description="Tall humanoid with a spade-shaped head.", leader=None, created_at=self.created_at, updated_at=self.updated_at) self.team_2 = TeamEntity( id=2, name="Greys", description= "Grey-skinned humanoids, usually 3–4 feet tall, hairless, with large heads.", leader=None, created_at=self.created_at + datetime.timedelta(seconds=10), updated_at=self.updated_at + datetime.timedelta(seconds=10)) self.work_arrangement = WorkArrangementEntity(id=1, percent=85, team=self.team_1, employee=self.employee_2) self.work_time = WorkTimeEntity(id=1, hours=34, employee=self.employee_2, work_arrangement=self.work_arrangement) teams = {1: self.team_1, 2: self.team_2} employees = {1: self.employee_1, 2: self.employee_2} work_arrangements = {1: self.work_arrangement} work_times = {1: self.work_time} team_employee = TeamEmployeeEntity(team=self.team_1, employee=self.employee_2, created_at=self.created_at, updated_at=self.updated_at) team_employees = {1: team_employee} team_leader = TeamLeaderEntity(team=self.team_1, leader=self.employee_1, created_at=self.created_at, updated_at=self.updated_at) team_leaders = {1: team_leader} self.db = MemoryDB(teams=teams, employees=employees, work_arrangements=work_arrangements, work_time=work_times, team_employees=team_employees, team_leaders=team_leaders) # copy object to avoid using the same db object in all test cases self.use_case_factory = UnittestsUseCasesFactory( db=copy.deepcopy(self.db)) self.use_case = self.use_case_factory.use_cases.work_arrangements_use_case( )
def save_work_time(self, wt_entity: WorkTimeEntity): new_id = len(self.db.work_arrangements) + 1 wt_entity.id = new_id self.db.work_times[new_id] = wt_entity return wt_entity