def check_employee(self, userinput): """ the userinput for search by employee is checked example: "Sab" special in this case: form the name input the employee is guessed: if the guess was not unique, a list of employees is prepared for the user to choose from if the name was unique: the searchparameters are set the qury function is returned """ employee, employee_queryset = _get_employee_from_name(userinput) if employee: header = ("Logentries for employee: {}".format(employee)) self.search_parameters = SearchParameters(employee_id=employee.id, header=header) return self.query_by_employee elif employee_queryset: self.choice = True self.choice_list = ChoiceList(list=list(employee_queryset), fmt_func=str, choice_func=self.choice_employee) return else: self.msg = "No employee has been found with name {}"\ .format(userinput) return
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 test_search_check_for_dialog_goal_case_not_reached(self): """ if there is no search result the user receives a message """ self.dialog.logentry_queryset = self.logentry_queryset_empty self.dialog.search_parameters = SearchParameters(header="some header") self.dialog.check_for_dialog_goal() self.assertIsNotNone(self.dialog.msg)
def test_search_query_by_time_range(self): self.dialog.search_parameters = SearchParameters(time_from=10, time_to=20) self.dialog.query_by_time_spent() hits = [ logentry for logentry in self.task_list if (10 <= logentry.time_spent <= 20) ] self.assertEqual(hits, list(self.dialog.logentry_queryset))
def test_search_query_by_time_exact(self): self.dialog.search_parameters = SearchParameters(time_from=15, time_to=None) self.dialog.query_by_time_spent() hits = [ logentry for logentry in self.task_list if (logentry.time_spent == 15) ] self.assertEqual(hits, list(self.dialog.logentry_queryset))
def test_search_query_by_term(self): searchterm = 'hard' self.dialog.search_parameters = SearchParameters(searchterm=searchterm) self.dialog.query_by_term() hits = [ logentry for logentry in self.task_list if (searchterm in logentry.task or searchterm in logentry.note) ] self.assertListEqual(list(self.dialog.logentry_queryset), hits)
def test_search_query_by_date_exact(self): self.dialog.search_parameters = SearchParameters( date_from=datetime.date(2016, 8, 30), date_to=None) self.dialog.query_by_date() hits = [ logentry for logentry in self.task_list if logentry.logdate == datetime.date(2016, 8, 30) ] self.assertSetEqual(set(hits), set(list(self.dialog.logentry_queryset)))
def choice_date(self): """ the choice of a date by means of a list is processed: the searchparameters are set and the query function is returned """ logentry = self.choice_list.list[self.active_choice_index] self.active_choice_item = None self.active_choice_index = None header = "Logentries for Logdate: {}" \ .format(logentry.logdate) self.search_parameters = SearchParameters(date_from=logentry.logdate, header=header) return self.query_by_date
def choice_employee(self): """ the choice of an employee by means of a list is processed: the searchparameters are set and the query function is returned """ employee = self.choice_list.list[self.active_choice_index] self.active_choice_item = None self.active_choice_index = None header = "Logentries for Employee: {}" \ .format(employee) self.search_parameters = SearchParameters(employee_id=employee.id, header=header) return self.query_by_employee
def check_term(self, userinput): """ the userinput for search by term is checked in case the check was okay: the searchparameters are set the qury function is returned """ if userinput == "": self.msg = "{} is not a valid search term!".format(userinput) return else: header = "Logentries for searchterm: {}" \ .format(userinput) self.search_parameters = SearchParameters(searchterm=userinput, header=header) return self.query_by_term
def test_search_check_for_dialog_goal_case_reached(self, mock_dialog_start, mock_main): """ if there is a searchresult the reult dialog should be called with it """ self.dialog.search_parameters = SearchParameters(header="some header") self.dialog.logentry_queryset = self.logentry_queryset mock_dialog_start.return_value = None self.dialog.check_for_dialog_goal() searchresult = ChoiceList(list=list(self.logentry_queryset), fmt_func=str, name="some header", fmt_detail_func=repr, choice_func=None) data = {'searchresult': searchresult} mock_dialog_start.assert_called_with(**data) mock_main.assert_called_with()