def test_update_time_sheet(self):
        time_sheet = TimeSheetProvider.create(
            date=datetime(2018, 1, 30),
            work_days_sheet=fixtures.load("january"),
            employee_id=0,
            employee_rate=RateCalculator.DAYS_FOR_3_YEARS,
            norm=22)
        time_sheet = TimeSheetProvider.update_with(time_sheet, norm=28)
        self.assertEqual(time_sheet.norm, 28)

        time_sheet = TimeSheetProvider.update_with(
            time_sheet, work_days_sheet=fixtures.load("february"))
        self.assertEqual(time_sheet.sheet, fixtures.load("february"))
 def test_close_time_sheet(self):
     time_sheet = TimeSheetProvider.create(
         date=datetime(2018, 1, 30),
         work_days_sheet=fixtures.load("january"),
         employee_id=0,
         employee_rate=RateCalculator.DAYS_FOR_3_YEARS,
         norm=22)
     time_sheet = TimeSheetProvider.close(time_sheet)
     try:
         TimeSheetProvider.update_with(time_sheet, 10)
         raise Exception("Closed time sheet has been updated")
     except AccessDeniedToUpdateTimeSheetError:
         self.assertEqual(time_sheet.closed, True)
    def test_update_time_sheet(self):
        ts_storage = TimeSheetsStorage(FakeDb().build())
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        ts_provider = TimeSheetProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        calculator = VacationCalculator()
        use_case = UpdateTimeSheetUseCase(ts_provider, e_use_case, calculator,
                                          ts_storage)

        use_case.update_time_sheet(0, sheet=fixtures.load('february'), norm=19)

        saved_time_sheet = ts_storage.find_by_id(0)
        self.assertEqual(saved_time_sheet.id, 0)
        self.assertEqual(saved_time_sheet.sheet, fixtures.load('february'))
        self.assertEqual(saved_time_sheet.norm, 19)
        self.assertNotEqual(saved_time_sheet.vacation, 1.0)

        use_case.update_time_sheet_for(0,
                                       2019,
                                       1,
                                       sheet=fixtures.load('full_january'))

        saved_time_sheet = ts_storage.find_first_by(employee_id=0,
                                                    year=2019,
                                                    month=1)
        self.assertEqual(saved_time_sheet.employee_id, 0)
        self.assertEqual(saved_time_sheet.sheet, fixtures.load('full_january'))
        self.assertEqual(saved_time_sheet.norm, 19)
        self.assertNotEqual(saved_time_sheet.vacation, 1.0)
    def test_get_time_sheet(self):
        ts_storage = TimeSheetsStorage(FakeDb().build())
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        ts_provider = TimeSheetProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        use_case = GetTimeSheetUseCase(ts_provider, e_use_case, ts_storage)

        time_sheet = use_case.get_for_employee(employee_id=0,
                                               year=2019,
                                               month=1)
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheet = use_case.get_by_id(time_sheet_id=0)
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)
 def test_create_time_sheet_without_norm(self):
     time_sheet = TimeSheetProvider.create(
         date=datetime(2018, 1, 30),
         work_days_sheet=fixtures.load("january"),
         employee_id=0,
         employee_rate=RateCalculator.DAYS_FOR_3_YEARS)
     self.assertIsNotNone(time_sheet)
     self.assertIsNone(time_sheet.norm)
