diff --git a/seahub/api2/endpoints/admin/statistics.py b/seahub/api2/endpoints/admin/statistics.py index 34f2030fbd..448cf88084 100644 --- a/seahub/api2/endpoints/admin/statistics.py +++ b/seahub/api2/endpoints/admin/statistics.py @@ -17,7 +17,7 @@ from seaserv import ccnet_api from seahub.utils import get_file_ops_stats_by_day, \ get_total_storage_stats_by_day, get_user_activity_stats_by_day, \ is_pro_version, EVENTS_ENABLED, get_system_traffic_by_day, \ - seafevents_api + get_all_users_traffic_by_month, get_all_orgs_traffic_by_month from seahub.utils.timeutils import datetime_to_isoformat_timestr from seahub.utils.ms_excel import write_xls from seahub.utils.file_size import byte_to_mb @@ -253,7 +253,7 @@ class SystemUserTrafficView(APIView): # get one more item than per_page, to judge has_next_page try: - traffics = seafevents_api.get_all_users_traffic_by_month(month_obj, + traffics = get_all_users_traffic_by_month(month_obj, start, start + per_page + 1, order_by) @@ -330,7 +330,7 @@ class SystemOrgTrafficView(APIView): # get one more item than per_page, to judge has_next_page try: - traffics = seafevents_api.get_all_orgs_traffic_by_month(month_obj, + traffics = get_all_orgs_traffic_by_month(month_obj, start, start + per_page + 1, order_by) @@ -387,7 +387,7 @@ class SystemUserTrafficExcelView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: - res_data = seafevents_api.get_all_users_traffic_by_month(month_obj, -1, -1) + res_data = get_all_users_traffic_by_month(month_obj, -1, -1) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' diff --git a/seahub/base/management/commands/export_user_traffic_report.py b/seahub/base/management/commands/export_user_traffic_report.py index 61a31d88a2..edd44fa9cf 100644 --- a/seahub/base/management/commands/export_user_traffic_report.py +++ b/seahub/base/management/commands/export_user_traffic_report.py @@ -7,7 +7,7 @@ import posixpath from django.core.management.base import BaseCommand from django.utils.translation import ugettext as _ -from seahub.utils import seafevents_api +from seahub.utils import get_all_users_traffic_by_month from seahub.utils.ms_excel import write_xls from seahub.utils.file_size import byte_to_mb @@ -39,7 +39,7 @@ class Command(BaseCommand): return month_obj = datetime.datetime.strptime(month, "%Y%m") - res_data = seafevents_api.get_all_users_traffic_by_month(month_obj, -1, -1) + res_data = get_all_users_traffic_by_month(month_obj, -1, -1) data_list = [] head = [_("Time"), _("User"), _("Web Download") + ('(MB)'), \ diff --git a/seahub/handlers.py b/seahub/handlers.py index 1d7c9b994b..2672e3d189 100644 --- a/seahub/handlers.py +++ b/seahub/handlers.py @@ -9,7 +9,7 @@ logger = logging.getLogger(__name__) try: - import seafevents + import seafevents_api def repo_created_cb(sender, **kwargs): org_id = kwargs['org_id'] @@ -43,7 +43,7 @@ try: from .utils import SeafEventsSession session = SeafEventsSession() - seafevents.save_user_activity(session, record) + seafevents_api.save_user_activity(session, record) session.close() LIBRARY_TEMPLATES = getattr(settings, 'LIBRARY_TEMPLATES', {}) @@ -92,7 +92,7 @@ try: from .utils import SeafEventsSession session = SeafEventsSession() - seafevents.save_user_activity(session, record) + seafevents_api.save_user_activity(session, record) session.close() def clean_up_repo_trash_cb(sender, **kwargs): @@ -129,7 +129,7 @@ try: from .utils import SeafEventsSession session = SeafEventsSession() - seafevents.save_user_activity(session, record) + seafevents_api.save_user_activity(session, record) session.close() def repo_restored_cb(sender, **kwargs): @@ -161,7 +161,7 @@ try: from .utils import SeafEventsSession session = SeafEventsSession() - seafevents.save_user_activity(session, record) + seafevents_api.save_user_activity(session, record) session.close() except ImportError: diff --git a/seahub/notifications/management/commands/send_file_updates.py b/seahub/notifications/management/commands/send_file_updates.py index cbb1e6364f..2e24789532 100644 --- a/seahub/notifications/management/commands/send_file_updates.py +++ b/seahub/notifications/management/commands/send_file_updates.py @@ -20,7 +20,7 @@ from seahub.options.models import ( KEY_FILE_UPDATES_LAST_EMAILED_TIME ) from seahub.profile.models import Profile -from seahub.utils import (get_site_name, seafevents_api, +from seahub.utils import (get_site_name, get_user_activities_by_timestamp, send_html_email, get_site_scheme_and_netloc) from seahub.utils.timeutils import utc_to_local @@ -228,7 +228,7 @@ class Command(BaseCommand): # get file updates(from: last_emailed_time, to: now) for repos # user can access - res = seafevents_api.get_user_activities_by_timestamp( + res = get_user_activities_by_timestamp( username, last_emailed_time, now) if not res: continue diff --git a/seahub/organizations/api/admin/statistics.py b/seahub/organizations/api/admin/statistics.py index e93e5d412c..ff8c14c1ac 100644 --- a/seahub/organizations/api/admin/statistics.py +++ b/seahub/organizations/api/admin/statistics.py @@ -16,7 +16,7 @@ from seaserv import ccnet_api from seahub.utils import get_org_file_ops_stats_by_day, \ get_org_total_storage_stats_by_day, get_org_user_activity_stats_by_day, \ get_org_traffic_by_day, is_pro_version, EVENTS_ENABLED, \ - seafevents_api + get_all_users_traffic_by_month from seahub.utils.timeutils import datetime_to_isoformat_timestr from seahub.utils.ms_excel import write_xls from seahub.utils.file_size import byte_to_mb @@ -267,7 +267,7 @@ class OrgUserTrafficView(APIView): # get one more item than per_page, to judge has_next_page try: - traffics = seafevents_api.get_all_users_traffic_by_month(month_obj, + traffics = get_all_users_traffic_by_month(month_obj, start, start + per_page + 1, order_by, @@ -322,7 +322,7 @@ class OrgUserTrafficExcelView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: - res_data = seafevents_api.get_all_users_traffic_by_month(month_obj, + res_data = get_all_users_traffic_by_month(month_obj, -1, -1, org_id=org_id) except Exception as e: diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 6f967e9e9c..ef98f43915 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -60,7 +60,6 @@ logger = logging.getLogger(__name__) if EVENTS_CONFIG_FILE: try: from seafevents import seafevents_api - seafevents_api.init(EVENTS_CONFIG_FILE) except ImportError: logging.exception('Failed to import seafevents package.') seafevents_api = None @@ -552,7 +551,7 @@ if EVENTS_CONFIG_FILE: try: import seafevents EVENTS_ENABLED = True - SeafEventsSession = seafevents.init_db_session_class(EVENTS_CONFIG_FILE) + SeafEventsSession = seafevents_api.init_db_session_class(parsed_events_conf) except ImportError: logging.exception('Failed to import seafevents package.') seafevents = None @@ -626,7 +625,7 @@ if EVENTS_CONFIG_FILE: events, total_count = [], 0 try: - events = seafevents.get_user_activities(ev_session, + events = seafevents_api.get_user_activities(ev_session, username, start, count) finally: ev_session.close() @@ -643,11 +642,11 @@ if EVENTS_CONFIG_FILE: next_start = start while True: if org_id and org_id > 0: - events = seafevents.get_org_user_events(ev_session, org_id, + events = seafevents_api.get_org_user_events(ev_session, org_id, username, next_start, limit) else: - events = seafevents.get_user_events(ev_session, username, + events = seafevents_api.get_user_events(ev_session, username, next_start, limit) if not events: break @@ -657,7 +656,7 @@ if EVENTS_CONFIG_FILE: repo = seafile_api.get_repo(ev.repo_id) if not repo: # delete the update event for repo which has been deleted - seafevents.delete_event(ev_session, ev.uuid) + seafevents_api.delete_event(ev_session, ev.uuid) continue if repo.encrypted: repo.password_set = seafile_api.is_password_set( @@ -700,13 +699,14 @@ if EVENTS_CONFIG_FILE: """ """ with _get_seafevents_session() as session: - res = seafevents.get_user_activity_stats_by_day(session, start, end, offset) + res = seafevents_api.get_user_activity_stats_by_day(session, start, end, offset) return res def get_org_user_activity_stats_by_day(org_id, start, end): """ """ - res = seafevents_api.get_org_user_activity_stats_by_day(org_id, start, end) + with _get_seafevents_session() as session: + res = seafevents_api.get_org_user_activity_stats_by_day(session, org_id, start, end) return res def get_org_user_events(org_id, username, start, count): @@ -716,14 +716,14 @@ if EVENTS_CONFIG_FILE: """Return file histories """ with _get_seafevents_session() as session: - res = seafevents.get_file_history(session, repo_id, path, start, count, history_limit) + res = seafevents_api.get_file_history(session, repo_id, path, start, count, history_limit) return res def get_log_events_by_time(log_type, tstart, tend): """Return log events list by start/end timestamp. (If no logs, return 'None') """ with _get_seafevents_session() as session: - events = seafevents.get_event_log_by_time(session, log_type, tstart, tend) + events = seafevents_api.get_event_log_by_time(session, log_type, tstart, tend) return events if events else None @@ -753,7 +753,7 @@ if EVENTS_CONFIG_FILE: 15th events. """ with _get_seafevents_session() as session: - events = seafevents.get_file_audit_events_by_path(session, + events = seafevents_api.get_file_audit_events_by_path(session, email, org_id, repo_id, file_path, start, limit) return events if events else None @@ -768,7 +768,7 @@ if EVENTS_CONFIG_FILE: 15th events. """ with _get_seafevents_session() as session: - events = seafevents.get_file_audit_events(session, email, org_id, repo_id, start, limit) + events = seafevents_api.get_file_audit_events(session, email, org_id, repo_id, start, limit) return events if events else None @@ -776,36 +776,38 @@ if EVENTS_CONFIG_FILE: """ return file audit record of sepcifiy time group by day. """ with _get_seafevents_session() as session: - res = seafevents.get_file_ops_stats_by_day(session, start, end, offset) + res = seafevents_api.get_file_ops_stats_by_day(session, start, end, offset) return res def get_org_file_ops_stats_by_day(org_id, start, end, offset): """ return file audit record of sepcifiy time group by day. """ - res = seafevents_api.get_org_file_ops_stats_by_day(org_id, start, end, offset) + with _get_seafevents_session() as session: + res = seafevents_api.get_org_file_ops_stats_by_day(session, org_id, start, end, offset) return res def get_total_storage_stats_by_day(start, end, offset): """ """ with _get_seafevents_session() as session: - res = seafevents.get_total_storage_stats_by_day(session, start, end, offset) + res = seafevents_api.get_total_storage_stats_by_day(session, start, end, offset) return res def get_org_total_storage_stats_by_day(org_id, start, end, offset): """ """ - res = seafevents_api.get_org_storage_stats_by_day(org_id, start, end, offset) + with _get_seafevents_session() as session: + res = seafevents_api.get_org_storage_stats_by_day(session, org_id, start, end, offset) return res def get_system_traffic_by_day(start, end, offset, op_type='all'): with _get_seafevents_session() as session: - res = seafevents.get_system_traffic_by_day(session, start, end, offset, op_type) + res = seafevents_api.get_system_traffic_by_day(session, start, end, offset, op_type) return res def get_org_traffic_by_day(org_id, start, end, offset, op_type='all'): with _get_seafevents_session() as session: - res = seafevents.get_org_traffic_by_day(session, org_id, start, end, offset, op_type) + res = seafevents_api.get_org_traffic_by_day(session, org_id, start, end, offset, op_type) return res def get_file_update_events(email, org_id, repo_id, start, limit): @@ -818,7 +820,7 @@ if EVENTS_CONFIG_FILE: 15th events. """ with _get_seafevents_session() as session: - events = seafevents.get_file_update_events(session, email, org_id, repo_id, start, limit) + events = seafevents_api.get_file_update_events(session, email, org_id, repo_id, start, limit) return events if events else None def get_perm_audit_events(email, org_id, repo_id, start, limit): @@ -831,37 +833,66 @@ if EVENTS_CONFIG_FILE: 15th events. """ with _get_seafevents_session() as session: - events = seafevents.get_perm_audit_events(session, email, org_id, repo_id, start, limit) + events = seafevents_api.get_perm_audit_events(session, email, org_id, repo_id, start, limit) return events if events else None def get_virus_files(repo_id=None, has_handled=None, start=-1, limit=-1): with _get_seafevents_session() as session: - r = seafevents.get_virus_files(session, repo_id, has_handled, start, limit) + r = seafevents_api.get_virus_files(session, repo_id, has_handled, start, limit) return r if r else [] def delete_virus_file(vid): with _get_seafevents_session() as session: - return True if seafevents.delete_virus_file(session, vid) == 0 else False + return True if seafevents_api.delete_virus_file(session, vid) == 0 else False def operate_virus_file(vid, ignore): with _get_seafevents_session() as session: - return True if seafevents.operate_virus_file(session, vid, ignore) == 0 else False + return True if seafevents_api.operate_virus_file(session, vid, ignore) == 0 else False def get_virus_file_by_vid(vid): with _get_seafevents_session() as session: - return seafevents.get_virus_file_by_vid(session, vid) + return seafevents_api.get_virus_file_by_vid(session, vid) def get_file_scan_record(start=-1, limit=-1): - records = seafevents_api.get_content_scan_results(start, limit) + with _get_seafevents_session() as session: + records = seafevents_api.get_content_scan_results(session, start, limit) return records if records else [] def get_user_activities_by_timestamp(username, start, end): - events = seafevents.get_user_activities_by_timestamp(username, start, end) + with _get_seafevents_session() as session: + events = seafevents_api.get_user_activities_by_timestamp(session, username, start, end) return events if events else [] + def get_all_users_traffic_by_month(month, start=-1, limit=-1, order_by='user', org_id=-1): + with _get_seafevents_session() as session: + res = seafevents_api.get_all_users_traffic_by_month(session, month, start, limit, order_by, org_id) + return res + + def get_all_orgs_traffic_by_month(month, start=-1, limit=-1, order_by='user'): + with _get_seafevents_session() as session: + res = seafevents_api.get_all_orgs_traffic_by_month(session, month, start, limit, order_by) + return res + + def get_user_traffic_by_month(username, month): + with _get_seafevents_session() as session: + res = seafevents_api.get_user_traffic_by_month(session, username, month) + return res + + def get_file_history_suffix(): + return seafevents_api.get_file_history_suffix(parsed_events_conf) + else: + parsed_events_conf = None EVENTS_ENABLED = False + def get_file_history_suffix(): + pass + def get_all_users_traffic_by_month(): + pass + def get_all_orgs_traffic_by_month(): + pass + def get_user_traffic_by_month(): + pass def get_user_events(): pass def get_user_activity_stats_by_day(): @@ -1097,8 +1128,8 @@ FILE_AUDIT_ENABLED = False if EVENTS_CONFIG_FILE: def check_file_audit_enabled(): enabled = False - if hasattr(seafevents, 'is_audit_enabled'): - enabled = seafevents.is_audit_enabled(parsed_events_conf) + if hasattr(seafevents_api, 'is_audit_enabled'): + enabled = seafevents_api.is_audit_enabled(parsed_events_conf) if enabled: logging.debug('file audit: enabled') @@ -1186,8 +1217,8 @@ HAS_FILE_SEARCH = False if EVENTS_CONFIG_FILE: def check_search_enabled(): enabled = False - if hasattr(seafevents, 'is_search_enabled'): - enabled = seafevents.is_search_enabled(parsed_events_conf) + if hasattr(seafevents_api, 'is_search_enabled'): + enabled = seafevents_api.is_search_enabled(parsed_events_conf) if enabled: logging.debug('search: enabled') @@ -1202,8 +1233,8 @@ ENABLE_REPO_AUTO_DEL = False if EVENTS_CONFIG_FILE: def check_repo_auto_del_enabled(): enabled = False - if hasattr(seafevents, 'is_repo_auto_del_enabled'): - enabled = seafevents.is_repo_auto_del_enabled(EVENTS_CONFIG_FILE) + if hasattr(seafevents_api, 'is_repo_auto_del_enabled'): + enabled = seafevents_api.is_repo_auto_del_enabled(parsed_events_conf) if enabled: logging.debug('search: enabled') else: diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 4d99dd174f..ba38d274ff 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -42,7 +42,7 @@ from seahub.utils import render_permission_error, render_error, \ get_user_repos, EMPTY_SHA1, gen_file_get_url, \ new_merge_with_no_conflict, get_max_upload_file_size, \ is_pro_version, FILE_AUDIT_ENABLED, is_valid_dirent_name, \ - is_windows_operating_system, seafevents_api, IS_EMAIL_CONFIGURED + is_windows_operating_system, get_file_history_suffix, IS_EMAIL_CONFIGURED from seahub.utils.star import get_dir_starred_files from seahub.utils.repo import get_library_storages, parse_repo_perm from seahub.utils.file_op import check_file_lock @@ -779,7 +779,7 @@ def file_revisions(request, repo_id): can_revert_file = False # Whether use new file history API which read file history from db. - suffix_list = seafevents_api.get_file_history_suffix() + suffix_list = get_file_history_suffix() if suffix_list and isinstance(suffix_list, list): suffix_list = [x.lower() for x in suffix_list] else: diff --git a/tests/seahub/notifications/management/commands/test_send_file_updates.py b/tests/seahub/notifications/management/commands/test_send_file_updates.py index e91c830e19..3eb27d13ea 100644 --- a/tests/seahub/notifications/management/commands/test_send_file_updates.py +++ b/tests/seahub/notifications/management/commands/test_send_file_updates.py @@ -62,25 +62,25 @@ class CommandTest(BaseTestCase): return [Record(**x) for x in l] - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_dir_evs(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._dir_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_dir_evs(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._dir_evs() UserOptions.objects.set_file_updates_email_interval( self.user.email, 30) self.assertEqual(len(mail.outbox), 0) call_command('send_file_updates') - mock_seafevents_api.get_user_activities_by_timestamp.assert_called_once() + mock_get_user_activities_by_timestamp.assert_called_once() self.assertEqual(len(mail.outbox), 1) assert mail.outbox[0].to[0] == self.user.username for op in ['Created', 'Deleted', 'Moved', 'Restored', 'Renamed', ]: assert op in mail.outbox[0].body - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_file_evs(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._file_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_file_evs(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._file_evs() UserOptions.objects.set_file_updates_email_interval( self.user.email, 30) @@ -88,7 +88,7 @@ class CommandTest(BaseTestCase): self.assertEqual(len(mail.outbox), 0) call_command('send_file_updates') - mock_seafevents_api.get_user_activities_by_timestamp.assert_called_once() + mock_get_user_activities_by_timestamp.assert_called_once() self.assertEqual(len(mail.outbox), 1) assert mail.outbox[0].to[0] == self.user.username @@ -97,9 +97,9 @@ class CommandTest(BaseTestCase): 'Renamed', ]: assert op in mail.outbox[0].body - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_repo_evs(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._repo_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_repo_evs(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._repo_evs() UserOptions.objects.set_file_updates_email_interval( self.user.email, 30) @@ -107,7 +107,7 @@ class CommandTest(BaseTestCase): self.assertEqual(len(mail.outbox), 0) call_command('send_file_updates') - mock_seafevents_api.get_user_activities_by_timestamp.assert_called_once() + mock_get_user_activities_by_timestamp.assert_called_once() self.assertEqual(len(mail.outbox), 1) assert mail.outbox[0].to[0] == self.user.username @@ -115,9 +115,9 @@ class CommandTest(BaseTestCase): for op in ['Created', 'Deleted', 'Renamed', 'Removed']: assert op in mail.outbox[0].body - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_seafevents_api(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._repo_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_seafevents_api(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._repo_evs() username = self.user.username UserOptions.objects.set_file_updates_email_interval(username, 30) @@ -130,8 +130,8 @@ class CommandTest(BaseTestCase): call_command('send_file_updates') after_dt = datetime.datetime.utcnow().replace(microsecond=0) - mock_seafevents_api.get_user_activities_by_timestamp.assert_called_once() - args = mock_seafevents_api.get_user_activities_by_timestamp.call_args[0] + mock_get_user_activities_by_timestamp.assert_called_once() + args = mock_get_user_activities_by_timestamp.call_args[0] assert args[0] == username assert args[1] == today @@ -140,37 +140,37 @@ class CommandTest(BaseTestCase): assert last_emailed_dt <= after_dt assert last_emailed_dt == args[2] - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_email_interval(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._repo_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_email_interval(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._repo_evs() username = self.user.username assert UserOptions.objects.get_file_updates_last_emailed_time(username) is None # assume this command will be finished in 5 seconds UserOptions.objects.set_file_updates_email_interval(username, 5) - assert mock_seafevents_api.get_user_activities_by_timestamp.called is False + assert mock_get_user_activities_by_timestamp.called is False call_command('send_file_updates') - assert mock_seafevents_api.get_user_activities_by_timestamp.called is True + assert mock_get_user_activities_by_timestamp.called is True # still within 5 seconds ... - mock_seafevents_api.get_user_activities_by_timestamp.reset_mock() - assert mock_seafevents_api.get_user_activities_by_timestamp.called is False + mock_get_user_activities_by_timestamp.reset_mock() + assert mock_get_user_activities_by_timestamp.called is False call_command('send_file_updates') - assert mock_seafevents_api.get_user_activities_by_timestamp.called is False + assert mock_get_user_activities_by_timestamp.called is False time.sleep(5) # 5 seconds passed - mock_seafevents_api.get_user_activities_by_timestamp.reset_mock() - assert mock_seafevents_api.get_user_activities_by_timestamp.called is False + mock_get_user_activities_by_timestamp.reset_mock() + assert mock_get_user_activities_by_timestamp.called is False call_command('send_file_updates') - assert mock_seafevents_api.get_user_activities_by_timestamp.called is True + assert mock_get_user_activities_by_timestamp.called is True @override_settings(TIME_ZONE='Asia/Shanghai') - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_timezone_in_email_body(self, mock_seafevents_api): + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_timezone_in_email_body(self, mock_get_user_activities_by_timestamp): assert timezone.get_default_timezone_name() == 'Asia/Shanghai' - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._repo_evs() + mock_get_user_activities_by_timestamp.return_value = self._repo_evs() UserOptions.objects.set_file_updates_email_interval( self.user.email, 30) @@ -180,9 +180,9 @@ class CommandTest(BaseTestCase): self.assertEqual(len(mail.outbox), 1) assert '2018-11-05 14:46:02' in mail.outbox[0].body - @patch('seahub.notifications.management.commands.send_file_updates.seafevents_api') - def test_invalid_option_vals(self, mock_seafevents_api): - mock_seafevents_api.get_user_activities_by_timestamp.return_value = self._repo_evs() + @patch('seahub.notifications.management.commands.send_file_updates.get_user_activities_by_timestamp') + def test_invalid_option_vals(self, mock_get_user_activities_by_timestamp): + mock_get_user_activities_by_timestamp.return_value = self._repo_evs() UserOptions.objects.set_file_updates_email_interval( self.user.email, 'a')