def get(self, clientKeyUrlSafe): user = Authorization.isAuthenticated() if user: # pets = PetService.getPets(clientPhone) ClientService.delete(clientKeyUrlSafe) self.redirect('/clients') else: self.redirect('/')
def setUp(self): self._client_validator = ClientValidator() self._client_repository = Repository({}) self._client_service = ClientService(self._client_repository, self._client_validator) self._client_service.add_client('1', 'King Arthur') self._client_service.add_client('2', 'Im Somebody') self._client_service.add_client('3', 'Some random dude') try: self._client_service.add_client('4', '43') except ClientValidatorException: pass
def setUp(self): self._book_validator = BookValidator() self._book_repository = Repository({}) self._book_service = BookService(self._book_repository, self._book_validator) self._client_validator = ClientValidator() self._client_repository = Repository({}) self._client_service = ClientService(self._client_repository, self._client_validator) self._rental_validator = RentalValidator() self._rental_repository = Repository({}) self._rental_service = RentalService(self._rental_repository, self._rental_validator, self._book_repository,self._client_repository) self._book_service.add_book('1', 'The Book', 'King Arthur') self._book_service.add_book('2', 'The Prize', 'Im Somebody') self._book_service.add_book('3', 'Im Out Of Ideeas', 'Some random dude') self._client_service.add_client('1', 'Raiu Madalin') self._client_service.add_client('2', 'Ristei Elena') self._client_service.add_client('3', 'Another random dude') self._rental_service.add_rental('1', '2', '3', '10/10/2019') self._rental_service.add_rental('2', '1', '2', '02/03/2019') try: self._rental_service.add_rental('2', '1', '2', '02/03/2019') except RentalValidatorException as ve: pass except RepositoryException: pass self._rental_service.set_return_date('2', '02/03/2020') self._rental_service.add_rental('3', '1', '3', '02/03/2019') try: self._rental_service.add_rental('4', '3', '1223', '02/03/2019') except RentalValidatorException: pass try: self._rental_service.add_rental('134', '444', '1223', '02/03/2019') except RentalValidatorException: pass try: self._rental_service.add_rental('134', '3', '2', '02/03/2019') self._rental_service.add_rental('134', '3', '2', '02/03/2019') except RentalValidatorException: pass except RepositoryException: pass try: self._rental_service.add_rental('134', '3', '2', '0d/s3/2019') except RentalValidatorException: pass
def post(self, clientKeyUrlSafe): user = Authorization.isAuthenticated() if user: try: ClientService.update(clientKeyUrlSafe, self.request) # client = ClientService.getClient(clientKeyUrlSafe) # # pets = PetService.getPetsFromClient(client) # clientService = ClientService(self.request) # clientService.update(client, pets) except: logging.error("ClientEdit.py => post(self, clientKeyUrlSafe) => an exception was thrown trying to retrieve and update Client") finally: self.redirect('/clients') else: self.redirect('/')
def setUp(self): """ Prepare tests """ self.rental_repository = Repository({}) self.validator2 = RentalValidator() self.book_repository = Repository({}) self.validator = BookValidator() self.client_repository = Repository({}) self.validatorc = ClientValidator() self.undo_service = UndoService() self.redo_service = RedoService() self.book_service = BookService(self.book_repository, self.validator) self.client_service = ClientService(self.client_repository, self.validatorc) self.rental_service = RentalService(self.rental_repository, self.validator2, self.book_repository, self.client_repository)
def addAllInRange(clientKeyUrlSafe, request): clientKey = ClientService.getClientKey(clientKeyUrlSafe) serviceKeyUrlSafe = request.get("serviceKeyUrlSafe") service = ServiceService.get(serviceKeyUrlSafe) dateFromString = request.get("dateFrom") dateToString = request.get("dateTo") repeatMonday = request.get("repeatMonday") repeatTuesday = request.get("repeatTuesday") repeatWednesday = request.get("repeatWednesday") repeatThursday = request.get("repeatThursday") repeatFriday = request.get("repeatFriday") repeatSaturday = request.get("repeatSaturday") repeatSunday = request.get("repeatSunday") startDate = datetime.strptime(dateFromString, "%m/%d/%Y").date() endDate = datetime.strptime(dateToString, "%m/%d/%Y").date() dateRange = endDate - startDate for i in range(dateRange.days + 1): currentDay = startDate + timedelta(days=i) if repeatSunday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.SUNDAY: LineItemService.add(clientKey, service, currentDay) if repeatMonday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.MONDAY: LineItemService.add(clientKey, service, currentDay) if repeatTuesday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.TUESDAY: LineItemService.add(clientKey, service, currentDay) if repeatWednesday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.WEDNESDAY: LineItemService.add(clientKey, service, currentDay) if repeatThursday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.THURSDAY: LineItemService.add(clientKey, service, currentDay) if repeatFriday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.FRIDAY: LineItemService.add(clientKey, service, currentDay) if repeatSaturday == LineItemService.FLAGACTIVE and currentDay.isoweekday() == LineItemService.SATURDAY: LineItemService.add(clientKey, service, currentDay)
def addAllInList(clientKeyUrlSafe, request): dateList = request.get("multiDatesPickerSelectedDates") clientKey = ClientService.getClientKey(clientKeyUrlSafe) dateList = dateList.split(",") serviceKeyUrlSafe = request.get("serviceKeyUrlSafe") service = ServiceService.get(serviceKeyUrlSafe) for dateString in dateList: dateString = dateString.strip() currentDate = datetime.strptime(dateString, "%m/%d/%Y").date() LineItemService.add(clientKey, service, currentDate)
def get(self): user = Authorization.isAuthenticated() if user: clients = ClientService.getAll() template_values = { 'clients' : clients, } template = JINJA_ENVIRONMENT.get_template('partials/lineItem.html') self.response.write(template.render(template_values)) else: self.redirect('/')
def getAllInRange(clientKeyUrlSafe, viewDateFrom, viewDateTo): try: viewDateFrom = datetime.strptime(viewDateFrom, "%m/%d/%Y").date() viewDateTo = datetime.strptime(viewDateTo, "%m/%d/%Y").date() clientKey = ClientService.getClientKey(clientKeyUrlSafe) lineItems = LineItem.query(ancestor=clientKey) lineItems = lineItems.filter(LineItem.dateOfService <= viewDateTo, LineItem.dateOfService >= viewDateFrom) lineItems = lineItems.order(LineItem.dateOfService).fetch() return lineItems except: logging.error("LineItemService.py => getAllInRang") return None
def get(self, clientKeyUrlSafe): user = Authorization.isAuthenticated() if user: client = ClientService.get(clientKeyUrlSafe) template_values = { 'client':client, 'buttonName' : 'Update', 'postURL' : '/clientDetail/'+clientKeyUrlSafe, } template = JINJA_ENVIRONMENT.get_template('partials/clientEditable.html') self.response.write(template.render(template_values)) else: self.redirect('/')
class TestClientService(unittest.TestCase): def setUp(self): self._client_validator = ClientValidator() self._client_repository = Repository({}) self._client_service = ClientService(self._client_repository, self._client_validator) self._client_service.add_client('1', 'King Arthur') self._client_service.add_client('2', 'Im Somebody') self._client_service.add_client('3', 'Some random dude') try: self._client_service.add_client('4', '43') except ClientValidatorException: pass def test_client_add(self): a = self._client_repository.get_entities() self.assertEqual(len(a), 3) self.assertEqual(a['1'].name, 'King Arthur') self.assertEqual(a['2'].name, 'Im Somebody') self.assertEqual(a['3'].name, 'Some random dude') def test_client_remove(self): self._client_service.remove_client('1') a = self._client_repository.get_entities() assert len(a) == 2 self.assertEqual(self._client_repository.find_by_id('1'), None) def test_search_by_id(self): a = self._client_service.search_client_by_id('1') self.assertEqual(a[0].id, '1') self.assertEqual(a[0].name, 'King Arthur') def test_search_by_name(self): a = self._client_service.search_client_by_name('King') self.assertEqual(a[0].id, '1') self.assertEqual(a[0].name, 'King Arthur') self.assertEqual(len(a), 1)
def get(self, lineItemKeyUrlSafe, clientKeyUrlSafe): user = Authorization.isAuthenticated() if user: client = ClientService.get(clientKeyUrlSafe) lineItem = LineItemService.get(lineItemKeyUrlSafe) services = ServiceService.getAll() template_values = { "client": client, "lineItem": lineItem, "services": services, "postURL": "/lineItemUpdate/" + lineItemKeyUrlSafe + "/client/" + clientKeyUrlSafe, } template = JINJA_ENVIRONMENT.get_template("partials/lineItemUpdate.html") self.response.write(template.render(template_values)) else: self.redirect("/")
def get(self, clientKeyUrlSafe): user = Authorization.isAuthenticated() if user: monthStart = DateService.getFirstDateOfMonth().strftime('%m/%d/%Y') monthEnd = DateService.getLastDateOfMonth().strftime('%m/%d/%Y') try: radLineItemType = LineItemsClient.radLineItemType except: radLineItemType = 'irregular' try: dateFrom = LineItemsClient.dateFrom dateTo = LineItemsClient.dateTo except: dateFrom = monthStart dateTo = monthEnd try: viewDateFrom = LineItemsClient.viewDateFrom viewDateTo = LineItemsClient.viewDateTo except: viewDateFrom = monthStart viewDateTo = monthEnd try: serviceKeyUrlSafe = LineItemsClient.serviceKeyUrlSafe except: serviceKeyUrlSafe = '' services = ServiceService.getAll() client = ClientService.get(clientKeyUrlSafe) # lineItems = LineItemService.getAll(clientKeyUrlSafe) lineItems = LineItemService.getAllInRange(clientKeyUrlSafe, viewDateFrom, viewDateTo) template_values = { 'services':services, 'client' : client, 'postUrl' : '/lineItem/client/' + clientKeyUrlSafe, 'lineItems' : lineItems, 'getUrl' : '/lineItem/client/' + clientKeyUrlSafe, 'viewDateFrom' : viewDateFrom, 'viewDateTo' : viewDateTo, 'dateFrom' : dateFrom, 'dateTo' : dateTo, 'serviceKeyUrlSafe' : serviceKeyUrlSafe, 'radLineItemType' : radLineItemType } template = JINJA_ENVIRONMENT.get_template('partials/lineItemClient.html') self.response.write(template.render(template_values)) else: self.redirect('/')
def update(request): employeeKeyUrlSafe = request.get("employeeKeyUrlSafe") accounts = AccountManagerService.getAll() # first delete all accounts associated with this employee for account in accounts: if account.employeeKeyUrlSafe == employeeKeyUrlSafe: accountKey = account.key accountKey.delete() # then add all accounts to be associated with this employee clients = ClientService.getAll() for client in clients: for i in range(len(clients)): currentClientKeyUrlSafe = request.get("client" + str(i)) if currentClientKeyUrlSafe == client.key.urlsafe(): account = AccountManager() account.clientKeyUrlSafe = client.key.urlsafe() account.employeeKeyUrlSafe = employeeKeyUrlSafe account.put() time.sleep(sleepTime)
def get(self, employeeKeyUrlSafe): user = Authorization.isAuthenticated() if user: try: dateFrom = CalendarDetail.dateFrom except: dateFrom = DateService.getFirstDateOfMonth().strftime('%m/%d/%Y') try: dateTo = CalendarDetail.dateTo except: dateTo = DateService.getLastDateOfMonth().strftime('%m/%d/%Y') employee = EmployeeService.get(employeeKeyUrlSafe) clients = ClientService.getAll() lineItems = LineItemService.getAllInRangeForEmployee(employeeKeyUrlSafe, clients, dateFrom, dateTo) if lineItems == None: lineItems = [] lineItemDates = [] for lineItem in lineItems: if lineItem.dateOfService not in lineItemDates: lineItemDates.append(lineItem.dateOfService) calendarLineItemViewModels = [] for lineItemDate in lineItemDates: lineItemServices = [] for lineItem in lineItems: if lineItem.dateOfService == lineItemDate: lineItemServices.append(lineItem.service) calendarLineItemViewModel = CalendarLineItem(lineItemDate, lineItemServices) calendarLineItemViewModels.append(calendarLineItemViewModel) template_values = { 'dateFrom' : dateFrom, 'dateTo' : dateTo, 'employee' : employee, 'calendarLineItemViewModels' : calendarLineItemViewModels } template = JINJA_ENVIRONMENT.get_template('partials/calendarDetail.html') self.response.write(template.render(template_values)) else: self.redirect('/')
if __name__ == '__main__': settings = Settings("../settings.properties") config = settings.get_the_settings() try: if config[0] == "inmemory": book_validator = BookValidator() client_validator = ClientValidator() rental_validator = RentalValidator() book_repository = Repository({}) client_repository = Repository({}) rental_repository = Repository({}) book_service = BookService(book_repository, book_validator) client_service = ClientService(client_repository, client_validator) rental_service = RentalService(rental_repository, rental_validator, book_repository, client_repository) console = Console(book_service, client_service, rental_service) console.run_console() elif config[0] == "filerepository": book_validator = BookValidator() client_validator = ClientValidator() rental_validator = RentalValidator() book_repository = BooksFileRepository(config[1]) client_repository = ClientsFileRepository(config[2]) rental_repository = RentalsFileRepository(config[3]) book_service = BookService(book_repository, book_validator) client_service = ClientService(client_repository, client_validator)
class TestRentalService(unittest.TestCase): def setUp(self): self._book_validator = BookValidator() self._book_repository = Repository({}) self._book_service = BookService(self._book_repository, self._book_validator) self._client_validator = ClientValidator() self._client_repository = Repository({}) self._client_service = ClientService(self._client_repository, self._client_validator) self._rental_validator = RentalValidator() self._rental_repository = Repository({}) self._rental_service = RentalService(self._rental_repository, self._rental_validator, self._book_repository,self._client_repository) self._book_service.add_book('1', 'The Book', 'King Arthur') self._book_service.add_book('2', 'The Prize', 'Im Somebody') self._book_service.add_book('3', 'Im Out Of Ideeas', 'Some random dude') self._client_service.add_client('1', 'Raiu Madalin') self._client_service.add_client('2', 'Ristei Elena') self._client_service.add_client('3', 'Another random dude') self._rental_service.add_rental('1', '2', '3', '10/10/2019') self._rental_service.add_rental('2', '1', '2', '02/03/2019') try: self._rental_service.add_rental('2', '1', '2', '02/03/2019') except RentalValidatorException as ve: pass except RepositoryException: pass self._rental_service.set_return_date('2', '02/03/2020') self._rental_service.add_rental('3', '1', '3', '02/03/2019') try: self._rental_service.add_rental('4', '3', '1223', '02/03/2019') except RentalValidatorException: pass try: self._rental_service.add_rental('134', '444', '1223', '02/03/2019') except RentalValidatorException: pass try: self._rental_service.add_rental('134', '3', '2', '02/03/2019') self._rental_service.add_rental('134', '3', '2', '02/03/2019') except RentalValidatorException: pass except RepositoryException: pass try: self._rental_service.add_rental('134', '3', '2', '0d/s3/2019') except RentalValidatorException: pass def test_rental_add(self): a = self._rental_repository.get_entities() self.assertEqual(len(a), 4) self.assertEqual(a['1'].book_id, '2') self.assertEqual(a['1'].client_id, '3') self.assertEqual(a['1'].rented_date, '10/10/2019') self.assertEqual(a['1'].data, 'This book is not returned yet') def test_rental_return(self): a = self._rental_repository.get_entities() self.assertEqual(a['1'].data, 'This book is not returned yet') self._rental_service.set_return_date('1', '20/10/2020') self.assertEqual(a['1'].data, '20/10/2020') self.assertEqual(a['3'].data, 'This book is not returned yet') try: self._rental_service.set_return_date('1', '20/10/2020') except RentalValidatorException: pass try: self._rental_service.set_return_date('3', '01/03/2019') except RentalValidatorException: pass try: self._rental_service.set_return_date('3', '02/02/2019') except RentalValidatorException: pass try: self._rental_service.set_return_date('3', '02/03/2018') except RentalValidatorException: pass def test_most_rented_books(self): self._rental_service.set_return_date('1', '20/10/2020') a, b = self._rental_service.most_rented_books() self.assertEqual(a[0], 'The Book') self.assertEqual(b[0], 2) def test_most_rented_authors(self): a, b = self._rental_service.most_rented_authors() self.assertEqual(a[0], 'King Arthur') self.assertEqual(b[0], 2) self.assertEqual(a[1], 'Im Somebody') self.assertEqual(b[1], 1) def test_most_active_clients(self): self._rental_service.set_return_date('1', '20/10/2020') a, b = self._rental_service.most_active_clients() self.assertEqual(a[0], 'Another random dude') self.assertEqual(b[0], 376) def test_rental_print(self): a = self._rental_service.print_rentals() self.assertNotEqual(len(a), 0)
def getAll(clientKeyUrlSafe): clientKey = ClientService.getClientKey(clientKeyUrlSafe) lineItems = LineItem.query(ancestor=clientKey).order(LineItem.dateOfService).fetch() return lineItems
class TestUndoService(unittest.TestCase): def setUp(self): """ Prepare tests """ self.rental_repository = Repository({}) self.validator2 = RentalValidator() self.book_repository = Repository({}) self.validator = BookValidator() self.client_repository = Repository({}) self.validatorc = ClientValidator() self.undo_service = UndoService() self.redo_service = RedoService() self.book_service = BookService(self.book_repository, self.validator) self.client_service = ClientService(self.client_repository, self.validatorc) self.rental_service = RentalService(self.rental_repository, self.validator2, self.book_repository, self.client_repository) def test_undo_controller(self): """ Tests for undo controller """ self.assertRaises(UndoException, self.undo_service.do_undo) self.assertRaises(RedoException, self.redo_service.do_redo) self.book_service.add_book('12', "the name", 'By me') self.undo_service.store_operation(self.book_service, UndoHandler.UNDO_ADD_BOOK, '12') self.undo_service.do_undo() self.assertTrue(len(self.book_service.get_entities()) == 0) self.redo_service.store_operation(self.book_service, RedoHandler.REDO_ADD_BOOK, '12', "the name", "By me") self.redo_service.do_redo() self.assertTrue(len(self.book_service.get_entities()) == 1) self.book_service.add_book('2', "the name", 'By me') self.book_service.remove_book('2') self.undo_service.store_operation(self.book_service, UndoHandler.UNDO_REMOVE_BOOK, '2', "The Mandalorian", "Didu") self.undo_service.do_undo() self.undo_service.store_operation(self.book_service, UndoHandler.UNDO_UPDATE_BOOK, '2', "The Mandalorian","Didu") self.undo_service.do_undo() self.redo_service.store_operation(self.book_service, RedoHandler.REDO_UPDATE_BOOK, '2', "The Mandalorian","Didu") self.redo_service.do_redo() self.client_service.add_client("10", "andrei") self.undo_service.store_operation(self.client_service, UndoHandler.UNDO_ADD_CLIENT, '10') self.undo_service.do_undo() self.assertTrue(len(self.client_service.get_entities()) == 0) self.redo_service.store_operation(self.client_service, RedoHandler.REDO_ADD_CLIENT, "10", "andrei") self.redo_service.do_redo() self.assertTrue(len(self.client_service.get_entities()) == 1) self.client_service.remove_client('10') self.undo_service.store_operation(self.client_service, UndoHandler.UNDO_REMOVE_CLIENT, '10', 'andrei') self.undo_service.do_undo() self.redo_service.store_operation(self.client_service, RedoHandler.REDO_REMOVE_CLIENT, '10') self.redo_service.do_redo() self.client_service.add_client('2', "Didu") self.undo_service.store_operation(self.client_service, UndoHandler.UNDO_UPDATE_CLIENT, '2', "Didu") self.undo_service.do_undo() self.redo_service.store_operation(self.client_service, RedoHandler.REDO_UPDATE_CLIENT, '2', 'Didu') self.redo_service.do_redo() self.rental_service.add_rental('1', '2', '2', '20/10/2020') self.undo_service.store_operation(self.rental_service, UndoHandler.UNDO_ADD_RENTAL, '1') self.undo_service.do_undo() self.redo_service.store_operation(self.rental_service, RedoHandler.REDO_ADD_RENTAL, '1', '2', '2', '20/10/2020','') self.redo_service.do_redo() self.book_service.add_book('20', "book", 'By me') self.book_service.remove_book('20') self.undo_service.store_operation(self.book_service, UndoHandler.UNDO_REMOVE_BOOK, '20', "book", "By me") self.undo_service.do_undo() self.redo_service.store_operation(self.book_service, RedoHandler.REDO_REMOVE_BOOK, '20') self.redo_service.do_redo() self.redo_service.clear()