예제 #6
0
    def build(self):
        session = super().build()
        admin_user = EmployeeProvider.deserialize(fixtures.load("admin_user"))
        unaccepted_user = EmployeeProvider.deserialize(
            fixtures.load("unaccepted_user"))
        user_with_vacation = EmployeeProvider.deserialize(
            fixtures.load("user_with_vacation"))
        session.add(admin_user)
        session.add(unaccepted_user)
        session.add(user_with_vacation)
        session.commit()

        january_ts = TimeSheetProvider.deserialize(
            fixtures.load('january_time_sheet'))
        half_january_ts = TimeSheetProvider.deserialize(
            fixtures.load('half_january_time_sheet'))
        session.add(january_ts)
        session.add(half_january_ts)
        session.commit()
        return session
    def test_close_time_sheet(self):
        storage = TimeSheetsStorage(FakeDb().build())
        controller = TimeSheetProvider()
        use_case = CloseTimeSheetUseCase(controller, storage)

        saved_time_sheet = storage.find_by_id(0)
        self.assertEqual(saved_time_sheet.closed, False)
        use_case.close_time_sheet(0)

        saved_time_sheet = storage.find_by_id(0)
        self.assertEqual(saved_time_sheet.id, 0)
        self.assertEqual(saved_time_sheet.closed, True)
    def test_create_time_sheet(self):
        storage = TimeSheetsStorage(FakeDb().build())
        controller = TimeSheetProvider()
        use_case = CreateTimeSheetUseCase(controller, storage)

        now = datetime(2019, 2, 1)
        use_case.create_time_sheet(now, fixtures.load('january'), 0, 10, 10)
        saved_time_sheet = storage.find_by_id(2)
        self.assertEqual(saved_time_sheet.year, 2019)
        self.assertEqual(saved_time_sheet.month, 2)
        self.assertEqual(saved_time_sheet.sheet, fixtures.load('january'))
        self.assertEqual(saved_time_sheet.employee_id, 0)
        self.assertEqual(saved_time_sheet.rate, 10)
        self.assertEqual(saved_time_sheet.norm, 10)
    def test_serialize_time_sheet(self):
        time_sheet = TimeSheetProvider.create(
            date=datetime(2018, 1, 30),
            work_days_sheet=fixtures.load("january"),
            employee_id=0,
            employee_rate=RateCalculator.DAYS_FOR_3_YEARS,
            norm=22)
        serialized_time_sheet = TimeSheetProvider.serialize(time_sheet)
        self.assertEqual(serialized_time_sheet['id'], None)
        self.assertEqual(serialized_time_sheet['year'], 2018)
        self.assertEqual(serialized_time_sheet['month'], 1)
        self.assertEqual(serialized_time_sheet['norm'], 22)
        self.assertEqual(serialized_time_sheet['rate'],
                         RateCalculator.DAYS_FOR_3_YEARS)
        self.assertEqual(serialized_time_sheet['vacation'], None)
        self.assertEqual(serialized_time_sheet['employee_id'], 0)
        self.assertEqual(serialized_time_sheet['closed'], False)
        self.assertEqual(serialized_time_sheet['sheet'],
                         fixtures.load("january"))

        time_sheet = TimeSheetProvider.close(time_sheet)
        serialized_time_sheet = TimeSheetProvider.serialize(time_sheet)
        self.assertEqual(serialized_time_sheet['closed'], True)
 def test_create_empty_time_sheet(self):
     time_sheet = TimeSheetProvider.create_empty(date=datetime(2018, 1, 30),
                                                 employee_id=0,
                                                 rate=8)
     self.assertIsNotNone(time_sheet)
     self.assertIsNone(time_sheet.id)
     self.assertEqual(time_sheet.rate, 8)
     self.assertEqual(time_sheet.vacation, 0)
     self.assertEqual(time_sheet.rate, 8)
     self.assertEqual(time_sheet.norm, 23)
     self.assertEqual(time_sheet.sheet.__len__(), 31)
     self.assertEqual(time_sheet.year, 2018)
     self.assertEqual(time_sheet.month, 1)
     self.assertEqual(time_sheet.employee_id, 0)
     self.assertEqual(time_sheet.closed, False)
    def test_update_one_day(self):
        ts_storage = TimeSheetsStorage(FakeDb().build())
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        ts_provider = TimeSheetProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        calculator = VacationCalculator()
        use_case = UpdateTimeSheetUseCase(ts_provider, e_use_case, calculator,
                                          ts_storage)

        use_case.update_day_mark(0, 1, 0.5)

        saved_time_sheet = ts_storage.find_by_id(0)
        self.assertEqual(saved_time_sheet.sheet[0], 0.5)
        self.assertNotEqual(saved_time_sheet.vacation, 1.0)
 def test_create_time_sheet(self):
     time_sheet = TimeSheetProvider.create(
         date=datetime(2018, 1, 30),
         work_days_sheet=fixtures.load("january"),
         employee_id=0,
         employee_rate=RateCalculator.DAYS_FOR_3_YEARS,
         norm=22)
     self.assertIsNotNone(time_sheet)
     self.assertEqual(time_sheet.id, None)
     self.assertEqual(time_sheet.norm, 22)
     self.assertEqual(time_sheet.rate, RateCalculator.DAYS_FOR_3_YEARS)
     self.assertEqual(time_sheet.sheet, fixtures.load("january"))
     self.assertEqual(time_sheet.year, 2018)
     self.assertEqual(time_sheet.month, 1)
     self.assertEqual(time_sheet.employee_id, 0)
     self.assertEqual(time_sheet.closed, False)
    def test_get_not_exist_time_sheet(self):
        ts_storage = TimeSheetsStorage(FakeDb().build())
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        ts_provider = TimeSheetProvider()
        use_case = GetTimeSheetUseCase(ts_provider, e_use_case, ts_storage)

        time_sheet = use_case.get_for_employee(employee_id=0,
                                               year=2019,
                                               month=12)
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 12)
        self.assertEqual(time_sheet['sheet'].__len__(), 31)
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 22)
예제 #14
0
    def test_calculate_norm(self):
        time_sheet = TimeSheet()

        initializer = TimeSheetInitHelper(datetime(2018, 1, 1))
        time_sheet.sheet = initializer.empty_sheet
        time_sheet.norm = initializer.norm
        self.assertEqual(time_sheet.norm, 23)
        self.assertEqual(time_sheet.sheet.__len__(), 31)

        initializer = TimeSheetInitHelper(datetime(2018, 2, 1))
        time_sheet.sheet = initializer.empty_sheet
        time_sheet.norm = initializer.norm
        self.assertEqual(time_sheet.norm, 20)
        self.assertEqual(time_sheet.sheet.__len__(), 28)

        time_sheet = TimeSheetProvider.update_with(time_sheet, norm=17)
        self.assertEqual(time_sheet.norm, 17)
    def test_save_employees(self):
        storage = TimeSheetsStorage(FakeDb().build())
        first_time_sheet = storage.find_by_id(0)
        date = datetime(2018, 2, 1)
        time_sheet = TimeSheetProvider.create(date,
                                              first_time_sheet.sheet,
                                              5,
                                              RateCalculator.MAX_DAYS,
                                              norm=10)
        time_sheet.id = 75
        storage.save(time_sheet)

        time_sheet = storage.find_by_id(75)
        self.assertIsNotNone(time_sheet)
        self.assertEqual(time_sheet.id, 75)
        self.assertEqual(time_sheet.year, 2018)
        self.assertEqual(time_sheet.month, 2)
        self.assertEqual(time_sheet.sheet, first_time_sheet.sheet)
        self.assertEqual(time_sheet.employee_id, 5)
        self.assertEqual(time_sheet.rate, RateCalculator.MAX_DAYS)
        self.assertEqual(time_sheet.norm, 10)
    def test_update_time_sheet_for_not_exist(self):
        ts_storage = TimeSheetsStorage(FakeDb().build())
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        ts_provider = TimeSheetProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        calculator = VacationCalculator()
        use_case = UpdateTimeSheetUseCase(ts_provider, e_use_case, calculator,
                                          ts_storage)
        try:
            ts_storage.find_first_by(employee_id=3, year=2019, month=5)
            raise Exception('Time sheet should not exist')
        except NotFoundError:
            pass
        use_case.update_time_sheet_for(employee_id=3,
                                       year=2019,
                                       month=5,
                                       sheet=fixtures.load('february'))

        saved_time_sheet = ts_storage.find_first_by(employee_id=3,
                                                    year=2019,
                                                    month=5)
        self.assertEqual(saved_time_sheet.sheet, fixtures.load('february'))
    def test_deserialize_time_sheet(self):
        time_sheet = TimeSheetProvider.create(
            date=datetime(2018, 1, 30),
            work_days_sheet=fixtures.load("february"),
            employee_id=0,
            employee_rate=RateCalculator.DAYS_FOR_3_YEARS,
            norm=22)
        serialized_time_sheet = TimeSheetProvider.serialize(time_sheet)
        time_sheet = TimeSheetProvider.deserialize(serialized_time_sheet)
        self.assertEqual(time_sheet.id, None)
        self.assertEqual(time_sheet.year, 2018)
        self.assertEqual(time_sheet.month, 1)
        self.assertEqual(time_sheet.norm, 22)
        self.assertEqual(time_sheet.rate, RateCalculator.DAYS_FOR_3_YEARS)
        self.assertEqual(time_sheet.vacation, None)
        self.assertEqual(time_sheet.employee_id, 0)
        self.assertEqual(time_sheet.closed, False)
        self.assertEqual(time_sheet.sheet, fixtures.load("february"))

        time_sheet = TimeSheetProvider.close(time_sheet)
        serialized_time_sheet = TimeSheetProvider.serialize(time_sheet)
        time_sheet = TimeSheetProvider.deserialize(serialized_time_sheet)
        self.assertEqual(time_sheet.closed, True)
