Show More
@@ -1,8 +1,20 b'' | |||||
1 | # List of modules to import when celery starts. |
|
1 | # List of modules to import when celery starts. | |
2 | import sys |
|
2 | import sys | |
3 | import os |
|
3 | import os | |
|
4 | import ConfigParser | |||
|
5 | ||||
|
6 | PYLONS_CONFIG_NAME = 'test.ini' | |||
|
7 | ||||
|
8 | root = os.getcwd() | |||
|
9 | config = ConfigParser.ConfigParser({'here':root}) | |||
|
10 | config.read('%s/%s' % (root, PYLONS_CONFIG_NAME)) | |||
|
11 | PYLONS_CONFIG = config | |||
|
12 | ||||
|
13 | ||||
|
14 | print config.items('app:main') | |||
|
15 | ||||
4 | sys.path.append(os.getcwd()) |
|
16 | sys.path.append(os.getcwd()) | |
5 |
CELERY_IMPORTS = ("pylons_app.lib.celerylib.tasks", |
|
17 | CELERY_IMPORTS = ("pylons_app.lib.celerylib.tasks",) | |
6 |
|
18 | |||
7 | ## Result store settings. |
|
19 | ## Result store settings. | |
8 | CELERY_RESULT_BACKEND = "database" |
|
20 | CELERY_RESULT_BACKEND = "database" | |
@@ -30,4 +42,4 b' CELERYD_MAX_TASKS_PER_CHILD = 1' | |||||
30 | #CELERY_ALWAYS_EAGER = True |
|
42 | #CELERY_ALWAYS_EAGER = True | |
31 | #rabbitmqctl add_user rabbitmq qweqwe |
|
43 | #rabbitmqctl add_user rabbitmq qweqwe | |
32 | #rabbitmqctl add_vhost rabbitmqhost |
|
44 | #rabbitmqctl add_vhost rabbitmqhost | |
33 | #rabbitmqctl set_permissions -p rabbitmqhost rabbitmq ".*" ".*" ".*" No newline at end of file |
|
45 | #rabbitmqctl set_permissions -p rabbitmqhost rabbitmq ".*" ".*" ".*" |
@@ -1,7 +1,7 b'' | |||||
1 | from celery.decorators import task |
|
1 | from celery.decorators import task | |
2 | from celery.task.sets import subtask |
|
2 | from celery.task.sets import subtask | |
|
3 | from celeryconfig import PYLONS_CONFIG as config | |||
3 | from datetime import datetime, timedelta |
|
4 | from datetime import datetime, timedelta | |
4 | from os.path import dirname as dn |
|
|||
5 | from pylons.i18n.translation import _ |
|
5 | from pylons.i18n.translation import _ | |
6 | from pylons_app.lib.celerylib import run_task |
|
6 | from pylons_app.lib.celerylib import run_task | |
7 | from pylons_app.lib.helpers import person |
|
7 | from pylons_app.lib.helpers import person | |
@@ -9,16 +9,9 b' from pylons_app.lib.smtp_mailer import S' | |||||
9 | from pylons_app.lib.utils import OrderedDict |
|
9 | from pylons_app.lib.utils import OrderedDict | |
10 | from time import mktime |
|
10 | from time import mktime | |
11 | from vcs.backends.hg import MercurialRepository |
|
11 | from vcs.backends.hg import MercurialRepository | |
12 | import ConfigParser |
|
|||
13 | import calendar |
|
12 | import calendar | |
14 | import os |
|
|||
15 | import traceback |
|
13 | import traceback | |
16 |
|
14 | |||
17 |
|
||||
18 | root = dn(dn(dn(dn(os.path.realpath(__file__))))) |
|
|||
19 | config = ConfigParser.ConfigParser({'here':root}) |
|
|||
20 | config.read('%s/development.ini' % root) |
|
|||
21 |
|
||||
22 | __all__ = ['whoosh_index', 'get_commits_stats', |
|
15 | __all__ = ['whoosh_index', 'get_commits_stats', | |
23 | 'reset_user_password', 'send_email'] |
|
16 | 'reset_user_password', 'send_email'] | |
24 |
|
17 | |||
@@ -91,7 +84,7 b' def whoosh_index(repo_location, full_ind' | |||||
91 | def get_commits_stats(repo): |
|
84 | def get_commits_stats(repo): | |
92 | log = get_commits_stats.get_logger() |
|
85 | log = get_commits_stats.get_logger() | |
93 | aggregate = OrderedDict() |
|
86 | aggregate = OrderedDict() | |
94 | repos_path = get_hg_ui_settings()['paths_root_path'].replace('*','') |
|
87 | repos_path = get_hg_ui_settings()['paths_root_path'].replace('*', '') | |
95 | repo = MercurialRepository(repos_path + repo) |
|
88 | repo = MercurialRepository(repos_path + repo) | |
96 | #graph range |
|
89 | #graph range | |
97 | td = datetime.today() + timedelta(days=1) |
|
90 | td = datetime.today() + timedelta(days=1) | |
@@ -205,7 +198,7 b' def send_email(recipients, subject, body' | |||||
205 | ssl = False |
|
198 | ssl = False | |
206 |
|
199 | |||
207 | try: |
|
200 | try: | |
208 |
m = SmtpMailer(mail_from, user, passwd, mail_server, |
|
201 | m = SmtpMailer(mail_from, user, passwd, mail_server, | |
209 | mail_port, ssl, tls) |
|
202 | mail_port, ssl, tls) | |
210 | m.send(recipients, subject, body) |
|
203 | m.send(recipients, subject, body) | |
211 | except: |
|
204 | except: |
@@ -33,19 +33,30 b' project_path = dn(dn(dn(dn(os.path.realp' | |||||
33 | sys.path.append(project_path) |
|
33 | sys.path.append(project_path) | |
34 |
|
34 | |||
35 | from pidlock import LockHeld, DaemonLock |
|
35 | from pidlock import LockHeld, DaemonLock | |
36 | import traceback |
|
|||
37 | from pylons_app.config.environment import load_environment |
|
|||
38 | from pylons_app.model.hg_model import HgModel |
|
36 | from pylons_app.model.hg_model import HgModel | |
39 | from pylons_app.lib.helpers import safe_unicode |
|
37 | from pylons_app.lib.helpers import safe_unicode | |
40 | from whoosh.index import create_in, open_dir |
|
38 | from whoosh.index import create_in, open_dir | |
41 | from shutil import rmtree |
|
39 | from shutil import rmtree | |
42 |
from pylons_app.lib.indexers import |
|
40 | from pylons_app.lib.indexers import INDEX_EXTENSIONS, IDX_LOCATION, SCHEMA, IDX_NAME | |
43 | SCHEMA, IDX_NAME |
|
|||
44 |
|
41 | |||
45 | import logging |
|
42 | import logging | |
46 | import logging.config |
|
43 | ||
47 | logging.config.fileConfig(jn(project_path, 'development.ini')) |
|
|||
48 | log = logging.getLogger('whooshIndexer') |
|
44 | log = logging.getLogger('whooshIndexer') | |
|
45 | # create logger | |||
|
46 | log.setLevel(logging.DEBUG) | |||
|
47 | ||||
|
48 | # create console handler and set level to debug | |||
|
49 | ch = logging.StreamHandler() | |||
|
50 | ch.setLevel(logging.DEBUG) | |||
|
51 | ||||
|
52 | # create formatter | |||
|
53 | formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | |||
|
54 | ||||
|
55 | # add formatter to ch | |||
|
56 | ch.setFormatter(formatter) | |||
|
57 | ||||
|
58 | # add ch to logger | |||
|
59 | log.addHandler(ch) | |||
49 |
|
60 | |||
50 | def scan_paths(root_location): |
|
61 | def scan_paths(root_location): | |
51 | return HgModel.repo_scan('/', root_location, None, True) |
|
62 | return HgModel.repo_scan('/', root_location, None, True) | |
@@ -221,6 +232,7 b' if __name__ == "__main__":' | |||||
221 | WhooshIndexingDaemon(repo_location=repo_location)\ |
|
232 | WhooshIndexingDaemon(repo_location=repo_location)\ | |
222 | .run(full_index=full_index) |
|
233 | .run(full_index=full_index) | |
223 | l.release() |
|
234 | l.release() | |
|
235 | reload(logging) | |||
224 | except LockHeld: |
|
236 | except LockHeld: | |
225 | sys.exit(1) |
|
237 | sys.exit(1) | |
226 |
|
238 |
@@ -16,7 +16,9 b' from routes.util import URLGenerator' | |||||
16 | from webtest import TestApp |
|
16 | from webtest import TestApp | |
17 | import os |
|
17 | import os | |
18 | from pylons_app.model import meta |
|
18 | from pylons_app.model import meta | |
|
19 | from pylons_app.lib.indexers import IDX_LOCATION | |||
19 | import logging |
|
20 | import logging | |
|
21 | import shutil | |||
20 | log = logging.getLogger(__name__) |
|
22 | log = logging.getLogger(__name__) | |
21 |
|
23 | |||
22 | import pylons.test |
|
24 | import pylons.test | |
@@ -25,6 +27,23 b' import pylons.test' | |||||
25 |
|
27 | |||
26 | # Invoke websetup with the current config file |
|
28 | # Invoke websetup with the current config file | |
27 | #SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) |
|
29 | #SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) | |
|
30 | def create_index(repo_location, full_index): | |||
|
31 | from pylons_app.lib.indexers import daemon | |||
|
32 | from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon | |||
|
33 | from pylons_app.lib.indexers.pidlock import DaemonLock, LockHeld | |||
|
34 | ||||
|
35 | try: | |||
|
36 | l = DaemonLock() | |||
|
37 | WhooshIndexingDaemon(repo_location=repo_location)\ | |||
|
38 | .run(full_index=full_index) | |||
|
39 | l.release() | |||
|
40 | except LockHeld: | |||
|
41 | pass | |||
|
42 | ||||
|
43 | if os.path.exists(IDX_LOCATION): | |||
|
44 | shutil.rmtree(IDX_LOCATION) | |||
|
45 | ||||
|
46 | create_index('/tmp/*', True) | |||
28 |
|
47 | |||
29 | environ = {} |
|
48 | environ = {} | |
30 |
|
49 | |||
@@ -36,6 +55,7 b' class TestController(TestCase):' | |||||
36 | self.app = TestApp(wsgiapp) |
|
55 | self.app = TestApp(wsgiapp) | |
37 | url._push_object(URLGenerator(config['routes.map'], environ)) |
|
56 | url._push_object(URLGenerator(config['routes.map'], environ)) | |
38 | self.sa = meta.Session |
|
57 | self.sa = meta.Session | |
|
58 | ||||
39 | TestCase.__init__(self, *args, **kwargs) |
|
59 | TestCase.__init__(self, *args, **kwargs) | |
40 |
|
60 | |||
41 |
|
61 | |||
@@ -46,4 +66,5 b' class TestController(TestCase):' | |||||
46 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
|
66 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | |
47 | assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' |
|
67 | assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' | |
48 | return response.follow() |
|
68 | return response.follow() | |
49 | No newline at end of file |
|
69 | ||
|
70 |
@@ -84,7 +84,7 b' class TestLoginController(TestController' | |||||
84 | def test_register_ok(self): |
|
84 | def test_register_ok(self): | |
85 | username = 'test_regular4' |
|
85 | username = 'test_regular4' | |
86 | password = 'qweqwe' |
|
86 | password = 'qweqwe' | |
87 |
email = 'marcin@ |
|
87 | email = 'marcin@test.com' | |
88 | name = 'testname' |
|
88 | name = 'testname' | |
89 | lastname = 'testlastname' |
|
89 | lastname = 'testlastname' | |
90 |
|
90 | |||
@@ -100,7 +100,7 b' class TestLoginController(TestController' | |||||
100 |
|
100 | |||
101 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() |
|
101 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() | |
102 | assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) |
|
102 | assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) | |
103 | assert check_password(password,ret.password) == True , 'password mismatch' |
|
103 | assert check_password(password, ret.password) == True , 'password mismatch' | |
104 | assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) |
|
104 | assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) | |
105 | assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) |
|
105 | assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) | |
106 | assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) |
|
106 | assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) | |
@@ -108,9 +108,9 b' class TestLoginController(TestController' | |||||
108 |
|
108 | |||
109 | def test_forgot_password_wrong_mail(self): |
|
109 | def test_forgot_password_wrong_mail(self): | |
110 | response = self.app.post(url(controller='login', action='password_reset'), |
|
110 | response = self.app.post(url(controller='login', action='password_reset'), | |
111 | {'email':'marcin@wrongmail.org',}) |
|
111 | {'email':'marcin@wrongmail.org', }) | |
112 |
|
112 | |||
113 | assert "That e-mail address doesn't exist" in response.body,'Missing error message about wrong email' |
|
113 | assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' | |
114 |
|
114 | |||
115 | def test_forgot_password(self): |
|
115 | def test_forgot_password(self): | |
116 | response = self.app.get(url(controller='login', action='password_reset')) |
|
116 | response = self.app.get(url(controller='login', action='password_reset')) | |
@@ -130,7 +130,7 b' class TestLoginController(TestController' | |||||
130 | 'lastname':lastname}) |
|
130 | 'lastname':lastname}) | |
131 | #register new user for email test |
|
131 | #register new user for email test | |
132 | response = self.app.post(url(controller='login', action='password_reset'), |
|
132 | response = self.app.post(url(controller='login', action='password_reset'), | |
133 | {'email':email,}) |
|
133 | {'email':email, }) | |
134 | print response.session['flash'] |
|
134 | print response.session['flash'] | |
135 | assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' |
|
135 | assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' | |
136 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' |
|
136 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' |
@@ -9,7 +9,7 b' class TestSearchController(TestControlle' | |||||
9 | self.log_user() |
|
9 | self.log_user() | |
10 | response = self.app.get(url(controller='search', action='index')) |
|
10 | response = self.app.get(url(controller='search', action='index')) | |
11 | print response.body |
|
11 | print response.body | |
12 | assert 'class="small" id="q" name="q" type="text"' in response.body,'Search box content error' |
|
12 | assert 'class="small" id="q" name="q" type="text"' in response.body, 'Search box content error' | |
13 | # Test response... |
|
13 | # Test response... | |
14 |
|
14 | |||
15 | def test_empty_search(self): |
|
15 | def test_empty_search(self): | |
@@ -18,12 +18,21 b' class TestSearchController(TestControlle' | |||||
18 | raise SkipTest('skipped due to existing index') |
|
18 | raise SkipTest('skipped due to existing index') | |
19 | else: |
|
19 | else: | |
20 | self.log_user() |
|
20 | self.log_user() | |
21 | response = self.app.get(url(controller='search', action='index'),{'q':'vcs_test'}) |
|
21 | response = self.app.get(url(controller='search', action='index'), {'q':'vcs_test'}) | |
22 | assert 'There is no index to search in. Please run whoosh indexer' in response.body,'No error message about empty index' |
|
22 | assert 'There is no index to search in. Please run whoosh indexer' in response.body, 'No error message about empty index' | |
23 |
|
23 | |||
24 | def test_normal_search(self): |
|
24 | def test_normal_search(self): | |
25 | self.log_user() |
|
25 | self.log_user() | |
26 |
response = self.app.get(url(controller='search', action='index'),{'q':'def |
|
26 | response = self.app.get(url(controller='search', action='index'), {'q':'def repo'}) | |
27 | print response.body |
|
27 | print response.body | |
28 |
assert ' |
|
28 | assert '10 results' in response.body, 'no message about proper search results' | |
|
29 | assert 'Permission denied' not in response.body, 'Wrong permissions settings for that repo and user' | |||
29 |
|
30 | |||
|
31 | ||||
|
32 | def test_repo_search(self): | |||
|
33 | self.log_user() | |||
|
34 | response = self.app.get(url(controller='search', action='index'), {'q':'repository:vcs_test def test'}) | |||
|
35 | print response.body | |||
|
36 | assert '4 results' in response.body, 'no message about proper search results' | |||
|
37 | assert 'Permission denied' not in response.body, 'Wrong permissions settings for that repo and user' | |||
|
38 |
General Comments 0
You need to be logged in to leave comments.
Login now