##// END OF EJS Templates
celery: move async tasks to model - they both use model and are used by model, so they must be pretty much the same
Mads Kiilerich -
r8556:341e4bb9 default
parent child Browse files
Show More
@@ -39,12 +39,11 b' import kallithea'
39 from kallithea.lib import webutils
39 from kallithea.lib import webutils
40 from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
40 from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
41 from kallithea.lib.base import BaseController, render
41 from kallithea.lib.base import BaseController, render
42 from kallithea.lib.celerylib import tasks
43 from kallithea.lib.utils import repo2db_mapper, set_app_settings
42 from kallithea.lib.utils import repo2db_mapper, set_app_settings
44 from kallithea.lib.utils2 import safe_str
43 from kallithea.lib.utils2 import safe_str
45 from kallithea.lib.vcs import VCSError
44 from kallithea.lib.vcs import VCSError
46 from kallithea.lib.webutils import url
45 from kallithea.lib.webutils import url
47 from kallithea.model import db, meta
46 from kallithea.model import async_tasks, db, meta
48 from kallithea.model.forms import ApplicationSettingsForm, ApplicationUiSettingsForm, ApplicationVisualisationForm
47 from kallithea.model.forms import ApplicationSettingsForm, ApplicationUiSettingsForm, ApplicationVisualisationForm
49 from kallithea.model.notification import EmailNotificationModel
48 from kallithea.model.notification import EmailNotificationModel
50 from kallithea.model.scm import ScmModel
49 from kallithea.model.scm import ScmModel
@@ -301,7 +300,7 b' class SettingsController(BaseController)'
301
300
302 recipients = [test_email] if test_email else None
301 recipients = [test_email] if test_email else None
303
302
304 tasks.send_email(recipients, test_email_subj,
303 async_tasks.send_email(recipients, test_email_subj,
305 test_email_txt_body, test_email_html_body)
304 test_email_txt_body, test_email_html_body)
306
305
307 webutils.flash(_('Send email task created'), category='success')
306 webutils.flash(_('Send email task created'), category='success')
@@ -379,7 +378,7 b' class SettingsController(BaseController)'
379 if request.POST:
378 if request.POST:
380 repo_location = self._get_hg_ui_settings()['paths_root_path']
379 repo_location = self._get_hg_ui_settings()['paths_root_path']
381 full_index = request.POST.get('full_index', False)
380 full_index = request.POST.get('full_index', False)
382 tasks.whoosh_index(repo_location, full_index)
381 async_tasks.whoosh_index(repo_location, full_index)
383 webutils.flash(_('Whoosh reindex task scheduled'), category='success')
382 webutils.flash(_('Whoosh reindex task scheduled'), category='success')
384 raise HTTPFound(location=url('admin_settings_search'))
383 raise HTTPFound(location=url('admin_settings_search'))
385
384
@@ -41,7 +41,6 b' from webob.exc import HTTPBadRequest'
41 from kallithea.lib import ext_json, webutils
41 from kallithea.lib import ext_json, webutils
42 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
42 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
43 from kallithea.lib.base import BaseRepoController, jsonify, render
43 from kallithea.lib.base import BaseRepoController, jsonify, render
44 from kallithea.lib.celerylib.tasks import get_commits_stats
45 from kallithea.lib.conf import ALL_EXTS, ALL_READMES, LANGUAGES_EXTENSIONS_MAP
44 from kallithea.lib.conf import ALL_EXTS, ALL_READMES, LANGUAGES_EXTENSIONS_MAP
46 from kallithea.lib.markup_renderer import MarkupRenderer
45 from kallithea.lib.markup_renderer import MarkupRenderer
47 from kallithea.lib.page import Page
46 from kallithea.lib.page import Page
@@ -49,7 +48,7 b' from kallithea.lib.utils2 import safe_in'
49 from kallithea.lib.vcs.backends.base import EmptyChangeset
48 from kallithea.lib.vcs.backends.base import EmptyChangeset
50 from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
49 from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
51 from kallithea.lib.vcs.nodes import FileNode
50 from kallithea.lib.vcs.nodes import FileNode
52 from kallithea.model import db
51 from kallithea.model import async_tasks, db
53
52
54
53
55 log = logging.getLogger(__name__)
54 log = logging.getLogger(__name__)
@@ -209,5 +208,5 b' class SummaryController(BaseRepoControll'
209 c.trending_languages = []
208 c.trending_languages = []
210
209
211 recurse_limit = 500 # don't recurse more than 500 times when parsing
210 recurse_limit = 500 # don't recurse more than 500 times when parsing
212 get_commits_stats(c.db_repo.repo_name, ts_min_y, ts_max_y, recurse_limit)
211 async_tasks.get_commits_stats(c.db_repo.repo_name, ts_min_y, ts_max_y, recurse_limit)
213 return render('summary/statistics.html')
212 return render('summary/statistics.html')
@@ -23,7 +23,7 b' import kallithea'
23
23
24
24
25 class CeleryConfig(object):
25 class CeleryConfig(object):
26 imports = ['kallithea.lib.celerylib.tasks']
26 imports = ['kallithea.model.async_tasks']
27 task_always_eager = False
27 task_always_eager = False
28
28
29 # map from Kallithea .ini Celery 3 config names to Celery 4 config names
29 # map from Kallithea .ini Celery 3 config names to Celery 4 config names
@@ -12,8 +12,8 b''
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 kallithea.lib.celerylib.tasks
15 kallithea.model.async_tasks
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
17
18 Kallithea task modules, containing all task that suppose to be run
18 Kallithea task modules, containing all task that suppose to be run
19 by celery daemon
19 by celery daemon
@@ -45,8 +45,7 b' from kallithea.lib import celerylib, con'
45 from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
45 from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
46 from kallithea.lib.utils2 import asbool, ascii_bytes
46 from kallithea.lib.utils2 import asbool, ascii_bytes
47 from kallithea.lib.vcs.utils import author_email
47 from kallithea.lib.vcs.utils import author_email
48 from kallithea.model import db, userlog
48 from kallithea.model import db, repo, userlog
49 from kallithea.model.repo import RepoModel
50
49
51
50
52 __all__ = ['whoosh_index', 'get_commits_stats', 'send_email']
51 __all__ = ['whoosh_index', 'get_commits_stats', 'send_email']
@@ -87,12 +86,12 b' def get_commits_stats(repo_name, ts_min_'
87
86
88 co_day_auth_aggr = {}
87 co_day_auth_aggr = {}
89 commits_by_day_aggregate = {}
88 commits_by_day_aggregate = {}
90 repo = db.Repository.get_by_repo_name(repo_name)
89 db_repo = db.Repository.get_by_repo_name(repo_name)
91 if repo is None:
90 if db_repo is None:
92 return True
91 return True
93
92
94 repo = repo.scm_instance
93 scm_repo = db_repo.scm_instance
95 repo_size = repo.count()
94 repo_size = scm_repo.count()
96 # return if repo have no revisions
95 # return if repo have no revisions
97 if repo_size < 1:
96 if repo_size < 1:
98 lock.release()
97 lock.release()
@@ -112,7 +111,7 b' def get_commits_stats(repo_name, ts_min_'
112 if cur_stats is not None:
111 if cur_stats is not None:
113 last_rev = cur_stats.stat_on_revision
112 last_rev = cur_stats.stat_on_revision
114
113
115 if last_rev == repo.get_changeset().revision and repo_size > 1:
114 if last_rev == scm_repo.get_changeset().revision and repo_size > 1:
116 # pass silently without any work if we're not on first revision or
115 # pass silently without any work if we're not on first revision or
117 # current state of parsing revision(from db marker) is the
116 # current state of parsing revision(from db marker) is the
118 # last revision
117 # last revision
@@ -130,7 +129,7 b' def get_commits_stats(repo_name, ts_min_'
130 log.debug('Getting revisions from %s to %s',
129 log.debug('Getting revisions from %s to %s',
131 last_rev, last_rev + parse_limit
130 last_rev, last_rev + parse_limit
132 )
131 )
133 for cs in repo[last_rev:last_rev + parse_limit]:
132 for cs in scm_repo[last_rev:last_rev + parse_limit]:
134 log.debug('parsing %s', cs)
133 log.debug('parsing %s', cs)
135 last_cs = cs # remember last parsed changeset
134 last_cs = cs # remember last parsed changeset
136 tt = cs.date.timetuple()
135 tt = cs.date.timetuple()
@@ -188,8 +187,8 b' def get_commits_stats(repo_name, ts_min_'
188 key=itemgetter(0))
187 key=itemgetter(0))
189
188
190 if not co_day_auth_aggr:
189 if not co_day_auth_aggr:
191 co_day_auth_aggr[akc(repo.contact)] = {
190 co_day_auth_aggr[akc(scm_repo.contact)] = {
192 "label": akc(repo.contact),
191 "label": akc(scm_repo.contact),
193 "data": [0, 1],
192 "data": [0, 1],
194 "schema": ["commits"],
193 "schema": ["commits"],
195 }
194 }
@@ -199,7 +198,7 b' def get_commits_stats(repo_name, ts_min_'
199 stats.commit_activity_combined = ascii_bytes(ext_json.dumps(overview_data))
198 stats.commit_activity_combined = ascii_bytes(ext_json.dumps(overview_data))
200
199
201 log.debug('last revision %s', last_rev)
200 log.debug('last revision %s', last_rev)
202 leftovers = len(repo.revisions[last_rev:])
201 leftovers = len(scm_repo.revisions[last_rev:])
203 log.debug('revisions to parse %s', leftovers)
202 log.debug('revisions to parse %s', leftovers)
204
203
205 if last_rev == 0 or leftovers < parse_limit:
204 if last_rev == 0 or leftovers < parse_limit:
@@ -221,7 +220,7 b' def get_commits_stats(repo_name, ts_min_'
221 lock.release()
220 lock.release()
222
221
223 # execute another task if celery is enabled
222 # execute another task if celery is enabled
224 if len(repo.revisions) > 1 and kallithea.CELERY_APP and recurse_limit > 0:
223 if len(scm_repo.revisions) > 1 and kallithea.CELERY_APP and recurse_limit > 0:
225 get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit - 1)
224 get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit - 1)
226 elif recurse_limit <= 0:
225 elif recurse_limit <= 0:
227 log.debug('Not recursing - limit has been reached')
226 log.debug('Not recursing - limit has been reached')
@@ -376,7 +375,7 b' def create_repo(form_data, cur_user):'
376 enable_downloads = defs.get('repo_enable_downloads')
375 enable_downloads = defs.get('repo_enable_downloads')
377
376
378 try:
377 try:
379 repo = RepoModel()._create_repo(
378 db_repo = repo.RepoModel()._create_repo(
380 repo_name=repo_name_full,
379 repo_name=repo_name_full,
381 repo_type=repo_type,
380 repo_type=repo_type,
382 description=description,
381 description=description,
@@ -398,30 +397,30 b' def create_repo(form_data, cur_user):'
398
397
399 DBS.commit()
398 DBS.commit()
400 # now create this repo on Filesystem
399 # now create this repo on Filesystem
401 RepoModel()._create_filesystem_repo(
400 repo.RepoModel()._create_filesystem_repo(
402 repo_name=repo_name,
401 repo_name=repo_name,
403 repo_type=repo_type,
402 repo_type=repo_type,
404 repo_group=db.RepoGroup.guess_instance(repo_group),
403 repo_group=db.RepoGroup.guess_instance(repo_group),
405 clone_uri=clone_uri,
404 clone_uri=clone_uri,
406 )
405 )
407 repo = db.Repository.get_by_repo_name(repo_name_full)
406 db_repo = db.Repository.get_by_repo_name(repo_name_full)
408 hooks.log_create_repository(repo.get_dict(), created_by=owner.username)
407 hooks.log_create_repository(db_repo.get_dict(), created_by=owner.username)
409
408
410 # update repo changeset caches initially
409 # update repo changeset caches initially
411 repo.update_changeset_cache()
410 db_repo.update_changeset_cache()
412
411
413 # set new created state
412 # set new created state
414 repo.set_state(db.Repository.STATE_CREATED)
413 db_repo.set_state(db.Repository.STATE_CREATED)
415 DBS.commit()
414 DBS.commit()
416 except Exception as e:
415 except Exception as e:
417 log.warning('Exception %s occurred when forking repository, '
416 log.warning('Exception %s occurred when forking repository, '
418 'doing cleanup...' % e)
417 'doing cleanup...' % e)
419 # rollback things manually !
418 # rollback things manually !
420 repo = db.Repository.get_by_repo_name(repo_name_full)
419 db_repo = db.Repository.get_by_repo_name(repo_name_full)
421 if repo:
420 if db_repo:
422 db.Repository.delete(repo.repo_id)
421 db.Repository.delete(db_repo.repo_id)
423 DBS.commit()
422 DBS.commit()
424 RepoModel()._delete_filesystem_repo(repo)
423 repo.RepoModel()._delete_filesystem_repo(db_repo)
425 raise
424 raise
426
425
427 return True
426 return True
@@ -455,7 +454,7 b' def create_repo_fork(form_data, cur_user'
455 try:
454 try:
456 fork_of = db.Repository.guess_instance(form_data.get('fork_parent_id'))
455 fork_of = db.Repository.guess_instance(form_data.get('fork_parent_id'))
457
456
458 RepoModel()._create_repo(
457 repo.RepoModel()._create_repo(
459 repo_name=repo_name_full,
458 repo_name=repo_name_full,
460 repo_type=repo_type,
459 repo_type=repo_type,
461 description=form_data['description'],
460 description=form_data['description'],
@@ -474,39 +473,39 b' def create_repo_fork(form_data, cur_user'
474 source_repo_path = os.path.join(base_path, fork_of.repo_name)
473 source_repo_path = os.path.join(base_path, fork_of.repo_name)
475
474
476 # now create this repo on Filesystem
475 # now create this repo on Filesystem
477 RepoModel()._create_filesystem_repo(
476 repo.RepoModel()._create_filesystem_repo(
478 repo_name=repo_name,
477 repo_name=repo_name,
479 repo_type=repo_type,
478 repo_type=repo_type,
480 repo_group=db.RepoGroup.guess_instance(repo_group),
479 repo_group=db.RepoGroup.guess_instance(repo_group),
481 clone_uri=source_repo_path,
480 clone_uri=source_repo_path,
482 )
481 )
483 repo = db.Repository.get_by_repo_name(repo_name_full)
482 db_repo = db.Repository.get_by_repo_name(repo_name_full)
484 hooks.log_create_repository(repo.get_dict(), created_by=owner.username)
483 hooks.log_create_repository(db_repo.get_dict(), created_by=owner.username)
485
484
486 # update repo changeset caches initially
485 # update repo changeset caches initially
487 repo.update_changeset_cache()
486 db_repo.update_changeset_cache()
488
487
489 # set new created state
488 # set new created state
490 repo.set_state(db.Repository.STATE_CREATED)
489 db_repo.set_state(db.Repository.STATE_CREATED)
491 DBS.commit()
490 DBS.commit()
492 except Exception as e:
491 except Exception as e:
493 log.warning('Exception %s occurred when forking repository, '
492 log.warning('Exception %s occurred when forking repository, '
494 'doing cleanup...' % e)
493 'doing cleanup...' % e)
495 # rollback things manually !
494 # rollback things manually !
496 repo = db.Repository.get_by_repo_name(repo_name_full)
495 db_repo = db.Repository.get_by_repo_name(repo_name_full)
497 if repo:
496 if db_repo:
498 db.Repository.delete(repo.repo_id)
497 db.Repository.delete(db_repo.repo_id)
499 DBS.commit()
498 DBS.commit()
500 RepoModel()._delete_filesystem_repo(repo)
499 repo.RepoModel()._delete_filesystem_repo(db_repo)
501 raise
500 raise
502
501
503 return True
502 return True
504
503
505
504
506 def __get_codes_stats(repo_name):
505 def __get_codes_stats(repo_name):
507 repo = db.Repository.get_by_repo_name(repo_name).scm_instance
506 scm_repo = db.Repository.get_by_repo_name(repo_name).scm_instance
508
507
509 tip = repo.get_changeset()
508 tip = scm_repo.get_changeset()
510 code_stats = {}
509 code_stats = {}
511
510
512 for _topnode, _dirnodes, filenodes in tip.walk('/'):
511 for _topnode, _dirnodes, filenodes in tip.walk('/'):
@@ -34,7 +34,7 b' from tg import tmpl_context as c'
34 from tg.i18n import ugettext as _
34 from tg.i18n import ugettext as _
35
35
36 from kallithea.lib.utils2 import fmt_date
36 from kallithea.lib.utils2 import fmt_date
37 from kallithea.model import db
37 from kallithea.model import async_tasks, db
38
38
39
39
40 log = logging.getLogger(__name__)
40 log = logging.getLogger(__name__)
@@ -66,7 +66,6 b' class NotificationModel(object):'
66 :param email_kwargs: additional dict to pass as args to email template
66 :param email_kwargs: additional dict to pass as args to email template
67 """
67 """
68 import kallithea.lib.helpers as h
68 import kallithea.lib.helpers as h
69 from kallithea.lib.celerylib import tasks
70 email_kwargs = email_kwargs or {}
69 email_kwargs = email_kwargs or {}
71 if recipients and not getattr(recipients, '__iter__', False):
70 if recipients and not getattr(recipients, '__iter__', False):
72 raise Exception('recipients must be a list or iterable')
71 raise Exception('recipients must be a list or iterable')
@@ -135,7 +134,7 b' class NotificationModel(object):'
135
134
136 # send email with notification to participants
135 # send email with notification to participants
137 for rec_mail in sorted(rec_mails):
136 for rec_mail in sorted(rec_mails):
138 tasks.send_email([rec_mail], email_subject, email_txt_body,
137 async_tasks.send_email([rec_mail], email_subject, email_txt_body,
139 email_html_body, headers,
138 email_html_body, headers,
140 from_name=created_by_obj.full_name_or_username)
139 from_name=created_by_obj.full_name_or_username)
141
140
@@ -405,8 +405,8 b' class RepoModel(object):'
405 :param form_data:
405 :param form_data:
406 :param cur_user:
406 :param cur_user:
407 """
407 """
408 from kallithea.lib.celerylib import tasks
408 from kallithea.model import async_tasks
409 return tasks.create_repo(form_data, cur_user)
409 return async_tasks.create_repo(form_data, cur_user)
410
410
411 def _update_permissions(self, repo, perms_new=None, perms_updates=None,
411 def _update_permissions(self, repo, perms_new=None, perms_updates=None,
412 check_perms=True):
412 check_perms=True):
@@ -448,8 +448,8 b' class RepoModel(object):'
448 :param form_data:
448 :param form_data:
449 :param cur_user:
449 :param cur_user:
450 """
450 """
451 from kallithea.lib.celerylib import tasks
451 from kallithea.model import async_tasks
452 return tasks.create_repo_fork(form_data, cur_user)
452 return async_tasks.create_repo_fork(form_data, cur_user)
453
453
454 def delete(self, repo, forks=None, fs_remove=True, cur_user=None):
454 def delete(self, repo, forks=None, fs_remove=True, cur_user=None):
455 """
455 """
@@ -298,8 +298,7 b' class UserModel(object):'
298 allowing users to copy-paste or manually enter the token from the
298 allowing users to copy-paste or manually enter the token from the
299 email.
299 email.
300 """
300 """
301 from kallithea.lib.celerylib import tasks
301 from kallithea.model import async_tasks, notification
302 from kallithea.model import notification
303
302
304 user_email = data['email']
303 user_email = data['email']
305 user = db.User.get_by_email(user_email)
304 user = db.User.get_by_email(user_email)
@@ -332,7 +331,7 b' class UserModel(object):'
332 reset_token=token,
331 reset_token=token,
333 reset_url=link)
332 reset_url=link)
334 log.debug('sending email')
333 log.debug('sending email')
335 tasks.send_email([user_email], _("Password reset link"), body, html_body)
334 async_tasks.send_email([user_email], _("Password reset link"), body, html_body)
336 log.info('send new password mail to %s', user_email)
335 log.info('send new password mail to %s', user_email)
337 else:
336 else:
338 log.debug("password reset email %s not found", user_email)
337 log.debug("password reset email %s not found", user_email)
@@ -365,7 +364,7 b' class UserModel(object):'
365 return expected_token == token
364 return expected_token == token
366
365
367 def reset_password(self, user_email, new_passwd):
366 def reset_password(self, user_email, new_passwd):
368 from kallithea.lib.celerylib import tasks
367 from kallithea.model import async_tasks
369 user = db.User.get_by_email(user_email)
368 user = db.User.get_by_email(user_email)
370 if user is not None:
369 if user is not None:
371 if not self.can_change_password(user):
370 if not self.can_change_password(user):
@@ -376,7 +375,7 b' class UserModel(object):'
376 if new_passwd is None:
375 if new_passwd is None:
377 raise Exception('unable to set new password')
376 raise Exception('unable to set new password')
378
377
379 tasks.send_email([user_email],
378 async_tasks.send_email([user_email],
380 _('Password reset notification'),
379 _('Password reset notification'),
381 _('The password to your account %s has been changed using password reset form.') % (user.username,))
380 _('The password to your account %s has been changed using password reset form.') % (user.username,))
382 log.info('send password reset mail to %s', user_email)
381 log.info('send password reset mail to %s', user_email)
@@ -6,7 +6,7 b' import urllib.parse'
6 import mock
6 import mock
7 from tg.util.webtest import test_context
7 from tg.util.webtest import test_context
8
8
9 import kallithea.lib.celerylib.tasks
9 import kallithea.model.async_tasks
10 from kallithea.lib import webutils
10 from kallithea.lib import webutils
11 from kallithea.lib.utils2 import check_password, generate_api_key
11 from kallithea.lib.utils2 import check_password, generate_api_key
12 from kallithea.model import db, meta, validators
12 from kallithea.model import db, meta, validators
@@ -410,7 +410,7 b' class TestLoginController(base.TestContr'
410 def mock_send_email(recipients, subject, body='', html_body='', headers=None, from_name=None):
410 def mock_send_email(recipients, subject, body='', html_body='', headers=None, from_name=None):
411 collected.append((recipients, subject, body, html_body))
411 collected.append((recipients, subject, body, html_body))
412
412
413 with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', mock_send_email), \
413 with mock.patch.object(kallithea.model.async_tasks, 'send_email', mock_send_email), \
414 mock.patch.object(time, 'time', lambda: timestamp):
414 mock.patch.object(time, 'time', lambda: timestamp):
415 response = self.app.post(base.url(controller='login',
415 response = self.app.post(base.url(controller='login',
416 action='password_reset'),
416 action='password_reset'),
@@ -5,8 +5,8 b' import mock'
5 from tg.util.webtest import test_context
5 from tg.util.webtest import test_context
6
6
7 import kallithea.lib.celerylib
7 import kallithea.lib.celerylib
8 import kallithea.lib.celerylib.tasks
9 import kallithea.lib.helpers as h
8 import kallithea.lib.helpers as h
9 import kallithea.model.async_tasks
10 from kallithea.model import db, meta
10 from kallithea.model import db, meta
11 from kallithea.model.notification import EmailNotificationModel, NotificationModel
11 from kallithea.model.notification import EmailNotificationModel, NotificationModel
12 from kallithea.model.user import UserModel
12 from kallithea.model.user import UserModel
@@ -48,7 +48,7 b' class TestNotifications(base.TestControl'
48 assert body == "hi there"
48 assert body == "hi there"
49 assert '>hi there<' in html_body
49 assert '>hi there<' in html_body
50 assert from_name == 'u1 u1'
50 assert from_name == 'u1 u1'
51 with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email):
51 with mock.patch.object(kallithea.model.async_tasks, 'send_email', send_email):
52 NotificationModel().create(created_by=self.u1,
52 NotificationModel().create(created_by=self.u1,
53 body='hi there',
53 body='hi there',
54 recipients=usrs)
54 recipients=usrs)
@@ -73,7 +73,7 b' class TestNotifications(base.TestControl'
73 l.append('<hr/>\n')
73 l.append('<hr/>\n')
74
74
75 with test_context(self.app):
75 with test_context(self.app):
76 with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email):
76 with mock.patch.object(kallithea.model.async_tasks, 'send_email', send_email):
77 pr_kwargs = dict(
77 pr_kwargs = dict(
78 pr_nice_id='#7',
78 pr_nice_id='#7',
79 pr_title='The Title',
79 pr_title='The Title',
@@ -155,7 +155,7 b' class TestNotifications(base.TestControl'
155 # Email type TYPE_PASSWORD_RESET has no corresponding notification type - test it directly:
155 # Email type TYPE_PASSWORD_RESET has no corresponding notification type - test it directly:
156 desc = 'TYPE_PASSWORD_RESET'
156 desc = 'TYPE_PASSWORD_RESET'
157 kwargs = dict(user='John Doe', reset_token='decbf64715098db5b0bd23eab44bd792670ab746', reset_url='http://reset.com/decbf64715098db5b0bd23eab44bd792670ab746')
157 kwargs = dict(user='John Doe', reset_token='decbf64715098db5b0bd23eab44bd792670ab746', reset_url='http://reset.com/decbf64715098db5b0bd23eab44bd792670ab746')
158 kallithea.lib.celerylib.tasks.send_email(['john@doe.com'],
158 kallithea.model.async_tasks.send_email(['john@doe.com'],
159 "Password reset link",
159 "Password reset link",
160 EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'txt', **kwargs),
160 EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'txt', **kwargs),
161 EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'html', **kwargs),
161 EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'html', **kwargs),
@@ -25,7 +25,7 b' class smtplib_mock(object):'
25 smtplib_mock.lastmsg = msg
25 smtplib_mock.lastmsg = msg
26
26
27
27
28 @mock.patch('kallithea.lib.celerylib.tasks.smtplib', smtplib_mock)
28 @mock.patch('kallithea.model.async_tasks.smtplib', smtplib_mock)
29 class TestMail(base.TestController):
29 class TestMail(base.TestController):
30
30
31 def test_send_mail_trivial(self):
31 def test_send_mail_trivial(self):
@@ -40,8 +40,8 b' class TestMail(base.TestController):'
40 'smtp_server': mailserver,
40 'smtp_server': mailserver,
41 'app_email_from': envelope_from,
41 'app_email_from': envelope_from,
42 }
42 }
43 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
43 with mock.patch('kallithea.model.async_tasks.config', config_mock):
44 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body)
44 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body)
45
45
46 assert smtplib_mock.lastdest == set(recipients)
46 assert smtplib_mock.lastdest == set(recipients)
47 assert smtplib_mock.lastsender == envelope_from
47 assert smtplib_mock.lastsender == envelope_from
@@ -64,8 +64,8 b' class TestMail(base.TestController):'
64 'app_email_from': envelope_from,
64 'app_email_from': envelope_from,
65 'email_to': email_to,
65 'email_to': email_to,
66 }
66 }
67 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
67 with mock.patch('kallithea.model.async_tasks.config', config_mock):
68 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body)
68 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body)
69
69
70 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL, email_to])
70 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL, email_to])
71 assert smtplib_mock.lastsender == envelope_from
71 assert smtplib_mock.lastsender == envelope_from
@@ -88,8 +88,8 b' class TestMail(base.TestController):'
88 'app_email_from': envelope_from,
88 'app_email_from': envelope_from,
89 'email_to': email_to,
89 'email_to': email_to,
90 }
90 }
91 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
91 with mock.patch('kallithea.model.async_tasks.config', config_mock):
92 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body)
92 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body)
93
93
94 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL] + email_to.split(','))
94 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL] + email_to.split(','))
95 assert smtplib_mock.lastsender == envelope_from
95 assert smtplib_mock.lastsender == envelope_from
@@ -110,8 +110,8 b' class TestMail(base.TestController):'
110 'smtp_server': mailserver,
110 'smtp_server': mailserver,
111 'app_email_from': envelope_from,
111 'app_email_from': envelope_from,
112 }
112 }
113 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
113 with mock.patch('kallithea.model.async_tasks.config', config_mock):
114 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body)
114 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body)
115
115
116 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL])
116 assert smtplib_mock.lastdest == set([base.TEST_USER_ADMIN_EMAIL])
117 assert smtplib_mock.lastsender == envelope_from
117 assert smtplib_mock.lastsender == envelope_from
@@ -133,8 +133,8 b' class TestMail(base.TestController):'
133 'smtp_server': mailserver,
133 'smtp_server': mailserver,
134 'app_email_from': envelope_from,
134 'app_email_from': envelope_from,
135 }
135 }
136 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
136 with mock.patch('kallithea.model.async_tasks.config', config_mock):
137 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body, from_name=author.full_name_or_username)
137 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body, from_name=author.full_name_or_username)
138
138
139 assert smtplib_mock.lastdest == set(recipients)
139 assert smtplib_mock.lastdest == set(recipients)
140 assert smtplib_mock.lastsender == envelope_from
140 assert smtplib_mock.lastsender == envelope_from
@@ -157,8 +157,8 b' class TestMail(base.TestController):'
157 'smtp_server': mailserver,
157 'smtp_server': mailserver,
158 'app_email_from': envelope_from,
158 'app_email_from': envelope_from,
159 }
159 }
160 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
160 with mock.patch('kallithea.model.async_tasks.config', config_mock):
161 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body, from_name=author.full_name_or_username)
161 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body, from_name=author.full_name_or_username)
162
162
163 assert smtplib_mock.lastdest == set(recipients)
163 assert smtplib_mock.lastdest == set(recipients)
164 assert smtplib_mock.lastsender == envelope_from
164 assert smtplib_mock.lastsender == envelope_from
@@ -181,8 +181,8 b' class TestMail(base.TestController):'
181 'smtp_server': mailserver,
181 'smtp_server': mailserver,
182 'app_email_from': envelope_from,
182 'app_email_from': envelope_from,
183 }
183 }
184 with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
184 with mock.patch('kallithea.model.async_tasks.config', config_mock):
185 kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body,
185 kallithea.model.async_tasks.send_email(recipients, subject, body, html_body,
186 from_name=author.full_name_or_username, headers=headers)
186 from_name=author.full_name_or_username, headers=headers)
187
187
188 assert smtplib_mock.lastdest == set(recipients)
188 assert smtplib_mock.lastdest == set(recipients)
@@ -131,7 +131,6 b' conftest'
131
131
132 normal_modules = set('''
132 normal_modules = set('''
133 kallithea
133 kallithea
134 kallithea.lib.celerylib.tasks
135 kallithea.lib
134 kallithea.lib
136 kallithea.lib.auth
135 kallithea.lib.auth
137 kallithea.lib.auth_modules
136 kallithea.lib.auth_modules
@@ -146,6 +145,7 b' kallithea.lib.utils2'
146 kallithea.lib.vcs
145 kallithea.lib.vcs
147 kallithea.lib.webutils
146 kallithea.lib.webutils
148 kallithea.model
147 kallithea.model
148 kallithea.model.async_tasks
149 kallithea.model.scm
149 kallithea.model.scm
150 kallithea.templates.py
150 kallithea.templates.py
151 '''.split())
151 '''.split())
@@ -158,10 +158,10 b' known_violations = ['
158 ('kallithea.lib.utils', 'kallithea.model'), # clean up utils
158 ('kallithea.lib.utils', 'kallithea.model'), # clean up utils
159 ('kallithea.lib.utils', 'kallithea.model.db'),
159 ('kallithea.lib.utils', 'kallithea.model.db'),
160 ('kallithea.lib.utils', 'kallithea.model.scm'),
160 ('kallithea.lib.utils', 'kallithea.model.scm'),
161 ('kallithea.lib.celerylib.tasks', 'kallithea.lib.helpers'),
161 ('kallithea.model.async_tasks', 'kallithea.lib.helpers'),
162 ('kallithea.lib.celerylib.tasks', 'kallithea.lib.hooks'),
162 ('kallithea.model.async_tasks', 'kallithea.lib.hooks'),
163 ('kallithea.lib.celerylib.tasks', 'kallithea.lib.indexers'),
163 ('kallithea.model.async_tasks', 'kallithea.lib.indexers'),
164 ('kallithea.lib.celerylib.tasks', 'kallithea.model'),
164 ('kallithea.model.async_tasks', 'kallithea.model'),
165 ('kallithea.model', 'kallithea.lib.auth'), # auth.HasXXX
165 ('kallithea.model', 'kallithea.lib.auth'), # auth.HasXXX
166 ('kallithea.model', 'kallithea.lib.auth_modules'), # validators
166 ('kallithea.model', 'kallithea.lib.auth_modules'), # validators
167 ('kallithea.model', 'kallithea.lib.helpers'),
167 ('kallithea.model', 'kallithea.lib.helpers'),
General Comments 0
You need to be logged in to leave comments. Login now