Пример #1
0
 def test_course_finder_search_execute_function_returns_error_on_failure(self, mock_search):
     course_finder_search = CourseFinderSearch("Computing", None, None, None, None, None, 1, 20)
     error = course_finder_search.execute()
     self.assertIsNone(course_finder_search.total_courses)
     self.assertIsNone(course_finder_search.total_institutions)
     self.assertIsNone(course_finder_search.results)
     self.assertIsNotNone(error)
     self.assertEquals(type(error), ApiError)
Пример #2
0
 def test_course_finder_search_execute_function_appends_counts_and_list_of_courses_to_model_on_success(self):
     mock_data = SearchMocks.get_search_response_content()
     course_finder_search = CourseFinderSearch("Computing", None, None, None, None, None, 1, 20)
     error = course_finder_search.execute()
     self.assertIsNone(error)
     self.assertEquals(course_finder_search.total_courses, mock_data.get('total_number_of_courses'))
     self.assertEquals(course_finder_search.total_institutions, mock_data.get('total_results'))
     self.assertEquals(type(course_finder_search.results), list)
     self.assertEquals(len(course_finder_search.results), len(mock_data.get('items')))
Пример #3
0
def course_finder_results(request, language=enums.languages.ENGLISH):
    query_params = request.POST
    countries_query = ','.join(query_params.getlist('countries_query')) if 'countries_query' in query_params else None
    filter_form = FilterForm(query_params)
    filters = build_filters(query_params)
    course_finder_search = CourseFinderSearch(query_params.get('subject_query', None),
                                              query_params.get('institution_query', None),
                                              countries_query,
                                              query_params.get('postcode_query', None),
                                              filters,
                                              query_params.get('course_query', None),
                                              query_params.get('page', 1),
                                              query_params.get('count', 20),
                                              language)
    error = course_finder_search.execute()
 
    if error:
        redirect_page = get_new_landing_page_for_language(language)
        #redirect_page = get_page_for_language(language, SearchLandingPage.objects.all()).url

        return redirect(redirect_page + '?load_error=true&error_type=1')

    page = get_page_for_language(language, CourseFinderResults.objects.all())

    comparison_page = get_page_for_language(language, CourseComparisonPage.objects.all())
    bookmark_page = get_page_for_language(language, CourseManagePage.objects.all())

    welsh_url = '/cy' + request.path if language == enums.languages.ENGLISH else request.path
    english_url = request.path.replace('/cy/', '/')

    if not page:
        return render(request, '404.html')

    context = page.get_context(request)

    context.update({
        'page': page,
        'search': course_finder_search,
        'pagination_url': 'course_finder_results',
        'comparison_link': comparison_page.url if comparison_page else '#',
        'manage_link': bookmark_page.url if bookmark_page else '#',
        'english_url': english_url,
        'welsh_url': welsh_url,
        'cookies_accepted': request.COOKIES.get('discoverUniCookies'),
        'filter_form': filter_form
    })

    return render(request, 'coursefinder/course_finder_results.html', context)
Пример #4
0
def course_finder_results(request, language=enums.languages.ENGLISH):
    query_params = request.POST
    filter_form = FilterForm(query_params)
    filters = build_filters(query_params)
    if "distance" in filters and "campus" not in filters:
        countries_query = ''
    else:
        countries_query = ','.join(query_params.getlist(
            'countries_query')) if 'countries_query' in query_params else None

    institution_query = '@'.join(query_params.getlist(
        'institution_query')) if 'institution_query' in query_params else None
    institution_array = institution_query.split(
        "@") if institution_query else None

    postcode = query_params.get(
        'postcode') if 'postcode' in query_params else None
    distance_query = query_params.get(
        'distance') if 'distance' in query_params else None
    postcode_query = (postcode + ',' +
                      distance_query) if postcode and distance_query else {}

    sort_by_subject_enabled = query_params.get('sort_by_subject', 'false')
    sort_by_subject_limit = int(os.environ.get('SORT_BY_SUBJECT_LIMIT', 5000))
    count = sort_by_subject_limit if sort_by_subject_enabled == 'true' else 20

    course_finder_search = CourseFinderSearch(
        query_params.get('subject_query', None), institution_query,
        countries_query, postcode_query, filters, sort_by_subject_enabled,
        sort_by_subject_limit, query_params.get('course_query', None),
        query_params.get('page', 1), count, language)
    error = course_finder_search.execute()

    if error:
        redirect_page = get_new_landing_page_for_language(language)
        # redirect_page = get_page_for_language(language, SearchLandingPage.objects.all()).url

        return redirect(redirect_page + '?load_error=true&error_type=1')

    page = get_page_for_language(language, CourseFinderResults.objects.all())

    comparison_page = get_page_for_language(language,
                                            CourseComparisonPage.objects.all())
    bookmark_page = get_page_for_language(language,
                                          CourseManagePage.objects.all())

    if language == enums.languages.ENGLISH:
        translated_url = '/cy' + request.path if language == enums.languages.ENGLISH else request.path
    else:
        translated_url = request.path.replace('/cy/', '/')

    if not page:
        return render(request, '404.html')

    context = page.get_context(request)

    context.update({
        'page':
        page,
        'search':
        course_finder_search,
        'pagination_url':
        'course_finder_results',
        'comparison_link':
        comparison_page.url if comparison_page else '#',
        'manage_link':
        bookmark_page.url if bookmark_page else '#',
        'translated_url':
        translated_url,
        'cookies_accepted':
        request.COOKIES.get('discoverUniCookies'),
        'filter_form':
        filter_form,
        'filters':
        filters,
        'postcode_query':
        postcode_query,
        'sort_by_subject_enabled':
        sort_by_subject_enabled,
        'sort_by_subject_limit':
        sort_by_subject_limit,
        'institution_array':
        institution_array,
        'search_info': {
            'institutions':
            filter_form.institutions,
            'number_options_selected':
            translations.term_for_key('number_options_selected', language),
            'institution_name':
            translations.term_for_key('institution_name', language),
            'select_all_results':
            translations.term_for_key('select_all_results', language),
            'select_all_institutions':
            translations.term_for_key('select_all_institutions', language)
        }
    })

    return render(request, 'coursefinder/course_finder_results.html', context)