mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-01 23:38:37 +00:00
[fixed] error when use search_path feature
This commit is contained in:
parent
bed0ed8bc5
commit
3998466c25
@ -25,8 +25,6 @@ from django.contrib.sites.models import RequestSite
|
|||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.http import HttpResponse
|
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.template.defaultfilters import filesizeformat
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -386,10 +384,10 @@ class Search(APIView):
|
|||||||
if search_path:
|
if search_path:
|
||||||
search_path = normalize_dir_path(search_path)
|
search_path = normalize_dir_path(search_path)
|
||||||
if not is_valid_repo_id_format(search_repo):
|
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)
|
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:
|
if not dir_id:
|
||||||
error_msg = 'Folder %s not found.' % search_path
|
error_msg = 'Folder %s not found.' % search_path
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||||
|
@ -61,3 +61,17 @@ class SearchTest(BaseTestCase):
|
|||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
resp = self.client.get(self.url)
|
resp = self.client.get(self.url)
|
||||||
self.assertEqual(400, resp.status_code)
|
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']
|
||||||
|
Loading…
Reference in New Issue
Block a user