From ebcd7ed44d835dbb5a58a93c8b709ee91be6c7ce Mon Sep 17 00:00:00 2001 From: zhengxie Date: Tue, 23 Feb 2016 10:45:43 +0800 Subject: [PATCH] [virus] Fix url error when records number more than 9 --- seahub/urls.py | 2 +- .../sysadmin/test_sys_virus_scan_records.py | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/seahub/views/sysadmin/test_sys_virus_scan_records.py diff --git a/seahub/urls.py b/seahub/urls.py index 3d3fa680b9..99ab43fd62 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -270,7 +270,7 @@ if EVENTS_ENABLED: urlpatterns += patterns( '', url(r'^sys/virus_scan_records/$', sys_virus_scan_records, name='sys_virus_scan_records'), - url(r'^sys/virus_scan_records/delete/(?P[\d+])/$', sys_delete_virus_scan_records, name='sys_delete_virus_scan_records'), + url(r'^sys/virus_scan_records/delete/(?P\d+)/$', sys_delete_virus_scan_records, name='sys_delete_virus_scan_records'), ) if settings.SERVE_STATIC: diff --git a/tests/seahub/views/sysadmin/test_sys_virus_scan_records.py b/tests/seahub/views/sysadmin/test_sys_virus_scan_records.py new file mode 100644 index 0000000000..fd12401dff --- /dev/null +++ b/tests/seahub/views/sysadmin/test_sys_virus_scan_records.py @@ -0,0 +1,48 @@ +from mock import patch + +from django.core.urlresolvers import reverse + +from seahub.test_utils import BaseTestCase + + +class VirusScanRecord(object): + def __init__(self, repo_id): + self.repo_id = repo_id + + +class SysVirusScanRecordsTest(BaseTestCase): + + # @patch('seahub.utils.EVENTS_ENABLED', True) + # @patch('seahub.utils.get_virus_record') + # def test_can_list_empty(self, mock_get_virus_record): + # mock_get_virus_record.return_value = [] + + # self.login_as(self.admin) + + # resp = self.client.get(reverse('sys_virus_scan_records')) + # self.assertEqual(200, resp.status_code) + # self.assertTemplateUsed(resp, 'sysadmin/sys_virus_scan_records.html') + + def _get_virus_record(self, start, limit): + records = [] + for i in range(11): + record = VirusScanRecord(self.repo.id) + record.vid = i + 1 + record.has_handle = False + records.append(record) + + return records + + @patch('seahub.utils.EVENTS_ENABLED') + @patch('seahub.utils.get_virus_record') + def test_can_list_records_num_more_than_10(self, mock_get_virus_record, + mock_events_enabled): + mock_events_enabled = True + mock_get_virus_record.side_effect = self._get_virus_record + + self.login_as(self.admin) + + resp = self.client.get(reverse('sys_virus_scan_records')) + self.assertEqual(200, resp.status_code) + self.assertTemplateUsed(resp, 'sysadmin/sys_virus_scan_records.html') + assert len(resp.context['records']) >= 10