Show More
@@ -0,0 +1,7 b'' | |||
|
1 | <link rel="import" href="../../../../../../bower_components/polymer/polymer.html"> | |
|
2 | <dom-module id="rhodecode-legacy-js"> | |
|
3 | <template> | |
|
4 | <script src="../../../scripts.js"></script> | |
|
5 | </template> | |
|
6 | <script src="rhodecode-legacy-js.js"></script> | |
|
7 | </dom-module> |
@@ -1,8 +1,9 b'' | |||
|
1 | 1 | <!-- required for stamped out templates that might use common elements --> |
|
2 | <link rel="import" href="rhodecode-legacy-js/rhodecode-legacy-js.html"> | |
|
2 | 3 | <link rel="import" href="../../../../../bower_components/iron-ajax/iron-ajax.html"> |
|
3 | 4 | <link rel="import" href="shared-styles.html"> |
|
4 | 5 | <link rel="import" href="channelstream-connection/channelstream-connection.html"> |
|
5 | 6 | <link rel="import" href="rhodecode-toast/rhodecode-toast.html"> |
|
6 | 7 | <link rel="import" href="rhodecode-toggle/rhodecode-toggle.html"> |
|
7 | 8 | <link rel="import" href="rhodecode-unsafe-html/rhodecode-unsafe-html.html"> |
|
8 | <link rel="import" href="rhodecode-app/rhodecode-app.html"> No newline at end of file | |
|
9 | <link rel="import" href="rhodecode-app/rhodecode-app.html"> |
@@ -1,174 +1,173 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | <!DOCTYPE html> |
|
3 | 3 | |
|
4 | 4 | <% |
|
5 | 5 | c.template_context['repo_name'] = getattr(c, 'repo_name', '') |
|
6 | 6 | |
|
7 | 7 | if hasattr(c, 'rhodecode_db_repo'): |
|
8 | 8 | c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type |
|
9 | 9 | c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1] |
|
10 | 10 | |
|
11 | 11 | if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id: |
|
12 | 12 | c.template_context['rhodecode_user']['username'] = c.rhodecode_user.username |
|
13 | 13 | c.template_context['rhodecode_user']['email'] = c.rhodecode_user.email |
|
14 | 14 | c.template_context['rhodecode_user']['notification_status'] = c.rhodecode_user.get_instance().user_data.get('notification_status', True) |
|
15 | 15 | |
|
16 | 16 | c.template_context['visual']['default_renderer'] = h.get_visual_attr(c, 'default_renderer') |
|
17 | 17 | %> |
|
18 | 18 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|
19 | 19 | <head> |
|
20 | 20 | <script src="${h.asset('js/vendors/webcomponentsjs/webcomponents-lite.min.js', ver=c.rhodecode_version_hash)}"></script> |
|
21 | 21 | <link rel="import" href="${h.asset('js/rhodecode-components.html', ver=c.rhodecode_version_hash)}"> |
|
22 | 22 | <title>${self.title()}</title> |
|
23 | 23 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> |
|
24 | 24 | <%def name="robots()"> |
|
25 | 25 | <meta name="robots" content="index, nofollow"/> |
|
26 | 26 | </%def> |
|
27 | 27 | ${self.robots()} |
|
28 | 28 | <link rel="icon" href="${h.asset('images/favicon.ico', ver=c.rhodecode_version_hash)}" sizes="16x16 32x32" type="image/png" /> |
|
29 | 29 | |
|
30 | 30 | ## CSS definitions |
|
31 | 31 | <%def name="css()"> |
|
32 | 32 | <link rel="stylesheet" type="text/css" href="${h.asset('css/style.css', ver=c.rhodecode_version_hash)}" media="screen"/> |
|
33 | 33 | <!--[if lt IE 9]> |
|
34 | 34 | <link rel="stylesheet" type="text/css" href="${h.asset('css/ie.css', ver=c.rhodecode_version_hash)}" media="screen"/> |
|
35 | 35 | <![endif]--> |
|
36 | 36 | ## EXTRA FOR CSS |
|
37 | 37 | ${self.css_extra()} |
|
38 | 38 | </%def> |
|
39 | 39 | ## CSS EXTRA - optionally inject some extra CSS stuff needed for specific websites |
|
40 | 40 | <%def name="css_extra()"> |
|
41 | 41 | </%def> |
|
42 | 42 | |
|
43 | 43 | ${self.css()} |
|
44 | 44 | |
|
45 | 45 | ## JAVASCRIPT |
|
46 | 46 | <%def name="js()"> |
|
47 | 47 | <script> |
|
48 | 48 | // setup Polymer options |
|
49 | 49 | window.Polymer = {lazyRegister: true, dom: 'shadow'}; |
|
50 | 50 | |
|
51 | 51 | // Load webcomponentsjs polyfill if browser does not support native Web Components |
|
52 | 52 | (function() { |
|
53 | 53 | 'use strict'; |
|
54 | 54 | var onload = function() { |
|
55 | 55 | // For native Imports, manually fire WebComponentsReady so user code |
|
56 | 56 | // can use the same code path for native and polyfill'd imports. |
|
57 | 57 | if (!window.HTMLImports) { |
|
58 | 58 | document.dispatchEvent( |
|
59 | 59 | new CustomEvent('WebComponentsReady', {bubbles: true}) |
|
60 | 60 | ); |
|
61 | 61 | } |
|
62 | 62 | }; |
|
63 | 63 | var webComponentsSupported = ( |
|
64 | 64 | 'registerElement' in document |
|
65 | 65 | && 'import' in document.createElement('link') |
|
66 | 66 | && 'content' in document.createElement('template') |
|
67 | 67 | ); |
|
68 | 68 | if (!webComponentsSupported) { |
|
69 | 69 | } else { |
|
70 | 70 | onload(); |
|
71 | 71 | } |
|
72 | 72 | })(); |
|
73 | 73 | </script> |
|
74 | 74 | |
|
75 | 75 | <script src="${h.asset('js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script> |
|
76 | 76 | <script type="text/javascript"> |
|
77 | 77 | // register templateContext to pass template variables to JS |
|
78 | 78 | var templateContext = ${h.json.dumps(c.template_context)|n}; |
|
79 | 79 | |
|
80 | 80 | var REPO_NAME = "${getattr(c, 'repo_name', '')}"; |
|
81 | 81 | %if hasattr(c, 'rhodecode_db_repo'): |
|
82 | 82 | var REPO_LANDING_REV = '${c.rhodecode_db_repo.landing_rev[1]}'; |
|
83 | 83 | var REPO_TYPE = '${c.rhodecode_db_repo.repo_type}'; |
|
84 | 84 | %else: |
|
85 | 85 | var REPO_LANDING_REV = ''; |
|
86 | 86 | var REPO_TYPE = ''; |
|
87 | 87 | %endif |
|
88 | 88 | var APPLICATION_URL = "${h.url('home').rstrip('/')}"; |
|
89 | 89 | var ASSET_URL = "${h.asset('')}"; |
|
90 | 90 | var DEFAULT_RENDERER = "${h.get_visual_attr(c, 'default_renderer')}"; |
|
91 | 91 | var CSRF_TOKEN = "${getattr(c, 'csrf_token', '')}"; |
|
92 | 92 | % if getattr(c, 'rhodecode_user', None): |
|
93 | 93 | var USER = {name:'${c.rhodecode_user.username}'}; |
|
94 | 94 | % else: |
|
95 | 95 | var USER = {name:null}; |
|
96 | 96 | % endif |
|
97 | 97 | |
|
98 | 98 | var APPENLIGHT = { |
|
99 | 99 | enabled: ${'true' if getattr(c, 'appenlight_enabled', False) else 'false'}, |
|
100 | 100 | key: '${getattr(c, "appenlight_api_public_key", "")}', |
|
101 | 101 | % if getattr(c, 'appenlight_server_url', None): |
|
102 | 102 | serverUrl: '${getattr(c, "appenlight_server_url", "")}', |
|
103 | 103 | % endif |
|
104 | 104 | requestInfo: { |
|
105 | 105 | % if getattr(c, 'rhodecode_user', None): |
|
106 | 106 | ip: '${c.rhodecode_user.ip_addr}', |
|
107 | 107 | username: '${c.rhodecode_user.username}' |
|
108 | 108 | % endif |
|
109 | 109 | }, |
|
110 | 110 | tags: { |
|
111 | 111 | rhodecode_version: '${c.rhodecode_version}', |
|
112 | 112 | rhodecode_edition: '${c.rhodecode_edition}' |
|
113 | 113 | } |
|
114 | 114 | }; |
|
115 | 115 | </script> |
|
116 | 116 | <%include file="/base/plugins_base.html"/> |
|
117 | 117 | <!--[if lt IE 9]> |
|
118 | 118 | <script language="javascript" type="text/javascript" src="${h.asset('js/excanvas.min.js')}"></script> |
|
119 | 119 | <![endif]--> |
|
120 | 120 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script> |
|
121 | 121 | <script> var alertMessagePayloads = ${h.flash.json_alerts()|n}; </script> |
|
122 | <script language="javascript" type="text/javascript" src="${h.asset('js/scripts.js', ver=c.rhodecode_version_hash)}"></script> | |
|
123 | 122 | ## avoide escaping the %N |
|
123 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode-components.js', ver=c.rhodecode_version_hash)}"></script> | |
|
124 | 124 | <script>CodeMirror.modeURL = "${h.asset('') + 'js/mode/%N/%N.js?ver='+c.rhodecode_version_hash}";</script> |
|
125 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode-components.js', ver=c.rhodecode_version_hash)}"></script> | |
|
126 | 125 | |
|
127 | 126 | |
|
128 | 127 | ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates |
|
129 | 128 | ${self.js_extra()} |
|
130 | 129 | |
|
131 | 130 | <script type="text/javascript"> |
|
132 | 131 | $(document).ready(function(){ |
|
133 | 132 | show_more_event(); |
|
134 | 133 | timeagoActivate(); |
|
135 | 134 | }) |
|
136 | 135 | </script> |
|
137 | 136 | |
|
138 | 137 | </%def> |
|
139 | 138 | |
|
140 | 139 | ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates |
|
141 | 140 | <%def name="js_extra()"></%def> |
|
142 | 141 | ${self.js()} |
|
143 | 142 | |
|
144 | 143 | <%def name="head_extra()"></%def> |
|
145 | 144 | ${self.head_extra()} |
|
146 | 145 | ## extra stuff |
|
147 | 146 | %if c.pre_code: |
|
148 | 147 | ${c.pre_code|n} |
|
149 | 148 | %endif |
|
150 | 149 | </head> |
|
151 | 150 | <body id="body"> |
|
152 | 151 | <noscript> |
|
153 | 152 | <div class="noscript-error"> |
|
154 | 153 | ${_('Please enable JavaScript to use RhodeCode Enterprise')} |
|
155 | 154 | </div> |
|
156 | 155 | </noscript> |
|
157 | 156 | ## IE hacks |
|
158 | 157 | <!--[if IE 7]> |
|
159 | 158 | <script>$(document.body).addClass('ie7')</script> |
|
160 | 159 | <![endif]--> |
|
161 | 160 | <!--[if IE 8]> |
|
162 | 161 | <script>$(document.body).addClass('ie8')</script> |
|
163 | 162 | <![endif]--> |
|
164 | 163 | <!--[if IE 9]> |
|
165 | 164 | <script>$(document.body).addClass('ie9')</script> |
|
166 | 165 | <![endif]--> |
|
167 | 166 | |
|
168 | 167 | ${next.body()} |
|
169 | 168 | %if c.post_code: |
|
170 | 169 | ${c.post_code|n} |
|
171 | 170 | %endif |
|
172 | 171 | <rhodecode-app></rhodecode-app> |
|
173 | 172 | </body> |
|
174 | 173 | </html> |
@@ -1,390 +1,390 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import json |
|
22 | 22 | |
|
23 | 23 | from mock import patch |
|
24 | 24 | import pytest |
|
25 | 25 | from pylons import tmpl_context as c |
|
26 | 26 | |
|
27 | 27 | import rhodecode |
|
28 | 28 | from rhodecode.lib.utils import map_groups |
|
29 | 29 | from rhodecode.model.db import Repository, User, RepoGroup |
|
30 | 30 | from rhodecode.model.meta import Session |
|
31 | 31 | from rhodecode.model.repo import RepoModel |
|
32 | 32 | from rhodecode.model.repo_group import RepoGroupModel |
|
33 | 33 | from rhodecode.model.settings import SettingsModel |
|
34 | 34 | from rhodecode.tests import TestController, url, TEST_USER_ADMIN_LOGIN |
|
35 | 35 | from rhodecode.tests.fixture import Fixture |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | fixture = Fixture() |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | class TestHomeController(TestController): |
|
42 | 42 | |
|
43 | 43 | def test_index(self): |
|
44 | 44 | self.log_user() |
|
45 | 45 | response = self.app.get(url(controller='home', action='index')) |
|
46 | 46 | # if global permission is set |
|
47 | 47 | response.mustcontain('Add Repository') |
|
48 | 48 | |
|
49 | 49 | # search for objects inside the JavaScript JSON |
|
50 | 50 | for repo in Repository.getAll(): |
|
51 | 51 | response.mustcontain('"name_raw": "%s"' % repo.repo_name) |
|
52 | 52 | |
|
53 | 53 | def test_index_contains_statics_with_ver(self): |
|
54 | 54 | self.log_user() |
|
55 | 55 | response = self.app.get(url(controller='home', action='index')) |
|
56 | 56 | |
|
57 | 57 | rhodecode_version_hash = c.rhodecode_version_hash |
|
58 | 58 | response.mustcontain('style.css?ver={0}'.format(rhodecode_version_hash)) |
|
59 |
response.mustcontain(' |
|
|
59 | response.mustcontain('rhodecode-components.js?ver={0}'.format(rhodecode_version_hash)) | |
|
60 | 60 | |
|
61 | 61 | def test_index_contains_backend_specific_details(self, backend): |
|
62 | 62 | self.log_user() |
|
63 | 63 | response = self.app.get(url(controller='home', action='index')) |
|
64 | 64 | tip = backend.repo.get_commit().raw_id |
|
65 | 65 | |
|
66 | 66 | # html in javascript variable: |
|
67 | 67 | response.mustcontain(r'<i class=\"icon-%s\"' % (backend.alias, )) |
|
68 | 68 | response.mustcontain(r'href=\"/%s\"' % (backend.repo_name, )) |
|
69 | 69 | |
|
70 | 70 | response.mustcontain("""/%s/changeset/%s""" % (backend.repo_name, tip)) |
|
71 | 71 | response.mustcontain("""Added a symlink""") |
|
72 | 72 | |
|
73 | 73 | def test_index_with_anonymous_access_disabled(self): |
|
74 | 74 | with fixture.anon_access(False): |
|
75 | 75 | response = self.app.get(url(controller='home', action='index'), |
|
76 | 76 | status=302) |
|
77 | 77 | assert 'login' in response.location |
|
78 | 78 | |
|
79 | 79 | def test_index_page_on_groups(self, autologin_user, repo_group): |
|
80 | 80 | response = self.app.get(url('repo_group_home', group_name='gr1')) |
|
81 | 81 | response.mustcontain("gr1/repo_in_group") |
|
82 | 82 | |
|
83 | 83 | def test_index_page_on_group_with_trailing_slash( |
|
84 | 84 | self, autologin_user, repo_group): |
|
85 | 85 | response = self.app.get(url('repo_group_home', group_name='gr1') + '/') |
|
86 | 86 | response.mustcontain("gr1/repo_in_group") |
|
87 | 87 | |
|
88 | 88 | @pytest.fixture(scope='class') |
|
89 | 89 | def repo_group(self, request): |
|
90 | 90 | gr = fixture.create_repo_group('gr1') |
|
91 | 91 | fixture.create_repo(name='gr1/repo_in_group', repo_group=gr) |
|
92 | 92 | |
|
93 | 93 | @request.addfinalizer |
|
94 | 94 | def cleanup(): |
|
95 | 95 | RepoModel().delete('gr1/repo_in_group') |
|
96 | 96 | RepoGroupModel().delete(repo_group='gr1', force_delete=True) |
|
97 | 97 | Session().commit() |
|
98 | 98 | |
|
99 | 99 | def test_index_with_name_with_tags(self, autologin_user): |
|
100 | 100 | user = User.get_by_username('test_admin') |
|
101 | 101 | user.name = '<img src="/image1" onload="alert(\'Hello, World!\');">' |
|
102 | 102 | user.lastname = ( |
|
103 | 103 | '<img src="/image2" onload="alert(\'Hello, World!\');">') |
|
104 | 104 | Session().add(user) |
|
105 | 105 | Session().commit() |
|
106 | 106 | |
|
107 | 107 | response = self.app.get(url(controller='home', action='index')) |
|
108 | 108 | response.mustcontain( |
|
109 | 109 | '<img src="/image1" onload="' |
|
110 | 110 | 'alert('Hello, World!');">') |
|
111 | 111 | response.mustcontain( |
|
112 | 112 | '<img src="/image2" onload="' |
|
113 | 113 | 'alert('Hello, World!');">') |
|
114 | 114 | |
|
115 | 115 | @pytest.mark.parametrize("name, state", [ |
|
116 | 116 | ('Disabled', False), |
|
117 | 117 | ('Enabled', True), |
|
118 | 118 | ]) |
|
119 | 119 | def test_index_show_version(self, autologin_user, name, state): |
|
120 | 120 | version_string = 'RhodeCode Enterprise %s' % rhodecode.__version__ |
|
121 | 121 | |
|
122 | 122 | sett = SettingsModel().create_or_update_setting( |
|
123 | 123 | 'show_version', state, 'bool') |
|
124 | 124 | Session().add(sett) |
|
125 | 125 | Session().commit() |
|
126 | 126 | SettingsModel().invalidate_settings_cache() |
|
127 | 127 | |
|
128 | 128 | response = self.app.get(url(controller='home', action='index')) |
|
129 | 129 | if state is True: |
|
130 | 130 | response.mustcontain(version_string) |
|
131 | 131 | if state is False: |
|
132 | 132 | response.mustcontain(no=[version_string]) |
|
133 | 133 | |
|
134 | 134 | |
|
135 | 135 | class TestUserAutocompleteData(TestController): |
|
136 | 136 | def test_returns_list_of_users(self, user_util): |
|
137 | 137 | self.log_user() |
|
138 | 138 | user = user_util.create_user(is_active=True) |
|
139 | 139 | user_name = user.username |
|
140 | 140 | response = self.app.get( |
|
141 | 141 | url(controller='home', action='user_autocomplete_data'), |
|
142 | 142 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
143 | 143 | result = json.loads(response.body) |
|
144 | 144 | values = [suggestion['value'] for suggestion in result['suggestions']] |
|
145 | 145 | assert user_name in values |
|
146 | 146 | |
|
147 | 147 | def test_returns_inactive_users_when_active_flag_sent(self, user_util): |
|
148 | 148 | self.log_user() |
|
149 | 149 | user = user_util.create_user(is_active=False) |
|
150 | 150 | user_name = user.username |
|
151 | 151 | response = self.app.get( |
|
152 | 152 | url(controller='home', action='user_autocomplete_data', |
|
153 | 153 | user_groups='true', active='0'), |
|
154 | 154 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
155 | 155 | result = json.loads(response.body) |
|
156 | 156 | values = [suggestion['value'] for suggestion in result['suggestions']] |
|
157 | 157 | assert user_name in values |
|
158 | 158 | |
|
159 | 159 | def test_returns_groups_when_user_groups_sent(self, user_util): |
|
160 | 160 | self.log_user() |
|
161 | 161 | group = user_util.create_user_group(user_groups_active=True) |
|
162 | 162 | group_name = group.users_group_name |
|
163 | 163 | response = self.app.get( |
|
164 | 164 | url(controller='home', action='user_autocomplete_data', |
|
165 | 165 | user_groups='true'), |
|
166 | 166 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
167 | 167 | result = json.loads(response.body) |
|
168 | 168 | values = [suggestion['value'] for suggestion in result['suggestions']] |
|
169 | 169 | assert group_name in values |
|
170 | 170 | |
|
171 | 171 | def test_result_is_limited_when_query_is_sent(self): |
|
172 | 172 | self.log_user() |
|
173 | 173 | fake_result = [ |
|
174 | 174 | { |
|
175 | 175 | 'first_name': 'John', |
|
176 | 176 | 'value_display': 'hello{} (John Smith)'.format(i), |
|
177 | 177 | 'icon_link': '/images/user14.png', |
|
178 | 178 | 'value': 'hello{}'.format(i), |
|
179 | 179 | 'last_name': 'Smith', |
|
180 | 180 | 'username': 'hello{}'.format(i), |
|
181 | 181 | 'id': i, |
|
182 | 182 | 'value_type': u'user' |
|
183 | 183 | } |
|
184 | 184 | for i in range(10) |
|
185 | 185 | ] |
|
186 | 186 | users_patcher = patch.object( |
|
187 | 187 | RepoModel, 'get_users', return_value=fake_result) |
|
188 | 188 | groups_patcher = patch.object( |
|
189 | 189 | RepoModel, 'get_user_groups', return_value=fake_result) |
|
190 | 190 | |
|
191 | 191 | query = 'hello' |
|
192 | 192 | with users_patcher as users_mock, groups_patcher as groups_mock: |
|
193 | 193 | response = self.app.get( |
|
194 | 194 | url(controller='home', action='user_autocomplete_data', |
|
195 | 195 | user_groups='true', query=query), |
|
196 | 196 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
197 | 197 | |
|
198 | 198 | result = json.loads(response.body) |
|
199 | 199 | users_mock.assert_called_once_with( |
|
200 | 200 | name_contains=query, only_active=True) |
|
201 | 201 | groups_mock.assert_called_once_with( |
|
202 | 202 | name_contains=query, only_active=True) |
|
203 | 203 | assert len(result['suggestions']) == 20 |
|
204 | 204 | |
|
205 | 205 | |
|
206 | 206 | def assert_and_get_content(result): |
|
207 | 207 | repos = [] |
|
208 | 208 | groups = [] |
|
209 | 209 | commits = [] |
|
210 | 210 | for data in result: |
|
211 | 211 | for data_item in data['children']: |
|
212 | 212 | assert data_item['id'] |
|
213 | 213 | assert data_item['text'] |
|
214 | 214 | assert data_item['url'] |
|
215 | 215 | if data_item['type'] == 'repo': |
|
216 | 216 | repos.append(data_item) |
|
217 | 217 | elif data_item['type'] == 'group': |
|
218 | 218 | groups.append(data_item) |
|
219 | 219 | elif data_item['type'] == 'commit': |
|
220 | 220 | commits.append(data_item) |
|
221 | 221 | else: |
|
222 | 222 | raise Exception('invalid type %s' % data_item['type']) |
|
223 | 223 | |
|
224 | 224 | return repos, groups, commits |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | class TestGotoSwitcherData(TestController): |
|
228 | 228 | required_repos_with_groups = [ |
|
229 | 229 | 'abc', |
|
230 | 230 | 'abc-fork', |
|
231 | 231 | 'forks/abcd', |
|
232 | 232 | 'abcd', |
|
233 | 233 | 'abcde', |
|
234 | 234 | 'a/abc', |
|
235 | 235 | 'aa/abc', |
|
236 | 236 | 'aaa/abc', |
|
237 | 237 | 'aaaa/abc', |
|
238 | 238 | 'repos_abc/aaa/abc', |
|
239 | 239 | 'abc_repos/abc', |
|
240 | 240 | 'abc_repos/abcd', |
|
241 | 241 | 'xxx/xyz', |
|
242 | 242 | 'forked-abc/a/abc' |
|
243 | 243 | ] |
|
244 | 244 | |
|
245 | 245 | @pytest.fixture(autouse=True, scope='class') |
|
246 | 246 | def prepare(self, request, pylonsapp): |
|
247 | 247 | for repo_and_group in self.required_repos_with_groups: |
|
248 | 248 | # create structure of groups and return the last group |
|
249 | 249 | |
|
250 | 250 | repo_group = map_groups(repo_and_group) |
|
251 | 251 | |
|
252 | 252 | RepoModel()._create_repo( |
|
253 | 253 | repo_and_group, 'hg', 'test-ac', TEST_USER_ADMIN_LOGIN, |
|
254 | 254 | repo_group=getattr(repo_group, 'group_id', None)) |
|
255 | 255 | |
|
256 | 256 | Session().commit() |
|
257 | 257 | |
|
258 | 258 | request.addfinalizer(self.cleanup) |
|
259 | 259 | |
|
260 | 260 | def cleanup(self): |
|
261 | 261 | # first delete all repos |
|
262 | 262 | for repo_and_groups in self.required_repos_with_groups: |
|
263 | 263 | repo = Repository.get_by_repo_name(repo_and_groups) |
|
264 | 264 | if repo: |
|
265 | 265 | RepoModel().delete(repo) |
|
266 | 266 | Session().commit() |
|
267 | 267 | |
|
268 | 268 | # then delete all empty groups |
|
269 | 269 | for repo_and_groups in self.required_repos_with_groups: |
|
270 | 270 | if '/' in repo_and_groups: |
|
271 | 271 | r_group = repo_and_groups.rsplit('/', 1)[0] |
|
272 | 272 | repo_group = RepoGroup.get_by_group_name(r_group) |
|
273 | 273 | if not repo_group: |
|
274 | 274 | continue |
|
275 | 275 | parents = repo_group.parents |
|
276 | 276 | RepoGroupModel().delete(repo_group, force_delete=True) |
|
277 | 277 | Session().commit() |
|
278 | 278 | |
|
279 | 279 | for el in reversed(parents): |
|
280 | 280 | RepoGroupModel().delete(el, force_delete=True) |
|
281 | 281 | Session().commit() |
|
282 | 282 | |
|
283 | 283 | def test_returns_list_of_repos_and_groups(self): |
|
284 | 284 | self.log_user() |
|
285 | 285 | |
|
286 | 286 | response = self.app.get( |
|
287 | 287 | url(controller='home', action='goto_switcher_data'), |
|
288 | 288 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
289 | 289 | result = json.loads(response.body)['results'] |
|
290 | 290 | |
|
291 | 291 | repos, groups, commits = assert_and_get_content(result) |
|
292 | 292 | |
|
293 | 293 | assert len(repos) == len(Repository.get_all()) |
|
294 | 294 | assert len(groups) == len(RepoGroup.get_all()) |
|
295 | 295 | assert len(commits) == 0 |
|
296 | 296 | |
|
297 | 297 | def test_returns_list_of_repos_and_groups_filtered(self): |
|
298 | 298 | self.log_user() |
|
299 | 299 | |
|
300 | 300 | response = self.app.get( |
|
301 | 301 | url(controller='home', action='goto_switcher_data'), |
|
302 | 302 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, |
|
303 | 303 | params={'query': 'abc'}, status=200) |
|
304 | 304 | result = json.loads(response.body)['results'] |
|
305 | 305 | |
|
306 | 306 | repos, groups, commits = assert_and_get_content(result) |
|
307 | 307 | |
|
308 | 308 | assert len(repos) == 13 |
|
309 | 309 | assert len(groups) == 5 |
|
310 | 310 | assert len(commits) == 0 |
|
311 | 311 | |
|
312 | 312 | def test_returns_list_of_properly_sorted_and_filtered(self): |
|
313 | 313 | self.log_user() |
|
314 | 314 | |
|
315 | 315 | response = self.app.get( |
|
316 | 316 | url(controller='home', action='goto_switcher_data'), |
|
317 | 317 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, |
|
318 | 318 | params={'query': 'abc'}, status=200) |
|
319 | 319 | result = json.loads(response.body)['results'] |
|
320 | 320 | |
|
321 | 321 | repos, groups, commits = assert_and_get_content(result) |
|
322 | 322 | |
|
323 | 323 | test_repos = [x['text'] for x in repos[:4]] |
|
324 | 324 | assert ['abc', 'abcd', 'a/abc', 'abcde'] == test_repos |
|
325 | 325 | |
|
326 | 326 | test_groups = [x['text'] for x in groups[:4]] |
|
327 | 327 | assert ['abc_repos', 'repos_abc', |
|
328 | 328 | 'forked-abc', 'forked-abc/a'] == test_groups |
|
329 | 329 | |
|
330 | 330 | |
|
331 | 331 | class TestRepoListData(TestController): |
|
332 | 332 | def test_returns_list_of_repos_and_groups(self, user_util): |
|
333 | 333 | self.log_user() |
|
334 | 334 | |
|
335 | 335 | response = self.app.get( |
|
336 | 336 | url(controller='home', action='repo_list_data'), |
|
337 | 337 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200) |
|
338 | 338 | result = json.loads(response.body)['results'] |
|
339 | 339 | |
|
340 | 340 | repos, groups, commits = assert_and_get_content(result) |
|
341 | 341 | |
|
342 | 342 | assert len(repos) == len(Repository.get_all()) |
|
343 | 343 | assert len(groups) == 0 |
|
344 | 344 | assert len(commits) == 0 |
|
345 | 345 | |
|
346 | 346 | def test_returns_list_of_repos_and_groups_filtered(self): |
|
347 | 347 | self.log_user() |
|
348 | 348 | |
|
349 | 349 | response = self.app.get( |
|
350 | 350 | url(controller='home', action='repo_list_data'), |
|
351 | 351 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, |
|
352 | 352 | params={'query': 'vcs_test_git'}, status=200) |
|
353 | 353 | result = json.loads(response.body)['results'] |
|
354 | 354 | |
|
355 | 355 | repos, groups, commits = assert_and_get_content(result) |
|
356 | 356 | |
|
357 | 357 | assert len(repos) == len(Repository.query().filter( |
|
358 | 358 | Repository.repo_name.ilike('%vcs_test_git%')).all()) |
|
359 | 359 | assert len(groups) == 0 |
|
360 | 360 | assert len(commits) == 0 |
|
361 | 361 | |
|
362 | 362 | def test_returns_list_of_repos_and_groups_filtered_with_type(self): |
|
363 | 363 | self.log_user() |
|
364 | 364 | |
|
365 | 365 | response = self.app.get( |
|
366 | 366 | url(controller='home', action='repo_list_data'), |
|
367 | 367 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, |
|
368 | 368 | params={'query': 'vcs_test_git', 'repo_type': 'git'}, status=200) |
|
369 | 369 | result = json.loads(response.body)['results'] |
|
370 | 370 | |
|
371 | 371 | repos, groups, commits = assert_and_get_content(result) |
|
372 | 372 | |
|
373 | 373 | assert len(repos) == len(Repository.query().filter( |
|
374 | 374 | Repository.repo_name.ilike('%vcs_test_git%')).all()) |
|
375 | 375 | assert len(groups) == 0 |
|
376 | 376 | assert len(commits) == 0 |
|
377 | 377 | |
|
378 | 378 | def test_returns_list_of_repos_non_ascii_query(self): |
|
379 | 379 | self.log_user() |
|
380 | 380 | response = self.app.get( |
|
381 | 381 | url(controller='home', action='repo_list_data'), |
|
382 | 382 | headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, |
|
383 | 383 | params={'query': 'ć_vcs_test_ą', 'repo_type': 'git'}, status=200) |
|
384 | 384 | result = json.loads(response.body)['results'] |
|
385 | 385 | |
|
386 | 386 | repos, groups, commits = assert_and_get_content(result) |
|
387 | 387 | |
|
388 | 388 | assert len(repos) == 0 |
|
389 | 389 | assert len(groups) == 0 |
|
390 | 390 | assert len(commits) == 0 |
General Comments 0
You need to be logged in to leave comments.
Login now