##// END OF EJS Templates
tests update
marcink -
r875:0765fd5b beta
parent child Browse files
Show More
@@ -1,97 +1,98
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.journal
3 rhodecode.controllers.journal
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Journal controller for pylons
6 Journal controller for pylons
7
7
8 :created_on: Nov 21, 2010
8 :created_on: Nov 21, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import logging
28 import logging
29 from sqlalchemy import or_
29 from sqlalchemy import or_
30
30
31 from pylons import request, response, session, tmpl_context as c, url
31 from pylons import request, response, session, tmpl_context as c, url
32
32
33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
34 from rhodecode.lib.base import BaseController, render
34 from rhodecode.lib.base import BaseController, render
35 from rhodecode.lib.helpers import get_token
35 from rhodecode.lib.helpers import get_token
36 from rhodecode.model.db import UserLog, UserFollowing
36 from rhodecode.model.db import UserLog, UserFollowing
37 from rhodecode.model.scm import ScmModel
37 from rhodecode.model.scm import ScmModel
38
38
39 from paste.httpexceptions import HTTPInternalServerError
39 from paste.httpexceptions import HTTPInternalServerError
40
40
41 log = logging.getLogger(__name__)
41 log = logging.getLogger(__name__)
42
42
43 class JournalController(BaseController):
43 class JournalController(BaseController):
44
44
45
45
46 @LoginRequired()
46 @LoginRequired()
47 @NotAnonymous()
47 @NotAnonymous()
48 def __before__(self):
48 def __before__(self):
49 super(JournalController, self).__before__()
49 super(JournalController, self).__before__()
50
50
51 def index(self):
51 def index(self):
52 # Return a rendered template
52 # Return a rendered template
53
53
54 c.following = self.sa.query(UserFollowing)\
54 c.following = self.sa.query(UserFollowing)\
55 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
55 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
56
56
57 repo_ids = [x.follows_repository.repo_id for x in c.following
57 repo_ids = [x.follows_repository.repo_id for x in c.following
58 if x.follows_repository is not None]
58 if x.follows_repository is not None]
59 user_ids = [x.follows_user.user_id for x in c.following
59 user_ids = [x.follows_user.user_id for x in c.following
60 if x.follows_user is not None]
60 if x.follows_user is not None]
61
61
62 c.journal = self.sa.query(UserLog)\
62 c.journal = self.sa.query(UserLog)\
63 .filter(or_(
63 .filter(or_(
64 UserLog.repository_id.in_(repo_ids),
64 UserLog.repository_id.in_(repo_ids),
65 UserLog.user_id.in_(user_ids),
65 UserLog.user_id.in_(user_ids),
66 ))\
66 ))\
67 .order_by(UserLog.action_date.desc())\
67 .order_by(UserLog.action_date.desc())\
68 .limit(20)\
68 .limit(20)\
69 .all()
69 .all()
70 return render('/journal.html')
70 return render('/journal.html')
71
71
72 def toggle_following(self):
72 def toggle_following(self):
73
73 cur_token = request.POST.get('auth_token')
74 if request.POST.get('auth_token') == get_token():
74 token = get_token()
75 if cur_token == token:
75 scm_model = ScmModel()
76 scm_model = ScmModel()
76
77
77 user_id = request.POST.get('follows_user_id')
78 user_id = request.POST.get('follows_user_id')
78 if user_id:
79 if user_id:
79 try:
80 try:
80 scm_model.toggle_following_user(user_id,
81 scm_model.toggle_following_user(user_id,
81 c.rhodecode_user.user_id)
82 c.rhodecode_user.user_id)
82 return 'ok'
83 return 'ok'
83 except:
84 except:
84 raise HTTPInternalServerError()
85 raise HTTPInternalServerError()
85
86
86 repo_id = request.POST.get('follows_repo_id')
87 repo_id = request.POST.get('follows_repo_id')
87 if repo_id:
88 if repo_id:
88 try:
89 try:
89 scm_model.toggle_following_repo(repo_id,
90 scm_model.toggle_following_repo(repo_id,
90 c.rhodecode_user.user_id)
91 c.rhodecode_user.user_id)
91 return 'ok'
92 return 'ok'
92 except:
93 except:
93 raise HTTPInternalServerError()
94 raise HTTPInternalServerError()
94
95
95
96
96
97 log.debug('token mismatch %s vs %s', cur_token, token)
97 raise HTTPInternalServerError()
98 raise HTTPInternalServerError()
@@ -1,11 +1,15
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2
2
3 class TestHomeController(TestController):
3 class TestHomeController(TestController):
4
4
5 def test_index(self):
5 def test_index(self):
6 self.log_user()
6 self.log_user()
7 response = self.app.get(url(controller='home', action='index'))
7 response = self.app.get(url(controller='home', action='index'))
8 #if global permission is set
8 #if global permission is set
9 assert 'ADD NEW REPOSITORY' in response.body, 'Wrong main page'
9 assert 'ADD NEW REPOSITORY' in response.body, 'No Button for add new repository'
10 assert 'href="/%s/summary"' % HG_REPO in response.body, ' mising repository in list'
10 assert 'href="/%s/summary"' % HG_REPO in response.body, ' mising repository in list'
11 # Test response...
11 # Test response...
12
13 assert """<img class="icon" title="Mercurial repository" alt="Mercurial repository" src="/images/icons/hgicon.png"/>""" in response.body, 'wrong info about type of repositry'
14 assert """<img class="icon" title="public repository" alt="public repository" src="/images/icons/lock_open.png"/>""" in response.body, 'wrong info about repository availabilty'
15 assert """<a class="tooltip" href="/vcs_test_hg/changeset/27cd5cce30c96924232dffcd24178a07ffeb5dfc" tooltip_title="merge">r173:27cd5cce30c9</a>""" in response.body, 'no info about tooltip'
@@ -1,7 +1,47
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2 from rhodecode.model.db import UserFollowing, User, Repository
3 from rhodecode.lib.helpers import get_token
2
4
3 class TestJournalController(TestController):
5 class TestJournalController(TestController):
4
6
5 def test_index(self):
7 def test_index(self):
8 self.log_user()
6 response = self.app.get(url(controller='journal', action='index'))
9 response = self.app.get(url(controller='journal', action='index'))
7 # Test response...
10 # Test response...
11 assert """<div class="currently_following">
12
13
14 <img class="icon" title="public repository" alt="public repository" src="/images/icons/lock_open.png"/>
15
16 <a href="/vcs_test_hg/summary">vcs_test_hg</a>
17
18 </div>""" in response.body, 'following repo list'
19
20
21
22 def test_stop_following_repository(self):
23 session = self.log_user()
24 # usr = self.sa.query(User).filter(User.username == 'test_admin').one()
25 # repo = self.sa.query(Repository).filter(Repository.repo_name == HG_REPO).one()
26 #
27 # followings = self.sa.query(UserFollowing)\
28 # .filter(UserFollowing.user == usr)\
29 # .filter(UserFollowing.follows_repository == repo).all()
30 #
31 # assert len(followings) == 1, 'Not following any repository'
32 #
33 # response = self.app.post(url(controller='journal',
34 # action='toggle_following'),
35 # {'auth_token':get_token(session),
36 # 'follows_repo_id':repo.repo_id})
37
38 def test_start_following_repository(self):
39 self.log_user()
40 response = self.app.get(url(controller='journal', action='index'),)
41
42
43 def __add_repo(self):
44 pass
45
46 def __remove_repo(self):
47 pass
General Comments 0
You need to be logged in to leave comments. Login now