##// END OF EJS Templates
Fixed tests for new i18n changes...
marcink -
r2317:c4d8ed62 beta
parent child Browse files
Show More
@@ -1,21 +1,22 b''
1 1 List of contributors to RhodeCode project:
2 2 Marcin Kuźmiński <marcin@python-works.com>
3 3 Lukasz Balcerzak <lukaszbalcerzak@gmail.com>
4 4 Jason Harris <jason@jasonfharris.com>
5 5 Thayne Harbaugh <thayne@fusionio.com>
6 6 cejones <>
7 7 Thomas Waldmann <tw-public@gmx.de>
8 8 Lorenzo M. Catucci <lorenzo@sancho.ccd.uniroma2.it>
9 9 Dmitri Kuznetsov <>
10 10 Jared Bunting <jared.bunting@peachjean.com>
11 11 Steve Romanow <slestak989@gmail.com>
12 12 Augosto Hermann <augusto.herrmann@planejamento.gov.br>
13 13 Ankit Solanki <ankit.solanki@gmail.com>
14 14 Liad Shani <liadff@gmail.com>
15 15 Les Peabody <lpeabody@gmail.com>
16 16 Jonas Oberschweiber <jonas.oberschweiber@d-velop.de>
17 17 Matt Zuba <matt.zuba@goodwillaz.org>
18 18 Aras Pranckevicius <aras@unity3d.com>
19 19 Tony Bussieres <t.bussieres@gmail.com>
20 20 Erwin Kroon <e.kroon@smartmetersolutions.nl>
21 nansenat16 <nansenat16@null.tw> No newline at end of file
21 nansenat16 <nansenat16@null.tw>
22 Vincent Duvert <vincent@duvert.net> No newline at end of file
@@ -1,152 +1,152 b''
1 1 from rhodecode.tests import *
2 2 from rhodecode.model.db import ChangesetComment, Notification, User, \
3 3 UserNotification
4 4
5 5
6 6 class TestChangeSetCommentsController(TestController):
7 7
8 8 def setUp(self):
9 9 for x in ChangesetComment.query().all():
10 10 self.Session.delete(x)
11 11 self.Session.commit()
12 12
13 13 for x in Notification.query().all():
14 14 self.Session.delete(x)
15 15 self.Session.commit()
16 16
17 17 def tearDown(self):
18 18 for x in ChangesetComment.query().all():
19 19 self.Session.delete(x)
20 20 self.Session.commit()
21 21
22 22 for x in Notification.query().all():
23 23 self.Session.delete(x)
24 24 self.Session.commit()
25 25
26 26 def test_create(self):
27 27 self.log_user()
28 28 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
29 29 text = u'CommentOnRevision'
30 30
31 31 params = {'text': text}
32 32 response = self.app.post(url(controller='changeset', action='comment',
33 33 repo_name=HG_REPO, revision=rev),
34 34 params=params)
35 35 # Test response...
36 36 self.assertEqual(response.status, '302 Found')
37 37 response.follow()
38 38
39 39 response = self.app.get(url(controller='changeset', action='index',
40 40 repo_name=HG_REPO, revision=rev))
41 41 # test DB
42 42 self.assertEqual(ChangesetComment.query().count(), 1)
43 self.assertTrue('''<div class="comments-number">%s '''
44 '''comment(s) (0 inline)</div>''' % 1 in response.body)
43 response.mustcontain('''<div class="comments-number">%s comment '''
44 '''(0 inline)</div>''' % 1)
45 45
46 46 self.assertEqual(Notification.query().count(), 1)
47 47 self.assertEqual(ChangesetComment.query().count(), 1)
48 48
49 49 notification = Notification.query().all()[0]
50 50
51 51 ID = ChangesetComment.query().first().comment_id
52 52 self.assertEqual(notification.type_,
53 53 Notification.TYPE_CHANGESET_COMMENT)
54 54 sbj = (u'/vcs_test_hg/changeset/'
55 55 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
56 56 print "%s vs %s" % (sbj, notification.subject)
57 57 self.assertTrue(sbj in notification.subject)
58 58
59 59 def test_create_inline(self):
60 60 self.log_user()
61 61 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
62 62 text = u'CommentOnRevision'
63 63 f_path = 'vcs/web/simplevcs/views/repository.py'
64 64 line = 'n1'
65 65
66 66 params = {'text': text, 'f_path': f_path, 'line': line}
67 67 response = self.app.post(url(controller='changeset', action='comment',
68 68 repo_name=HG_REPO, revision=rev),
69 69 params=params)
70 70 # Test response...
71 71 self.assertEqual(response.status, '302 Found')
72 72 response.follow()
73 73
74 74 response = self.app.get(url(controller='changeset', action='index',
75 75 repo_name=HG_REPO, revision=rev))
76 76 #test DB
77 77 self.assertEqual(ChangesetComment.query().count(), 1)
78 78 response.mustcontain(
79 '''<div class="comments-number">0 comment(s)'''
79 '''<div class="comments-number">0 comments'''
80 80 ''' (%s inline)</div>''' % 1
81 81 )
82 82 response.mustcontain(
83 83 '''<div style="display:none" class="inline-comment-placeholder" '''
84 84 '''path="vcs/web/simplevcs/views/repository.py" '''
85 85 '''target_id="vcswebsimplevcsviewsrepositorypy">'''
86 86 )
87 87
88 88 self.assertEqual(Notification.query().count(), 1)
89 89 self.assertEqual(ChangesetComment.query().count(), 1)
90 90
91 91 notification = Notification.query().all()[0]
92 92 ID = ChangesetComment.query().first().comment_id
93 93 self.assertEqual(notification.type_,
94 94 Notification.TYPE_CHANGESET_COMMENT)
95 95 sbj = (u'/vcs_test_hg/changeset/'
96 96 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
97 97 print "%s vs %s" % (sbj, notification.subject)
98 98 self.assertTrue(sbj in notification.subject)
99 99
100 100 def test_create_with_mention(self):
101 101 self.log_user()
102 102
103 103 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
104 104 text = u'@test_regular check CommentOnRevision'
105 105
106 106 params = {'text':text}
107 107 response = self.app.post(url(controller='changeset', action='comment',
108 108 repo_name=HG_REPO, revision=rev),
109 109 params=params)
110 110 # Test response...
111 111 self.assertEqual(response.status, '302 Found')
112 112 response.follow()
113 113
114 114 response = self.app.get(url(controller='changeset', action='index',
115 115 repo_name=HG_REPO, revision=rev))
116 116 # test DB
117 117 self.assertEqual(ChangesetComment.query().count(), 1)
118 self.assertTrue('''<div class="comments-number">%s '''
119 '''comment(s) (0 inline)</div>''' % 1 in response.body)
118 response.mustcontain('''<div class="comments-number">%s '''
119 '''comment (0 inline)</div>''' % 1)
120 120
121 121 self.assertEqual(Notification.query().count(), 2)
122 122 users = [x.user.username for x in UserNotification.query().all()]
123 123
124 124 # test_regular get's notification by @mention
125 125 self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
126 126
127 127 def test_delete(self):
128 128 self.log_user()
129 129 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
130 130 text = u'CommentOnRevision'
131 131
132 132 params = {'text': text}
133 133 response = self.app.post(url(controller='changeset', action='comment',
134 134 repo_name=HG_REPO, revision=rev),
135 135 params=params)
136 136
137 137 comments = ChangesetComment.query().all()
138 138 self.assertEqual(len(comments), 1)
139 139 comment_id = comments[0].comment_id
140 140
141 141 self.app.delete(url(controller='changeset',
142 142 action='delete_comment',
143 143 repo_name=HG_REPO,
144 144 comment_id=comment_id))
145 145
146 146 comments = ChangesetComment.query().all()
147 147 self.assertEqual(len(comments), 0)
148 148
149 149 response = self.app.get(url(controller='changeset', action='index',
150 150 repo_name=HG_REPO, revision=rev))
151 self.assertTrue('''<div class="comments-number">0 comment(s)'''
152 ''' (0 inline)</div>''' in response.body)
151 response.mustcontain('''<div class="comments-number">0 comments'''
152 ''' (0 inline)</div>''')
@@ -1,118 +1,131 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.tests.test_libs
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6
7 7 Package for testing various lib/helper functions in rhodecode
8 8
9 9 :created_on: Jun 9, 2011
10 10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26
26 import unittest
27 import datetime
28 from rhodecode.tests import *
27 29
28 import unittest
29 from rhodecode.tests import *
30 30
31 31 proto = 'http'
32 32 TEST_URLS = [
33 33 ('%s://127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
34 34 '%s://127.0.0.1' % proto),
35 35 ('%s://marcink@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
36 36 '%s://127.0.0.1' % proto),
37 37 ('%s://marcink:pass@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
38 38 '%s://127.0.0.1' % proto),
39 39 ('%s://127.0.0.1:8080' % proto, ['%s://' % proto, '127.0.0.1', '8080'],
40 40 '%s://127.0.0.1:8080' % proto),
41 41 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'],
42 42 '%s://domain.org' % proto),
43 43 ('%s://user:pass@domain.org:8080' % proto, ['%s://' % proto, 'domain.org',
44 44 '8080'],
45 45 '%s://domain.org:8080' % proto),
46 46 ]
47 47
48 48 proto = 'https'
49 49 TEST_URLS += [
50 50 ('%s://127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
51 51 '%s://127.0.0.1' % proto),
52 52 ('%s://marcink@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
53 53 '%s://127.0.0.1' % proto),
54 54 ('%s://marcink:pass@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
55 55 '%s://127.0.0.1' % proto),
56 56 ('%s://127.0.0.1:8080' % proto, ['%s://' % proto, '127.0.0.1', '8080'],
57 57 '%s://127.0.0.1:8080' % proto),
58 58 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'],
59 59 '%s://domain.org' % proto),
60 60 ('%s://user:pass@domain.org:8080' % proto, ['%s://' % proto, 'domain.org',
61 61 '8080'],
62 62 '%s://domain.org:8080' % proto),
63 63 ]
64 64
65 65
66 66 class TestLibs(unittest.TestCase):
67 67
68 68 def test_uri_filter(self):
69 69 from rhodecode.lib.utils2 import uri_filter
70 70
71 71 for url in TEST_URLS:
72 72 self.assertEqual(uri_filter(url[0]), url[1])
73 73
74 74 def test_credentials_filter(self):
75 75 from rhodecode.lib.utils2 import credentials_filter
76 76
77 77 for url in TEST_URLS:
78 78 self.assertEqual(credentials_filter(url[0]), url[2])
79 79
80 80 def test_str2bool(self):
81 81 from rhodecode.lib.utils2 import str2bool
82 82 test_cases = [
83 83 ('t', True),
84 84 ('true', True),
85 85 ('y', True),
86 86 ('yes', True),
87 87 ('on', True),
88 88 ('1', True),
89 89 ('Y', True),
90 90 ('yeS', True),
91 91 ('Y', True),
92 92 ('TRUE', True),
93 93 ('T', True),
94 94 ('False', False),
95 95 ('F', False),
96 96 ('FALSE', False),
97 97 ('0', False),
98 98 ('-1', False),
99 99 ('', False), ]
100 100
101 101 for case in test_cases:
102 102 self.assertEqual(str2bool(case[0]), case[1])
103 103
104 104 def test_mention_extractor(self):
105 105 from rhodecode.lib.utils2 import extract_mentioned_users
106 106 sample = (
107 107 "@first hi there @marcink here's my email marcin@email.com "
108 108 "@lukaszb check @one_more22 it pls @ ttwelve @D[] @one@two@three "
109 109 "@MARCIN @maRCiN @2one_more22 @john please see this http://org.pl "
110 110 "@marian.user just do it @marco-polo and next extract @marco_polo "
111 111 "user.dot hej ! not-needed maril@domain.org"
112 112 )
113 113
114 114 s = sorted([
115 115 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john',
116 116 'marian.user', 'marco-polo', 'marco_polo'
117 117 ], key=lambda k: k.lower())
118 118 self.assertEqual(s, extract_mentioned_users(sample))
119
120 def test_age(self):
121 from rhodecode.lib.utils2 import age
122 n = datetime.datetime.now()
123 delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs)
124 self.assertEqual(age(n), u'just now')
125 self.assertEqual(age(n - delt(seconds=1)), u'1 second ago')
126 self.assertEqual(age(n - delt(seconds=60 * 2)), u'2 minutes ago')
127 self.assertEqual(age(n - delt(hours=1)), u'1 hour ago')
128 self.assertEqual(age(n - delt(hours=24)), u'1 day ago')
129 self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago')
130 self.assertEqual(age(n - delt(hours=24 * 32)), u'1 month and 2 days ago')
131 self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago')
General Comments 0
You need to be logged in to leave comments. Login now