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_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_update_employee(self): to_hash = FakeToHash() storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = UpdateEmployeeUseCase(to_hash, controller, storage) use_case.update_employee(0, name="new name", old_password="******", new_password="******", email="*****@*****.**") saved_employee = storage.find_by_id(0) self.assertIsNotNone(saved_employee.password) self.assertEqual(saved_employee.name, "new name") self.assertEqual(saved_employee.email, "*****@*****.**") self.assertEqual(saved_employee.activated, True) try: use_case.update_employee(employee_id=0, old_password="******", new_password="******") raise Exception('Updating must be break') except UpdatingError: pass try: use_case.update_employee(employee_id=0, email="*****@*****.**") raise Exception('Updating must be break') except EmailIsBusyError: pass
def test_get_employee(self): storage = EmployeesStorage(FakeDb().build()) employee = storage.find_by_id(0) self.assertIsNotNone(employee) self.assertEqual(employee.id, 0) self.assertIsNotNone(employee.name) self.assertIsNotNone(employee.email) self.assertIsNotNone(employee.password)
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)
def setUp(self): db = FakeDb().build() self.time_sheet_storage = TimeSheetsStorage(db) self.employee_storage = EmployeesStorage(db) self.calculator = VacationCalculator() reporter = ExcelReporter() self.use_case = ReporterUseCase(self.employee_storage, self.time_sheet_storage, self.calculator, reporter)
def test_get_all_employee(self): storage = EmployeesStorage(FakeDb().build()) employees = storage.get_all() self.assertIsNotNone(employees) employee = employees[0] self.assertEqual(employee.id, 0) self.assertIsNotNone(employee.name) self.assertIsNotNone(employee.email) self.assertIsNotNone(employee.password)
def test_save_employees(self): storage = EmployeesStorage(FakeDb().build()) employee = EmployeeProvider.create_simple("some name", "some password", "*****@*****.**") storage.save(employee) saved_employee = storage.find_by_email("*****@*****.**") self.assertIsNotNone(saved_employee) self.assertEqual(saved_employee.id, employee.id) self.assertEqual(saved_employee.name, employee.name) self.assertEqual(saved_employee.email, employee.email) self.assertEqual(saved_employee.password, employee.password)
def test_update_employee(self): storage = TimeSheetsStorage(FakeDb().build()) time_sheet = storage.find_by_id(0) time_sheet.norm = 23 time_sheet.rate = RateCalculator.DAYS_FOR_2_YEARS storage.update(time_sheet) self.assertIsNotNone(time_sheet) self.assertEqual(time_sheet.id, 0) self.assertEqual(time_sheet.norm, 23) self.assertEqual(time_sheet.rate, RateCalculator.DAYS_FOR_2_YEARS)
def test_get_first_by_filter_time_sheet(self): storage = TimeSheetsStorage(FakeDb().build()) time_sheet = storage.find_first_by(id=0) self.assertIsNotNone(time_sheet) self.assertEqual(time_sheet.id, 0) self.assertEqual(time_sheet.employee_id, 0) self.assertIsNotNone(time_sheet.year) self.assertIsNotNone(time_sheet.month) self.assertIsNotNone(time_sheet.sheet) self.assertIsNotNone(time_sheet.rate) self.assertIsNotNone(time_sheet.norm) self.assertIsNotNone(time_sheet.closed)
def test_update_employee(self): storage = EmployeesStorage(FakeDb().build()) employee = storage.find_by_id(0) employee.name = "Updated Name" employee.password = "******" storage.update(employee) self.assertIsNotNone(employee) self.assertEqual(employee.id, 0) self.assertEqual(employee.name, "Updated Name") self.assertEqual(employee.email, "*****@*****.**") self.assertEqual(employee.password, "Updated Password")
def test_get_all_employee(self): storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = GetAllEmployeeUseCase(controller, storage) employees = use_case.get_employees() self.assertEqual(employees.__len__(), 3) saved_employee = employees[0] self.assertEqual(saved_employee['name'], "admin") self.assertEqual(saved_employee['email'], "*****@*****.**") self.assertEqual(saved_employee['activated'], True) self.assertEqual(saved_employee['vacation'], 1.0)
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_get_all_employee(self): storage = TimeSheetsStorage(FakeDb().build()) employees = storage.get_all() self.assertIsNotNone(employees) time_sheet = employees[0] self.assertEqual(time_sheet.id, 0) self.assertEqual(time_sheet.employee_id, 0) self.assertIsNotNone(time_sheet.year) self.assertIsNotNone(time_sheet.month) self.assertIsNotNone(time_sheet.sheet) self.assertIsNotNone(time_sheet.rate) self.assertIsNotNone(time_sheet.norm) self.assertIsNotNone(time_sheet.closed)
def test_register_employee(self): storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = RegisterEmployeeUseCase(controller, storage) now = datetime.now() serialized_employee = fixtures.load("unaccepted_user") use_case.register_employee(serialized_employee["id"], employment_date=now) saved_employee = storage.find_by_email(serialized_employee["email"]) self.assertEqual(saved_employee.employment_date, now) self.assertEqual(saved_employee.vacation, 0) self.assertEqual(saved_employee.activated, True)
def test_get_employee(self): storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = GetEmployeeUseCase(controller, storage) saved_employee = use_case.get_employee(employee_id=0) self.assertEqual(saved_employee['name'], "admin") self.assertEqual(saved_employee['email'], "*****@*****.**") self.assertEqual(saved_employee['activated'], True) saved_employee = use_case.get_employee_by_email("*****@*****.**") self.assertEqual(saved_employee['name'], "admin") self.assertEqual(saved_employee['email'], "*****@*****.**") self.assertEqual(saved_employee['activated'], True)
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_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_admin_rights_employee(self): storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = AdminRightsEmployeeUseCase(controller, storage) saved_employee = storage.find_by_id(1) self.assertEqual(saved_employee.is_admin, False) use_case.grant_to_admin(1) saved_employee = storage.find_by_id(1) self.assertEqual(saved_employee.is_admin, True) use_case.pick_up_admin(1) saved_employee = storage.find_by_id(1) self.assertEqual(saved_employee.is_admin, False)
def test_create_employee(self): storage = EmployeesStorage(FakeDb().build()) controller = EmployeeProvider() use_case = CreateEmployeeUseCase(controller, storage, Tokenizer(), ToHash()) use_case.create_employee("some name", password="******", email="*****@*****.**") saved_employee = storage.find_by_email("*****@*****.**") self.assertEqual(saved_employee.name, "some name") self.assertEqual(saved_employee.email, "*****@*****.**") self.assertIsNotNone(saved_employee.password) use_case.create_employee("new user", "some password", "*****@*****.**") saved_employee = storage.find_by_email("*****@*****.**") self.assertEqual(saved_employee.name, "new user") self.assertEqual(saved_employee.email, "*****@*****.**") self.assertIsNotNone(saved_employee.password) self.assertEqual(saved_employee.activated, False)
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_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)