def setUp(self): """ the database is filled with testdata. a logentry queryset is prepared as possible search result """ self.create_test_data() self.dialog = SearchDialog() self.logentry_queryset = LogEntry.select() self.logentry_queryset_empty = LogEntry.select().where( LogEntry.employee_id == 100)
def check_date(self, userinput): """ the userinput for search by date is checked example: "29.8.2016" or "29.8.2016 - 30.8.2016" if a date or date range is given, the searchparameters are set the qury function is returned. The user can also choose "l" as list, then a list of all dates for which logentries exist is prepared for the user to choose from """ if userinput == 'l': logentries = \ LogEntry.select(LogEntry.logdate).group_by(LogEntry.logdate) self.choice_list = ChoiceList(list=list(logentries), fmt_func=_logentry_to_date, choice_func=self.choice_date) if logentries: self.choice = True return else: self.msg = "No logentries are in the database yet." else: try: search_parameters = \ get_date_searchparameters_from_userinput(userinput) except ValueError as e: self.msg = e return else: self.search_parameters = search_parameters return self.query_by_date
def setUp(self): """ the database is filled with testdata. The logentry """ self.create_test_data() self.dialog = SearchDialog() self.logentry_queryset = LogEntry.select()
def test_search_query_by_employee(self): employee = Employee.select().get() tasks = LogEntry.select().where(LogEntry.employee_id == employee.id) self.dialog.search_parameters = SearchParameters( employee_id=employee.id) self.dialog.query_by_employee() self.assertEqual(tasks, self.dialog.logentry_queryset)
def setUp(self): """ sets up seacrh results for the 3 cases: one employee was found with a name, more than one employee found, no employee found. this set up relies on the knowledge of the testdata that is created """ self.create_test_data() self.dialog = SearchDialog() self.logentry_queryset = LogEntry.select() self.employee1, self.employee_queryset1 = _get_employee_from_name( 'Love') self.employee2, self.employee_queryset2 = _get_employee_from_name( 'Sabine') self.employee3, self.employee_queryset3 = _get_employee_from_name( 'Nobody') self.logentries_dates = list( LogEntry.select(LogEntry.logdate).group_by(LogEntry.logdate))
def query_by_employee(self): """ query for search by employee and set up the searchresult list """ self.logentry_queryset = \ LogEntry.select().join(Employee).where( (Employee.id == self.search_parameters.employee_id) )
def test_create_save_logentry(self): """ logentry is saved """ self.dialog.save_logentry() self.assertTrue(self.dialog.quit_dialog) self.assertIsNotNone(self.dialog.return_msg) self.assertTrue(LogEntry.select(LogEntry.task == "some exotic task").exists())
def query_by_term(self): """ query for search by term and set up the searchresult list """ searchstring = self.search_parameters.searchterm self.logentry_queryset = \ LogEntry.select()\ .where(LogEntry.task.contains(searchstring) | LogEntry.note.contains(searchstring))
def test_result_discard_delete(self): """ when the delete is rejected everything stays as is """ self.dialog.discard_delete() self.assertIsNone(self.dialog.activestep) self.assertIsNotNone(self.dialog.msg) self.assertTrue( LogEntry.select().where(LogEntry.id == self.logentry.id).exists())
def setUp(self): """ the date list is set up """ self.create_test_data() self.dialog = SearchDialog() self.dialog.active_choice_index = 0 date_list = list( LogEntry.select(LogEntry.logdate).group_by(LogEntry.logdate)) self.dialog.choice_list = ChoiceList(list=date_list)
def test_helpers__logentry_to_date(self): """ get formated date out of logentry in format of '%d.%m.%Y' """ with test_database(test_db, (Employee, LogEntry)): self.create_test_data() logentry = LogEntry.select().get() datestring = _logentry_to_date(logentry) date_from_datestring = datetime.datetime.strptime( datestring, date_fmt).date() self.assertEqual(logentry.logdate, date_from_datestring)
def test_result_delete(self): """ when the delete is rejected everything stays as is """ self.dialog.delete() self.assertTrue(self.dialog.choice) self.assertNotIn(self.logentry, self.dialog.choice_list.list) self.assertIsNotNone(self.dialog.msg) self.assertFalse( LogEntry.select().where(LogEntry.id == self.logentry.id).exists()) self.assertIsNone(self.dialog.activestep)
def query_by_date(self): """ query for search by date and set up the searchresult list """ date_from = self.search_parameters.date_from if self.search_parameters.date_to: date_to = self.search_parameters.date_to else: date_to = date_from self.logentry_queryset = \ LogEntry.select()\ .where((LogEntry.logdate <= date_to) & (LogEntry.logdate >= date_from))
def query_by_time_spent(self): """ query for search by time spent and set up the searchresult list """ time_from = self.search_parameters.time_from if self.search_parameters.time_to: time_to = self.search_parameters.time_to else: time_to = time_from self.logentry_queryset = \ LogEntry.select()\ .where((LogEntry.time_spent <= time_to) & (LogEntry.time_spent >= time_from))
def setUp(self): """ a logentry has been chosen from the list, so the dialog is in detail view the list of the dialog consists of logentries """ self.create_test_data() self.logentry_queryset = LogEntry.select() self.logentry_list = list(self.logentry_queryset) searchresult = ChoiceList(list=self.logentry_list, name="logentries") data = {"searchresult": searchresult} self.dialog = ResultDialog(**data) self.logentry = self.logentry_queryset.get() self.dialog.active_choice_item = self.logentry self.dialog.active_choice_index = self.dialog.choice_list.list.index( self.logentry) self.dialog.prepare_delete()
def setUp(self): """ Szenario: temporary logentry has been build. the user can now decide what to do with it. """ self.create_test_data() self.logentry = LogEntry.select().get() data = {'logentry': self.logentry} self.dialog = UpdateDialog(**data) self.employee = Employee.select().get() self.dialog.logentry_tmp = { 'task': "some exotic task", 'time_spent': 20, 'note': "some note", 'employee': self.employee, } self.print_stack = ['some item'] self.print_logentries = _print_logentry_tmp(self.dialog.logentry_tmp, self.logentry)
def test_helpers__print_logentry_tmp_for_update(self): """ print in case of update: fields are taken from tmps and if they are not filled, from the database record """ with test_database(test_db, (Employee, LogEntry)): self.create_test_data() employee = Employee.select().get() logentry = LogEntry.select().get() logentry_tmp = { 'employee': employee, 'time_spent': 45, } printstring = _print_logentry_tmp(logentry_tmp=logentry_tmp, logentry=logentry) self.assertEqual( printstring, (("{0:<20s} {1}\n{2:<20s} {3}\n" "{4:<20s} {5} min\n{6}\n{7}").format( 'Employee:', employee, 'Task:', logentry.task, 'Time spent:', 45, 'Note:', logentry.note)))