diff --git a/seahub/api2/views.py b/seahub/api2/views.py index d5b0a20b28..e704108e1b 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -25,8 +25,6 @@ from django.contrib.sites.models import RequestSite from django.db import IntegrityError from django.db.models import F from django.http import HttpResponse -from django.template import RequestContext -from django.template.loader import render_to_string from django.template.defaultfilters import filesizeformat from django.shortcuts import render_to_response from django.utils import timezone @@ -386,10 +384,10 @@ class Search(APIView): if search_path: search_path = normalize_dir_path(search_path) if not is_valid_repo_id_format(search_repo): - error_msg = 'search_path invalid.' + error_msg = 'search_repo invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - dir_id = seafile_api.get_dir_id_by_path(repo_id, search_path) + dir_id = seafile_api.get_dir_id_by_path(search_repo, search_path) if not dir_id: error_msg = 'Folder %s not found.' % search_path return api_error(status.HTTP_404_NOT_FOUND, error_msg) diff --git a/tests/api/test_search.py b/tests/api/test_search.py index b395b49514..0ae54a34b6 100644 --- a/tests/api/test_search.py +++ b/tests/api/test_search.py @@ -61,3 +61,17 @@ class SearchTest(BaseTestCase): self.login_as(self.user) resp = self.client.get(self.url) self.assertEqual(400, resp.status_code) + + @patch('seahub.api2.views.HAS_FILE_SEARCH', True) + @patch('seahub.api2.views.search_files') + @pytest.mark.skipif(TRAVIS, reason="") + def test_can_search_with_search_path(self, mock_search_files): + mock_search_files.return_value = self.mock_results, \ + self.mock_total + + self.login_as(self.user) + resp = self.client.get(self.url + '?q=lian&search_repo=%s&search_path=%s' % (self.repo_id, '/')) + json_resp = json.loads(resp.content) + print json_resp + assert json_resp['total'] == self.mock_total + assert json_resp['results'][0]['repo_id'] == self.mock_results[0]['repo_id']