예제 #18
0
    def create_app(self):
        if self.app is None:
            self.app = App()

        if self.db is None:
            self.db = DbBuilder().build()

        self.to_hash = ToHash()
        self.tokenizer = Tokenizer()

        self.vacation_calculator = VacationCalculator()
        self.employee_storage = EmployeesStorage(self.db)
        self.time_sheet_storage = TimeSheetsStorage(self.db)

        self.employee_provider = EmployeeProvider()
        self.time_sheet_provider = TimeSheetProvider()

        self.app.get_employee_use_case = GetEmployeeUseCase(self.employee_provider,
                                                            self.employee_storage)
        self.app.get_employees_use_case = GetAllEmployeeUseCase(self.employee_provider,
                                                                self.employee_storage)
        self.app.create_employee_use_case = CreateEmployeeUseCase(self.employee_provider,
                                                                  self.employee_storage,
                                                                  self.tokenizer,
                                                                  self.to_hash)
        self.app.check_employee_use_case = CheckEmployeeUseCase(self.employee_provider,
                                                                self.employee_storage,
                                                                self.tokenizer,
                                                                self.to_hash)
        self.app.check_admin_rights_use_case = CheckAdminRightsUseCase(self.employee_storage)
        self.app.register_employee_use_case = RegisterEmployeeUseCase(self.employee_provider,
                                                                      self.employee_storage)
        self.app.update_employee_use_case = UpdateEmployeeUseCase(self.to_hash,
                                                                  self.employee_provider,
                                                                  self.employee_storage)
        self.app.admin_rights_employee_use_case = AdminRightsEmployeeUseCase(self.employee_provider,
                                                                             self.employee_storage)

        self.app.get_time_sheet_use_case = GetTimeSheetUseCase(self.time_sheet_provider,
                                                               self.app.get_employee_use_case,
                                                               self.time_sheet_storage)
        self.app.get_time_sheets_use_case = GetTimeSheetsUseCase(self.time_sheet_provider,
                                                                 self.app.get_employee_use_case,
                                                                 self.time_sheet_storage)
        self.app.create_time_sheet_use_case = CreateTimeSheetUseCase(self.time_sheet_provider,
                                                                     self.time_sheet_storage)
        self.app.update_time_sheet_use_case = UpdateTimeSheetUseCase(self.time_sheet_provider,
                                                                     self.app.get_employee_use_case,
                                                                     self.vacation_calculator,
                                                                     self.time_sheet_storage)
        self.app.close_time_sheet_use_case = CloseTimeSheetUseCase(self.time_sheet_provider,
                                                                   self.time_sheet_storage)

        self.app.calculate_vacation_use_case = CalculateVacationUseCase(self.vacation_calculator,
                                                                        self.employee_storage,
                                                                        self.time_sheet_storage)

        self.registration_employee_controller = RegistrationEmployeeController(
            self.app.create_employee_use_case)
        self.authentication_employee_controller = AuthenticationEmployeeController(
            self.app.check_employee_use_case)
        self.get_employee_profile_controller = ProfileController(
            self.app.get_employee_use_case,
            self.app.check_employee_use_case,
            self.app.update_employee_use_case)
        self.accept_employee_controller = AcceptEmployeeController(
            self.app.check_admin_rights_use_case,
            self.app.register_employee_use_case)
        self.employee_controller = GetEmployeeController(self.app.get_employee_use_case)
        self.get_employees_controller = GetEmployeesController(self.app.get_employees_use_case)

        self.time_sheet_controller = TimeSheetController(
            self.app.get_time_sheet_use_case,
            self.app.update_time_sheet_use_case
        )
        self.day_of_time_sheet_controller = DayOfTimeSheetController(
            self.app.get_time_sheet_use_case,
            self.app.update_time_sheet_use_case
        )
        self.employee_time_sheets_controller = EmployeeTimeSheetsController(
            self.app.get_time_sheets_use_case, self.app.update_time_sheet_use_case)
        self.get_employees_time_sheets_controller = GetEmployeesTimeSheetsController(
            self.app.get_time_sheets_use_case)

        self.calculate_vacation_controller = VacationCalculatorController(
            self.app.calculate_vacation_use_case)

        self._init_routes()
        return self.app
    def test_get_time_sheets(self):
        storage = TimeSheetsStorage(FakeDb().build())
        controller = TimeSheetProvider()
        e_storage = EmployeesStorage(FakeDb().build())
        e_provider = EmployeeProvider()
        e_use_case = GetEmployeeUseCase(e_provider, e_storage)
        use_case = GetTimeSheetsUseCase(controller, e_use_case, storage)

        time_sheets = use_case.get_for_employee(employee_id=0,
                                                year=2019,
                                                month=1)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_employee(employee_id=0, year=2019)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_all_employees(year=2019)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_all_employees(year=2019, month=1)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_all_employees(month=1)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_employee(employee_id=0, month=1)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_for_employee(employee_id=0)
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)

        time_sheets = use_case.get_all()
        time_sheet = time_sheets[0]
        self.assertEqual(time_sheet['year'], 2019)
        self.assertEqual(time_sheet['month'], 1)
        self.assertEqual(time_sheet['sheet'], fixtures.load('january'))
        self.assertEqual(time_sheet['employee_id'], 0)
        self.assertEqual(time_sheet['rate'], 10)
        self.assertEqual(time_sheet['norm'], 23)