def test_get_student_results(self): backend = haystack.load_backend(HAYSTACK_SEARCH_ENGINE_TEST) with self._whoosh_settings(): with patch('haystack.backend', backend): periodbuilder = PeriodBuilder.quickadd_ducku_duck1010_active() group1 = periodbuilder.add_assignment('assignment1', long_name="Assignment One")\ .add_group().add_students(self.testuser).group group2 = periodbuilder.add_assignment('assignment2', long_name="Assignment Two")\ .add_group().add_students(self.testuser).group group_not_student = periodbuilder.add_assignment('assignment3', long_name="Assignment Three")\ .add_group().add_students(UserBuilder('nobody').user).group self._rebuild_searchindex() results = SearchHelper(self.testuser, 'Assignment').get_student_results() self.assertEquals(results.count(), 2) self.assertEquals(set(map(lambda r: r.object, results)), set([group1, group2]))
def test_get_examiner_results(self): with self._whoosh_settings(): with patch('haystack.backend', haystack.load_backend(HAYSTACK_SEARCH_ENGINE_TEST)): periodbuilder = PeriodBuilder.quickadd_ducku_duck1010_active() assignment1builder = periodbuilder.add_assignment('assignment1', long_name="Assignment One") assignment2builder = periodbuilder.add_assignment('assignment2', long_name="Assignment Two") group1 = assignment1builder.add_group().add_examiners(self.testuser).group group2 = assignment1builder.add_group().add_examiners(self.testuser).group group3 = assignment2builder.add_group().add_examiners(self.testuser).group assignment2builder.add_group().add_examiners(UserBuilder('nobody').user) # Should not math self._rebuild_searchindex() results = SearchHelper(self.testuser, 'Assignment').get_examiner_results() self.assertEquals(results.count(), 5) self.assertEquals(set(map(lambda r: r.object, results)), set([group1, group2, group3, assignment1builder.assignment, assignment2builder.assignment]))