annotate kallithea/tests/functional/test_home.py @ 8687:5e46f73f0d1c

model: always import the whole db module - drop "from" imports
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 12 Oct 2020 11:12:37 +0200
parents b095e2fbba44
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
1 # -*- coding: utf-8 -*-
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
2 import json
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
3
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8224
diff changeset
4 from kallithea.model import meta
7811
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7143
diff changeset
5 from kallithea.model.repo import RepoModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7143
diff changeset
6 from kallithea.model.repo_group import RepoGroupModel
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
7 from kallithea.tests import base
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
8 from kallithea.tests.fixture import Fixture
462
298546182b41 more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
1788
ef0613584ced test fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1481
diff changeset
10
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3291
diff changeset
11 fixture = Fixture()
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3291
diff changeset
12
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3291
diff changeset
13
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
14 class TestHomeController(base.TestController):
462
298546182b41 more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
298546182b41 more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 def test_index(self):
464
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
17 self.log_user()
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
18 response = self.app.get(base.url(controller='home', action='index'))
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6532
diff changeset
19 # if global permission is set
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4010
diff changeset
20 response.mustcontain('Add Repository')
6487
481f64dbe85c tests: tighten TestHomeController matching/description
Søren Løvborg <sorenl@unity3d.com>
parents: 6220
diff changeset
21
6946
f1acd7c28157 changelog: add more verbose titles to [HG] and [GIT] repotags
domruf <dominikruf@gmail.com>
parents: 6875
diff changeset
22 response.mustcontain(
7105
97ea346aa4bd less: use .label and .label-* style instead of custom .*tag
domruf <dominikruf@gmail.com>
parents: 7052
diff changeset
23 """<span class="label label-repo" title="Git repository">git"""
6946
f1acd7c28157 changelog: add more verbose titles to [HG] and [GIT] repotags
domruf <dominikruf@gmail.com>
parents: 6875
diff changeset
24 )
f1acd7c28157 changelog: add more verbose titles to [HG] and [GIT] repotags
domruf <dominikruf@gmail.com>
parents: 6875
diff changeset
25
f1acd7c28157 changelog: add more verbose titles to [HG] and [GIT] repotags
domruf <dominikruf@gmail.com>
parents: 6875
diff changeset
26 response.mustcontain(
7105
97ea346aa4bd less: use .label and .label-* style instead of custom .*tag
domruf <dominikruf@gmail.com>
parents: 7052
diff changeset
27 """<span class="label label-repo" title="Mercurial repository">hg"""
6946
f1acd7c28157 changelog: add more verbose titles to [HG] and [GIT] repotags
domruf <dominikruf@gmail.com>
parents: 6875
diff changeset
28 )
6487
481f64dbe85c tests: tighten TestHomeController matching/description
Søren Løvborg <sorenl@unity3d.com>
parents: 6220
diff changeset
29
3752
1e5bb8ed77d6 index: always use lightweight - there shouldn't be any reason not to
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
30 # html in javascript variable:
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
31 response.mustcontain(r'href=\"/%s\"' % base.HG_REPO)
875
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
32
6532
33b71a130b16 templates: properly escape inline JavaScript values
Søren Løvborg <sorenl@unity3d.com>
parents: 6487
diff changeset
33 response.mustcontain(r'\x3ci class=\"icon-globe\"')
1788
ef0613584ced test fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1481
diff changeset
34
6487
481f64dbe85c tests: tighten TestHomeController matching/description
Søren Løvborg <sorenl@unity3d.com>
parents: 6220
diff changeset
35 response.mustcontain(r'\"fixes issue with having custom format for git-log\n\"')
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
36 response.mustcontain(r'\"/%s/changeset/5f2c6ee195929b0be80749243c18121c9864a3b3\"' % base.GIT_REPO)
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3752
diff changeset
37
6487
481f64dbe85c tests: tighten TestHomeController matching/description
Søren Løvborg <sorenl@unity3d.com>
parents: 6220
diff changeset
38 response.mustcontain(r'\"disable security checks on hg clone for travis\"')
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
39 response.mustcontain(r'\"/%s/changeset/96507bd11ecc815ebc6270fdf6db110928c09c1e\"' % base.HG_REPO)
2714
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
40
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
41 def test_repo_summary_with_anonymous_access_disabled(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4010
diff changeset
42 with fixture.anon_access(False):
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
43 response = self.app.get(base.url(controller='summary',
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
44 action='index', repo_name=base.HG_REPO),
2714
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
45 status=302)
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
46 assert 'login' in response.location
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
47
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
48 def test_index_with_anonymous_access_disabled(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4010
diff changeset
49 with fixture.anon_access(False):
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
50 response = self.app.get(base.url(controller='home', action='index'),
2714
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
51 status=302)
a2eaa0054430 fixed error when disabled anonymous access lead to error on server
Marcin Kuzminski <marcin@python-works.com>
parents: 2427
diff changeset
52 assert 'login' in response.location
2946
dbb311201ce3 add test for enabling lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 2714
diff changeset
53
3167
87258a137018 fixed issue with displaying repos in groups view (without lightweight dashboard), added tests for this case
Marcin Kuzminski <marcin@python-works.com>
parents: 2973
diff changeset
54 def test_index_page_on_groups(self):
87258a137018 fixed issue with displaying repos in groups view (without lightweight dashboard), added tests for this case
Marcin Kuzminski <marcin@python-works.com>
parents: 2973
diff changeset
55 self.log_user()
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
56 gr = fixture.create_repo_group('gr1')
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
57 fixture.create_repo(name='gr1/repo_in_group', repo_group=gr)
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
58 response = self.app.get(base.url('repos_group_home', group_name='gr1'))
3167
87258a137018 fixed issue with displaying repos in groups view (without lightweight dashboard), added tests for this case
Marcin Kuzminski <marcin@python-works.com>
parents: 2973
diff changeset
59
87258a137018 fixed issue with displaying repos in groups view (without lightweight dashboard), added tests for this case
Marcin Kuzminski <marcin@python-works.com>
parents: 2973
diff changeset
60 try:
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
61 response.mustcontain("gr1/repo_in_group")
3167
87258a137018 fixed issue with displaying repos in groups view (without lightweight dashboard), added tests for this case
Marcin Kuzminski <marcin@python-works.com>
parents: 2973
diff changeset
62 finally:
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
63 RepoModel().delete('gr1/repo_in_group')
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
64 RepoGroupModel().delete(repo_group='gr1', force_delete=True)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8224
diff changeset
65 meta.Session().commit()
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
66
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
67 def test_users_and_groups_data(self):
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
68 fixture.create_user('evil', firstname='D\'o\'ct"o"r', lastname='Évíl')
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
69 fixture.create_user_group('grrrr', user_group_description="Groüp")
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
70 response = self.app.get(base.url('users_and_groups_data', query='evi'))
7143
dc7e37ec3dfd auth: users_and_groups_data should not be available for anonymous/default user
domruf <dominikruf@gmail.com>
parents: 7105
diff changeset
71 assert response.status_code == 302
8109
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
72 assert base.url('login_home') in response.location
e527cc2ce8dc cleanup: get rid of most "import *"
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
73 self.log_user(base.TEST_USER_REGULAR_LOGIN, base.TEST_USER_REGULAR_PASS)
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
74 response = self.app.get(base.url('users_and_groups_data', query='evi'))
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
75 result = json.loads(response.body)['results']
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
76 assert result[0].get('fname') == 'D\'o\'ct"o"r'
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
77 assert result[0].get('lname') == 'Évíl'
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
78 response = self.app.get(base.url('users_and_groups_data', key='evil'))
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
79 result = json.loads(response.body)['results']
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
80 assert result[0].get('fname') == 'D\'o\'ct"o"r'
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
81 assert result[0].get('lname') == 'Évíl'
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
82 response = self.app.get(base.url('users_and_groups_data', query='rrrr'))
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
83 result = json.loads(response.body)['results']
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
84 assert not result
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
85 response = self.app.get(base.url('users_and_groups_data', types='users,groups', query='rrrr'))
6967
6c3bda995a88 js: use ajax requests for select2 autocomplete
domruf <dominikruf@gmail.com>
parents: 6946
diff changeset
86 result = json.loads(response.body)['results']
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8109
diff changeset
87 assert result[0].get('grname') == 'grrrr'