Show More
@@ -155,7 +155,7 b' class TestAuthSettingsView(object):' | |||||
155 | response = self._post_ldap_settings(params, override={ |
|
155 | response = self._post_ldap_settings(params, override={ | |
156 | 'port': invalid_port_value, |
|
156 | 'port': invalid_port_value, | |
157 | }) |
|
157 | }) | |
158 |
assertr = |
|
158 | assertr = response.assert_response() | |
159 | assertr.element_contains( |
|
159 | assertr.element_contains( | |
160 | '.form .field #port ~ .error-message', |
|
160 | '.form .field #port ~ .error-message', | |
161 | invalid_port_value) |
|
161 | invalid_port_value) |
@@ -81,13 +81,13 b' class TestAdminRepos(object):' | |||||
81 | def test_create_page_restricted_to_single_backend(self, autologin_user, backend): |
|
81 | def test_create_page_restricted_to_single_backend(self, autologin_user, backend): | |
82 | with mock.patch('rhodecode.BACKENDS', {'git': 'git'}): |
|
82 | with mock.patch('rhodecode.BACKENDS', {'git': 'git'}): | |
83 | response = self.app.get(route_path('repo_new'), status=200) |
|
83 | response = self.app.get(route_path('repo_new'), status=200) | |
84 |
assert_response = |
|
84 | assert_response = response.assert_response() | |
85 | element = assert_response.get_element('#repo_type') |
|
85 | element = assert_response.get_element('#repo_type') | |
86 | assert element.text_content() == '\ngit\n' |
|
86 | assert element.text_content() == '\ngit\n' | |
87 |
|
87 | |||
88 | def test_create_page_non_restricted_backends(self, autologin_user, backend): |
|
88 | def test_create_page_non_restricted_backends(self, autologin_user, backend): | |
89 | response = self.app.get(route_path('repo_new'), status=200) |
|
89 | response = self.app.get(route_path('repo_new'), status=200) | |
90 |
assert_response = |
|
90 | assert_response = response.assert_response() | |
91 | assert_response.element_contains('#repo_type', 'git') |
|
91 | assert_response.element_contains('#repo_type', 'git') | |
92 | assert_response.element_contains('#repo_type', 'svn') |
|
92 | assert_response.element_contains('#repo_type', 'svn') | |
93 | assert_response.element_contains('#repo_type', 'hg') |
|
93 | assert_response.element_contains('#repo_type', 'hg') |
@@ -367,7 +367,7 b' class TestAdminSettingsVcs(object):' | |||||
367 |
|
367 | |||
368 | def test_has_an_input_for_invalidation_of_inline_comments(self): |
|
368 | def test_has_an_input_for_invalidation_of_inline_comments(self): | |
369 | response = self.app.get(route_path('admin_settings_vcs')) |
|
369 | response = self.app.get(route_path('admin_settings_vcs')) | |
370 |
assert_response = |
|
370 | assert_response = response.assert_response() | |
371 | assert_response.one_element_exists( |
|
371 | assert_response.one_element_exists( | |
372 | '[name=rhodecode_use_outdated_comments]') |
|
372 | '[name=rhodecode_use_outdated_comments]') | |
373 |
|
373 | |||
@@ -518,7 +518,7 b' class TestOpenSourceLicenses(object):' | |||||
518 | response = self.app.get( |
|
518 | response = self.app.get( | |
519 | route_path('admin_settings_open_source'), status=200) |
|
519 | route_path('admin_settings_open_source'), status=200) | |
520 |
|
520 | |||
521 |
assert_response = |
|
521 | assert_response = response.assert_response() | |
522 | assert_response.element_contains( |
|
522 | assert_response.element_contains( | |
523 | '.panel-heading', 'Licenses of Third Party Packages') |
|
523 | '.panel-heading', 'Licenses of Third Party Packages') | |
524 | for license_data in sample_licenses: |
|
524 | for license_data in sample_licenses: | |
@@ -528,7 +528,7 b' class TestOpenSourceLicenses(object):' | |||||
528 | def test_records_can_be_read(self, autologin_user): |
|
528 | def test_records_can_be_read(self, autologin_user): | |
529 | response = self.app.get( |
|
529 | response = self.app.get( | |
530 | route_path('admin_settings_open_source'), status=200) |
|
530 | route_path('admin_settings_open_source'), status=200) | |
531 |
assert_response = |
|
531 | assert_response = response.assert_response() | |
532 | assert_response.element_contains( |
|
532 | assert_response.element_contains( | |
533 | '.panel-heading', 'Licenses of Third Party Packages') |
|
533 | '.panel-heading', 'Licenses of Third Party Packages') | |
534 |
|
534 |
@@ -88,7 +88,7 b' class TestPasswordReset(TestController):' | |||||
88 |
|
88 | |||
89 | response = self.app.get(route_path('reset_password')) |
|
89 | response = self.app.get(route_path('reset_password')) | |
90 |
|
90 | |||
91 |
assert_response = |
|
91 | assert_response = response.assert_response() | |
92 | if show_reset: |
|
92 | if show_reset: | |
93 | response.mustcontain('Send password reset email') |
|
93 | response.mustcontain('Send password reset email') | |
94 | assert_response.one_element_exists('#email') |
|
94 | assert_response.one_element_exists('#email') |
@@ -90,7 +90,7 b' class TestRegisterCaptcha(object):' | |||||
90 |
|
90 | |||
91 | response = app.get(ADMIN_PREFIX + '/register') |
|
91 | response = app.get(ADMIN_PREFIX + '/register') | |
92 |
|
92 | |||
93 |
assertr = |
|
93 | assertr = response.assert_response() | |
94 | if active: |
|
94 | if active: | |
95 | assertr.one_element_exists('#recaptcha_field') |
|
95 | assertr.one_element_exists('#recaptcha_field') | |
96 | else: |
|
96 | else: | |
@@ -128,6 +128,6 b' class TestRegisterCaptcha(object):' | |||||
128 | else: |
|
128 | else: | |
129 | # If captche input is invalid we expect to stay on the registration |
|
129 | # If captche input is invalid we expect to stay on the registration | |
130 | # page with an error message displayed. |
|
130 | # page with an error message displayed. | |
131 |
assertr = |
|
131 | assertr = response.assert_response() | |
132 | assert response.status_int == 200 |
|
132 | assert response.status_int == 200 | |
133 | assertr.one_element_exists('#recaptcha_field ~ span.error-message') |
|
133 | assertr.one_element_exists('#recaptcha_field ~ span.error-message') |
@@ -116,7 +116,7 b' class TestFeedView(TestController):' | |||||
116 | self, backend, user_util, feed_type): |
|
116 | self, backend, user_util, feed_type): | |
117 | user = user_util.create_user() |
|
117 | user = user_util.create_user() | |
118 | auth_token = AuthTokenModel().create( |
|
118 | auth_token = AuthTokenModel().create( | |
119 | user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_API) |
|
119 | user.user_id, u'test-token', -1, AuthTokenModel.cls.ROLE_API) | |
120 | auth_token = auth_token.api_key |
|
120 | auth_token = auth_token.api_key | |
121 |
|
121 | |||
122 | self.app.get( |
|
122 | self.app.get( | |
@@ -127,7 +127,7 b' class TestFeedView(TestController):' | |||||
127 | status=302) |
|
127 | status=302) | |
128 |
|
128 | |||
129 | auth_token = AuthTokenModel().create( |
|
129 | auth_token = AuthTokenModel().create( | |
130 | user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_FEED) |
|
130 | user.user_id, u'test-token', -1, AuthTokenModel.cls.ROLE_FEED) | |
131 | auth_token = auth_token.api_key |
|
131 | auth_token = auth_token.api_key | |
132 | self.app.get( |
|
132 | self.app.get( | |
133 | route_path( |
|
133 | route_path( |
@@ -236,7 +236,7 b' class TestSummaryView(object):' | |||||
236 | with scm_patcher: |
|
236 | with scm_patcher: | |
237 | response = self.app.get( |
|
237 | response = self.app.get( | |
238 | route_path('repo_summary', repo_name=repo_name)) |
|
238 | route_path('repo_summary', repo_name=repo_name)) | |
239 |
assert_response = |
|
239 | assert_response = response.assert_response() | |
240 | assert_response.element_contains( |
|
240 | assert_response.element_contains( | |
241 | '.main .alert-warning strong', 'Missing requirements') |
|
241 | '.main .alert-warning strong', 'Missing requirements') | |
242 | assert_response.element_contains( |
|
242 | assert_response.element_contains( |
@@ -98,7 +98,7 b' class TestVcsSettings(object):' | |||||
98 | repo_name = backend.repo_name |
|
98 | repo_name = backend.repo_name | |
99 | response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name)) |
|
99 | response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name)) | |
100 |
|
100 | |||
101 |
assert_response = |
|
101 | assert_response = response.assert_response() | |
102 | element = assert_response.get_element('#inherit_global_settings') |
|
102 | element = assert_response.get_element('#inherit_global_settings') | |
103 | assert element.checked |
|
103 | assert element.checked | |
104 |
|
104 | |||
@@ -111,7 +111,7 b' class TestVcsSettings(object):' | |||||
111 | repo, 'inherit_vcs_settings', checked_value, 'bool') |
|
111 | repo, 'inherit_vcs_settings', checked_value, 'bool') | |
112 | response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name)) |
|
112 | response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name)) | |
113 |
|
113 | |||
114 |
assert_response = |
|
114 | assert_response = response.assert_response() | |
115 | element = assert_response.get_element('#inherit_global_settings') |
|
115 | element = assert_response.get_element('#inherit_global_settings') | |
116 | assert element.checked == checked_value |
|
116 | assert element.checked == checked_value | |
117 |
|
117 | |||
@@ -491,7 +491,7 b' class TestVcsSettings(object):' | |||||
491 |
|
491 | |||
492 | response = self.app.get( |
|
492 | response = self.app.get( | |
493 | route_path('edit_repo_vcs', repo_name=repo_name), status=200) |
|
493 | route_path('edit_repo_vcs', repo_name=repo_name), status=200) | |
494 |
assert_response = |
|
494 | assert_response = response.assert_response() | |
495 | for branch in branches: |
|
495 | for branch in branches: | |
496 | css_selector = '[name=branch_value_{}]'.format(branch.ui_id) |
|
496 | css_selector = '[name=branch_value_{}]'.format(branch.ui_id) | |
497 | element = assert_response.get_element(css_selector) |
|
497 | element = assert_response.get_element(css_selector) | |
@@ -668,7 +668,7 b' class TestVcsSettings(object):' | |||||
668 | Session().commit() |
|
668 | Session().commit() | |
669 |
|
669 | |||
670 | def assert_repo_value_equals_global_value(self, response, setting): |
|
670 | def assert_repo_value_equals_global_value(self, response, setting): | |
671 |
assert_response = |
|
671 | assert_response = response.assert_response() | |
672 | global_css_selector = '[name={}_inherited]'.format(setting) |
|
672 | global_css_selector = '[name={}_inherited]'.format(setting) | |
673 | repo_css_selector = '[name={}]'.format(setting) |
|
673 | repo_css_selector = '[name={}]'.format(setting) | |
674 | repo_element = assert_response.get_element(repo_css_selector) |
|
674 | repo_element = assert_response.get_element(repo_css_selector) |
@@ -59,7 +59,7 b' class TestAdminRepoVcsSettings(object):' | |||||
59 | rhodecode.CONFIG, {'labs_settings_active': 'true'}): |
|
59 | rhodecode.CONFIG, {'labs_settings_active': 'true'}): | |
60 | response = self.app.get(vcs_settings_url) |
|
60 | response = self.app.get(vcs_settings_url) | |
61 |
|
61 | |||
62 |
assertr = |
|
62 | assertr = response.assert_response() | |
63 | assertr.one_element_exists('#rhodecode_{}'.format(setting_name)) |
|
63 | assertr.one_element_exists('#rhodecode_{}'.format(setting_name)) | |
64 |
|
64 | |||
65 | @pytest.mark.parametrize('setting_name, setting_backends', [ |
|
65 | @pytest.mark.parametrize('setting_name, setting_backends', [ |
@@ -46,7 +46,7 b' class TestSearchController(TestControlle' | |||||
46 | def test_index(self): |
|
46 | def test_index(self): | |
47 | self.log_user() |
|
47 | self.log_user() | |
48 | response = self.app.get(route_path('search')) |
|
48 | response = self.app.get(route_path('search')) | |
49 |
assert_response = |
|
49 | assert_response = response.assert_response() | |
50 | assert_response.one_element_exists('input#q') |
|
50 | assert_response.one_element_exists('input#q') | |
51 |
|
51 | |||
52 | def test_search_files_empty_search(self): |
|
52 | def test_search_files_empty_search(self): |
@@ -46,14 +46,14 b' class TestUsersController(TestController' | |||||
46 | response = self.app.get(route_path('user_profile', username=username)) |
|
46 | response = self.app.get(route_path('user_profile', username=username)) | |
47 | response.mustcontain('testme') |
|
47 | response.mustcontain('testme') | |
48 | response.mustcontain('testme@rhodecode.org') |
|
48 | response.mustcontain('testme@rhodecode.org') | |
49 |
assert_response = |
|
49 | assert_response = response.assert_response() | |
50 | assert_response.no_element_exists(edit_link_css) |
|
50 | assert_response.no_element_exists(edit_link_css) | |
51 |
|
51 | |||
52 | # edit should be available to superadmin users |
|
52 | # edit should be available to superadmin users | |
53 | self.logout_user() |
|
53 | self.logout_user() | |
54 | self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) |
|
54 | self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) | |
55 | response = self.app.get(route_path('user_profile', username=username)) |
|
55 | response = self.app.get(route_path('user_profile', username=username)) | |
56 |
assert_response = |
|
56 | assert_response = response.assert_response() | |
57 | assert_response.element_contains(edit_link_css, 'Edit') |
|
57 | assert_response.element_contains(edit_link_css, 'Edit') | |
58 |
|
58 | |||
59 | def test_user_profile_not_available(self, user_util): |
|
59 | def test_user_profile_not_available(self, user_util): |
@@ -584,7 +584,7 b' class User(Base, BaseModel):' | |||||
584 | _user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data |
|
584 | _user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data | |
585 |
|
585 | |||
586 | user_log = relationship('UserLog') |
|
586 | user_log = relationship('UserLog') | |
587 | user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all') |
|
587 | user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all, delete-orphan') | |
588 |
|
588 | |||
589 | repositories = relationship('Repository') |
|
589 | repositories = relationship('Repository') | |
590 | repository_groups = relationship('RepoGroup') |
|
590 | repository_groups = relationship('RepoGroup') | |
@@ -593,9 +593,9 b' class User(Base, BaseModel):' | |||||
593 | user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
|
593 | user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') | |
594 | followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all') |
|
594 | followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all') | |
595 |
|
595 | |||
596 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
|
596 | repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all, delete-orphan') | |
597 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
|
597 | repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all, delete-orphan') | |
598 | user_group_to_perm = relationship('UserUserGroupToPerm', primaryjoin='UserUserGroupToPerm.user_id==User.user_id', cascade='all') |
|
598 | user_group_to_perm = relationship('UserUserGroupToPerm', primaryjoin='UserUserGroupToPerm.user_id==User.user_id', cascade='all, delete-orphan') | |
599 |
|
599 | |||
600 | group_member = relationship('UserGroupMember', cascade='all') |
|
600 | group_member = relationship('UserGroupMember', cascade='all') | |
601 |
|
601 | |||
@@ -1328,7 +1328,7 b' class UserGroup(Base, BaseModel):' | |||||
1328 | created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
|
1328 | created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) | |
1329 | _group_data = Column("group_data", LargeBinary(), nullable=True) # JSON data |
|
1329 | _group_data = Column("group_data", LargeBinary(), nullable=True) # JSON data | |
1330 |
|
1330 | |||
1331 |
members = relationship('UserGroupMember', cascade="all, delete |
|
1331 | members = relationship('UserGroupMember', cascade="all, delete-orphan", lazy="joined") | |
1332 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') |
|
1332 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
1333 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
|
1333 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
1334 | users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') |
|
1334 | users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
@@ -1665,21 +1665,21 b' class Repository(Base, BaseModel):' | |||||
1665 | primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', |
|
1665 | primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', | |
1666 | cascade='all') |
|
1666 | cascade='all') | |
1667 | extra_fields = relationship( |
|
1667 | extra_fields = relationship( | |
1668 |
'RepositoryField', cascade="all, delete |
|
1668 | 'RepositoryField', cascade="all, delete-orphan") | |
1669 | logs = relationship('UserLog') |
|
1669 | logs = relationship('UserLog') | |
1670 | comments = relationship( |
|
1670 | comments = relationship( | |
1671 |
'ChangesetComment', cascade="all, delete |
|
1671 | 'ChangesetComment', cascade="all, delete-orphan") | |
1672 | pull_requests_source = relationship( |
|
1672 | pull_requests_source = relationship( | |
1673 | 'PullRequest', |
|
1673 | 'PullRequest', | |
1674 | primaryjoin='PullRequest.source_repo_id==Repository.repo_id', |
|
1674 | primaryjoin='PullRequest.source_repo_id==Repository.repo_id', | |
1675 |
cascade="all, delete |
|
1675 | cascade="all, delete-orphan") | |
1676 | pull_requests_target = relationship( |
|
1676 | pull_requests_target = relationship( | |
1677 | 'PullRequest', |
|
1677 | 'PullRequest', | |
1678 | primaryjoin='PullRequest.target_repo_id==Repository.repo_id', |
|
1678 | primaryjoin='PullRequest.target_repo_id==Repository.repo_id', | |
1679 |
cascade="all, delete |
|
1679 | cascade="all, delete-orphan") | |
1680 | ui = relationship('RepoRhodeCodeUi', cascade="all") |
|
1680 | ui = relationship('RepoRhodeCodeUi', cascade="all") | |
1681 | settings = relationship('RepoRhodeCodeSetting', cascade="all") |
|
1681 | settings = relationship('RepoRhodeCodeSetting', cascade="all") | |
1682 |
integrations = relationship('Integration', cascade="all, delete |
|
1682 | integrations = relationship('Integration', cascade="all, delete-orphan") | |
1683 |
|
1683 | |||
1684 | scoped_tokens = relationship('UserApiKeys', cascade="all") |
|
1684 | scoped_tokens = relationship('UserApiKeys', cascade="all") | |
1685 |
|
1685 | |||
@@ -2551,7 +2551,7 b' class RepoGroup(Base, BaseModel):' | |||||
2551 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') |
|
2551 | users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |
2552 | parent_group = relationship('RepoGroup', remote_side=group_id) |
|
2552 | parent_group = relationship('RepoGroup', remote_side=group_id) | |
2553 | user = relationship('User') |
|
2553 | user = relationship('User') | |
2554 |
integrations = relationship('Integration', cascade="all, delete |
|
2554 | integrations = relationship('Integration', cascade="all, delete-orphan") | |
2555 |
|
2555 | |||
2556 | def __init__(self, group_name='', parent_group=None): |
|
2556 | def __init__(self, group_name='', parent_group=None): | |
2557 | self.group_name = group_name |
|
2557 | self.group_name = group_name | |
@@ -3270,7 +3270,7 b' class UserRepoToPerm(Base, BaseModel):' | |||||
3270 | repository = relationship('Repository') |
|
3270 | repository = relationship('Repository') | |
3271 | permission = relationship('Permission') |
|
3271 | permission = relationship('Permission') | |
3272 |
|
3272 | |||
3273 |
branch_perm_entry = relationship('UserToRepoBranchPermission', cascade="all, delete |
|
3273 | branch_perm_entry = relationship('UserToRepoBranchPermission', cascade="all, delete-orphan", lazy='joined') | |
3274 |
|
3274 | |||
3275 | @classmethod |
|
3275 | @classmethod | |
3276 | def create(cls, user, repository, permission): |
|
3276 | def create(cls, user, repository, permission): | |
@@ -3646,7 +3646,7 b' class ChangesetComment(Base, BaseModel):' | |||||
3646 |
|
3646 | |||
3647 | author = relationship('User', lazy='joined') |
|
3647 | author = relationship('User', lazy='joined') | |
3648 | repo = relationship('Repository') |
|
3648 | repo = relationship('Repository') | |
3649 |
status_change = relationship('ChangesetStatus', cascade="all, delete |
|
3649 | status_change = relationship('ChangesetStatus', cascade="all, delete-orphan", lazy='joined') | |
3650 | pull_request = relationship('PullRequest', lazy='joined') |
|
3650 | pull_request = relationship('PullRequest', lazy='joined') | |
3651 | pull_request_version = relationship('PullRequestVersion') |
|
3651 | pull_request_version = relationship('PullRequestVersion') | |
3652 |
|
3652 | |||
@@ -4120,13 +4120,13 b' class PullRequest(Base, _PullRequestBase' | |||||
4120 | return '<DB:PullRequest at %#x>' % id(self) |
|
4120 | return '<DB:PullRequest at %#x>' % id(self) | |
4121 |
|
4121 | |||
4122 | reviewers = relationship('PullRequestReviewers', |
|
4122 | reviewers = relationship('PullRequestReviewers', | |
4123 |
cascade="all, delete |
|
4123 | cascade="all, delete-orphan") | |
4124 | statuses = relationship('ChangesetStatus', |
|
4124 | statuses = relationship('ChangesetStatus', | |
4125 |
cascade="all, delete |
|
4125 | cascade="all, delete-orphan") | |
4126 | comments = relationship('ChangesetComment', |
|
4126 | comments = relationship('ChangesetComment', | |
4127 |
cascade="all, delete |
|
4127 | cascade="all, delete-orphan") | |
4128 | versions = relationship('PullRequestVersion', |
|
4128 | versions = relationship('PullRequestVersion', | |
4129 |
cascade="all, delete |
|
4129 | cascade="all, delete-orphan", | |
4130 | lazy='dynamic') |
|
4130 | lazy='dynamic') | |
4131 |
|
4131 | |||
4132 | @classmethod |
|
4132 | @classmethod | |
@@ -4341,7 +4341,7 b' class Notification(Base, BaseModel):' | |||||
4341 |
|
4341 | |||
4342 | created_by_user = relationship('User') |
|
4342 | created_by_user = relationship('User') | |
4343 | notifications_to_users = relationship('UserNotification', lazy='joined', |
|
4343 | notifications_to_users = relationship('UserNotification', lazy='joined', | |
4344 |
cascade="all, delete |
|
4344 | cascade="all, delete-orphan") | |
4345 |
|
4345 | |||
4346 | @property |
|
4346 | @property | |
4347 | def recipients(self): |
|
4347 | def recipients(self): |
@@ -510,8 +510,7 b' class UserModel(BaseModel):' | |||||
510 | from rhodecode.lib.hooks_base import log_delete_user |
|
510 | from rhodecode.lib.hooks_base import log_delete_user | |
511 |
|
511 | |||
512 | if not cur_user: |
|
512 | if not cur_user: | |
513 | cur_user = getattr( |
|
513 | cur_user = getattr(get_current_rhodecode_user(), 'username', None) | |
514 | get_current_rhodecode_user(), 'username', None) |
|
|||
515 | user = self._get_user(user) |
|
514 | user = self._get_user(user) | |
516 |
|
515 | |||
517 | try: |
|
516 | try: |
@@ -27,7 +27,7 b' from mock import patch' | |||||
27 | from rhodecode.lib import auth |
|
27 | from rhodecode.lib import auth | |
28 | from rhodecode.lib.utils2 import md5 |
|
28 | from rhodecode.lib.utils2 import md5 | |
29 | from rhodecode.model.auth_token import AuthTokenModel |
|
29 | from rhodecode.model.auth_token import AuthTokenModel | |
30 | from rhodecode.model.db import User |
|
30 | from rhodecode.model.db import Session, User | |
31 | from rhodecode.model.repo import RepoModel |
|
31 | from rhodecode.model.repo import RepoModel | |
32 | from rhodecode.model.user import UserModel |
|
32 | from rhodecode.model.user import UserModel | |
33 | from rhodecode.model.user_group import UserGroupModel |
|
33 | from rhodecode.model.user_group import UserGroupModel | |
@@ -93,6 +93,7 b' def test_cached_perms_data_user_group_gl' | |||||
93 |
|
93 | |||
94 | granted_permission = 'repository.write' |
|
94 | granted_permission = 'repository.write' | |
95 | UserGroupModel().grant_perm(user_group, granted_permission) |
|
95 | UserGroupModel().grant_perm(user_group, granted_permission) | |
|
96 | Session().commit() | |||
96 |
|
97 | |||
97 | permissions = get_permissions(user) |
|
98 | permissions = get_permissions(user) | |
98 | assert granted_permission in permissions['global'] |
|
99 | assert granted_permission in permissions['global'] | |
@@ -104,6 +105,7 b' def test_cached_perms_data_user_group_gl' | |||||
104 |
|
105 | |||
105 | granted_permission = 'repository.write' |
|
106 | granted_permission = 'repository.write' | |
106 | UserGroupModel().grant_perm(user_group, granted_permission) |
|
107 | UserGroupModel().grant_perm(user_group, granted_permission) | |
|
108 | Session().commit() | |||
107 |
|
109 | |||
108 | permissions = get_permissions(user) |
|
110 | permissions = get_permissions(user) | |
109 | assert granted_permission in permissions['global'] |
|
111 | assert granted_permission in permissions['global'] | |
@@ -112,6 +114,7 b' def test_cached_perms_data_user_group_gl' | |||||
112 | def test_cached_perms_data_user_global_permissions(user_util): |
|
114 | def test_cached_perms_data_user_global_permissions(user_util): | |
113 | user = user_util.create_user() |
|
115 | user = user_util.create_user() | |
114 | UserModel().grant_perm(user, 'repository.none') |
|
116 | UserModel().grant_perm(user, 'repository.none') | |
|
117 | Session().commit() | |||
115 |
|
118 | |||
116 | permissions = get_permissions(user, user_inherit_default_permissions=True) |
|
119 | permissions = get_permissions(user, user_inherit_default_permissions=True) | |
117 | assert 'repository.read' in permissions['global'] |
|
120 | assert 'repository.read' in permissions['global'] | |
@@ -127,6 +130,7 b' def test_cached_perms_data_repository_pe' | |||||
127 | granted_permission = 'repository.write' |
|
130 | granted_permission = 'repository.write' | |
128 | RepoModel().grant_user_group_permission( |
|
131 | RepoModel().grant_user_group_permission( | |
129 | repo, user_group.users_group_name, granted_permission) |
|
132 | repo, user_group.users_group_name, granted_permission) | |
|
133 | Session().commit() | |||
130 |
|
134 | |||
131 | permissions = get_permissions(user) |
|
135 | permissions = get_permissions(user) | |
132 | assert permissions['repositories'][repo.repo_name] == granted_permission |
|
136 | assert permissions['repositories'][repo.repo_name] == granted_permission | |
@@ -153,6 +157,7 b' def test_cached_perms_data_repository_pe' | |||||
153 |
|
157 | |||
154 | # Don't inherit default object permissions |
|
158 | # Don't inherit default object permissions | |
155 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') |
|
159 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') | |
|
160 | Session().commit() | |||
156 |
|
161 | |||
157 | permissions = get_permissions(user) |
|
162 | permissions = get_permissions(user) | |
158 | assert permissions['repositories'][repo.repo_name] == 'repository.none' |
|
163 | assert permissions['repositories'][repo.repo_name] == 'repository.none' | |
@@ -203,6 +208,7 b' def test_cached_perms_data_default_permi' | |||||
203 | # Don't inherit default object permissions |
|
208 | # Don't inherit default object permissions | |
204 | user = user_util.create_user() |
|
209 | user = user_util.create_user() | |
205 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') |
|
210 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') | |
|
211 | Session().commit() | |||
206 |
|
212 | |||
207 | permissions = get_permissions(user) |
|
213 | permissions = get_permissions(user) | |
208 | assert permissions['repositories_groups'][repo_group.group_name] == \ |
|
214 | assert permissions['repositories_groups'][repo_group.group_name] == \ | |
@@ -224,6 +230,7 b' def test_cached_perms_data_repository_pe' | |||||
224 | repo, user_group.users_group_name, 'repository.read') |
|
230 | repo, user_group.users_group_name, 'repository.read') | |
225 | RepoModel().grant_user_group_permission( |
|
231 | RepoModel().grant_user_group_permission( | |
226 | repo, user_group2.users_group_name, 'repository.write') |
|
232 | repo, user_group2.users_group_name, 'repository.write') | |
|
233 | Session().commit() | |||
227 |
|
234 | |||
228 | permissions = get_permissions(user) |
|
235 | permissions = get_permissions(user) | |
229 | assert permissions['repositories'][repo.repo_name] == 'repository.write' |
|
236 | assert permissions['repositories'][repo.repo_name] == 'repository.write' | |
@@ -238,6 +245,7 b' def test_cached_perms_data_repository_pe' | |||||
238 |
|
245 | |||
239 | RepoModel().grant_user_group_permission( |
|
246 | RepoModel().grant_user_group_permission( | |
240 | repo, user_group.users_group_name, 'repository.write') |
|
247 | repo, user_group.users_group_name, 'repository.write') | |
|
248 | Session().commit() | |||
241 |
|
249 | |||
242 | permissions = get_permissions(user) |
|
250 | permissions = get_permissions(user) | |
243 | assert permissions['repositories'][repo.repo_name] == 'repository.admin' |
|
251 | assert permissions['repositories'][repo.repo_name] == 'repository.admin' | |
@@ -249,6 +257,7 b' def test_cached_perms_data_user_reposito' | |||||
249 | repo = backend_random.create_repo() |
|
257 | repo = backend_random.create_repo() | |
250 | granted_permission = 'repository.write' |
|
258 | granted_permission = 'repository.write' | |
251 | RepoModel().grant_user_permission(repo, user, granted_permission) |
|
259 | RepoModel().grant_user_permission(repo, user, granted_permission) | |
|
260 | Session().commit() | |||
252 |
|
261 | |||
253 | permissions = get_permissions(user) |
|
262 | permissions = get_permissions(user) | |
254 | assert permissions['repositories'][repo.repo_name] == granted_permission |
|
263 | assert permissions['repositories'][repo.repo_name] == granted_permission | |
@@ -260,6 +269,7 b' def test_cached_perms_data_user_reposito' | |||||
260 | repo = backend_random.create_repo() |
|
269 | repo = backend_random.create_repo() | |
261 | granted_permission = 'repository.none' |
|
270 | granted_permission = 'repository.none' | |
262 | RepoModel().grant_user_permission(repo, user, granted_permission) |
|
271 | RepoModel().grant_user_permission(repo, user, granted_permission) | |
|
272 | Session().commit() | |||
263 |
|
273 | |||
264 | permissions = get_permissions(user, explicit=True) |
|
274 | permissions = get_permissions(user, explicit=True) | |
265 | assert permissions['repositories'][repo.repo_name] == granted_permission |
|
275 | assert permissions['repositories'][repo.repo_name] == granted_permission | |
@@ -271,6 +281,7 b' def test_cached_perms_data_user_reposito' | |||||
271 | repo = backend_random.create_repo() |
|
281 | repo = backend_random.create_repo() | |
272 | repo.user_id = user.user_id |
|
282 | repo.user_id = user.user_id | |
273 | RepoModel().grant_user_permission(repo, user, 'repository.write') |
|
283 | RepoModel().grant_user_permission(repo, user, 'repository.write') | |
|
284 | Session().commit() | |||
274 |
|
285 | |||
275 | permissions = get_permissions(user) |
|
286 | permissions = get_permissions(user) | |
276 | assert permissions['repositories'][repo.repo_name] == 'repository.admin' |
|
287 | assert permissions['repositories'][repo.repo_name] == 'repository.admin' | |
@@ -380,6 +391,7 b' def test_cached_perms_data_user_group_pe' | |||||
380 | user = user_util.create_user() |
|
391 | user = user_util.create_user() | |
381 | user_group = user_util.create_user_group() |
|
392 | user_group = user_util.create_user_group() | |
382 | UserGroupModel().grant_user_permission(user_group, user, 'usergroup.write') |
|
393 | UserGroupModel().grant_user_permission(user_group, user, 'usergroup.write') | |
|
394 | Session().commit() | |||
383 |
|
395 | |||
384 | permissions = get_permissions(user) |
|
396 | permissions = get_permissions(user) | |
385 | assert permissions['user_groups'][user_group.users_group_name] == \ |
|
397 | assert permissions['user_groups'][user_group.users_group_name] == \ | |
@@ -391,6 +403,7 b' def test_cached_perms_data_user_group_pe' | |||||
391 | user = user_util.create_user() |
|
403 | user = user_util.create_user() | |
392 | user_group = user_util.create_user_group() |
|
404 | user_group = user_util.create_user_group() | |
393 | UserGroupModel().grant_user_permission(user_group, user, 'usergroup.none') |
|
405 | UserGroupModel().grant_user_permission(user_group, user, 'usergroup.none') | |
|
406 | Session().commit() | |||
394 |
|
407 | |||
395 | permissions = get_permissions(user, explicit=True) |
|
408 | permissions = get_permissions(user, explicit=True) | |
396 | assert permissions['user_groups'][user_group.users_group_name] == \ |
|
409 | assert permissions['user_groups'][user_group.users_group_name] == \ | |
@@ -404,6 +417,7 b' def test_cached_perms_data_user_group_pe' | |||||
404 |
|
417 | |||
405 | # Don't inherit default object permissions |
|
418 | # Don't inherit default object permissions | |
406 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') |
|
419 | UserModel().grant_perm(user, 'hg.inherit_default_perms.false') | |
|
420 | Session().commit() | |||
407 |
|
421 | |||
408 | permissions = get_permissions(user) |
|
422 | permissions = get_permissions(user) | |
409 | assert permissions['user_groups'][user_group.users_group_name] == \ |
|
423 | assert permissions['user_groups'][user_group.users_group_name] == \ | |
@@ -447,6 +461,7 b' def test_permission_calculator_repositor' | |||||
447 |
|
461 | |||
448 | RepoModel().grant_user_permission( |
|
462 | RepoModel().grant_user_permission( | |
449 | backend_random.repo, user, 'repository.write') |
|
463 | backend_random.repo, user, 'repository.write') | |
|
464 | Session().commit() | |||
450 |
|
465 | |||
451 | calculator = auth.PermissionCalculator( |
|
466 | calculator = auth.PermissionCalculator( | |
452 | user.user_id, {}, False, False, False, 'higherwin') |
|
467 | user.user_id, {}, False, False, False, 'higherwin') | |
@@ -610,7 +625,7 b' def test_auth_by_token(test_token, test_' | |||||
610 | user = user_util.create_user() |
|
625 | user = user_util.create_user() | |
611 | user_id = user.user_id |
|
626 | user_id = user.user_id | |
612 | for token, role, expires in expected_tokens: |
|
627 | for token, role, expires in expected_tokens: | |
613 | new_token = AuthTokenModel().create(user_id, 'test-token', expires, role) |
|
628 | new_token = AuthTokenModel().create(user_id, u'test-token', expires, role) | |
614 | new_token.api_key = token # inject known name for testing... |
|
629 | new_token.api_key = token # inject known name for testing... | |
615 |
|
630 | |||
616 | assert auth_result == user.authenticate_by_token( |
|
631 | assert auth_result == user.authenticate_by_token( |
@@ -277,6 +277,8 b' class TestCreateOrUpdateRepoHookSettings' | |||||
277 |
|
277 | |||
278 | with pytest.raises(ValueError) as exc_info: |
|
278 | with pytest.raises(ValueError) as exc_info: | |
279 | model.create_or_update_repo_hook_settings(data) |
|
279 | model.create_or_update_repo_hook_settings(data) | |
|
280 | Session().commit() | |||
|
281 | ||||
280 | msg = 'The given data does not contain {} key'.format(deleted_key) |
|
282 | msg = 'The given data does not contain {} key'.format(deleted_key) | |
281 | assert str(exc_info.value) == msg |
|
283 | assert str(exc_info.value) == msg | |
282 |
|
284 | |||
@@ -286,6 +288,8 b' class TestCreateOrUpdateRepoHookSettings' | |||||
286 | settings_util.create_repo_rhodecode_ui( |
|
288 | settings_util.create_repo_rhodecode_ui( | |
287 | repo_stub, section, None, key=key, active=False) |
|
289 | repo_stub, section, None, key=key, active=False) | |
288 | model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA) |
|
290 | model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA) | |
|
291 | Session().commit() | |||
|
292 | ||||
289 | for section, key in model.HOOKS_SETTINGS: |
|
293 | for section, key in model.HOOKS_SETTINGS: | |
290 | ui = model.repo_settings.get_ui_by_section_and_key(section, key) |
|
294 | ui = model.repo_settings.get_ui_by_section_and_key(section, key) | |
291 | assert ui.ui_active is True |
|
295 | assert ui.ui_active is True | |
@@ -297,6 +301,7 b' class TestCreateOrUpdateRepoHookSettings' | |||||
297 | with global_patch as global_mock: |
|
301 | with global_patch as global_mock: | |
298 | global_mock.get_ui_by_section_and_key.return_value = global_setting |
|
302 | global_mock.get_ui_by_section_and_key.return_value = global_setting | |
299 | model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA) |
|
303 | model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA) | |
|
304 | Session().commit() | |||
300 |
|
305 | |||
301 |
|
306 | |||
302 | class TestUpdateGlobalHookSettings(object): |
|
307 | class TestUpdateGlobalHookSettings(object): | |
@@ -309,6 +314,8 b' class TestUpdateGlobalHookSettings(objec' | |||||
309 |
|
314 | |||
310 | with pytest.raises(ValueError) as exc_info: |
|
315 | with pytest.raises(ValueError) as exc_info: | |
311 | model.update_global_hook_settings(data) |
|
316 | model.update_global_hook_settings(data) | |
|
317 | Session().commit() | |||
|
318 | ||||
312 | msg = 'The given data does not contain {} key'.format(deleted_key) |
|
319 | msg = 'The given data does not contain {} key'.format(deleted_key) | |
313 | assert str(exc_info.value) == msg |
|
320 | assert str(exc_info.value) == msg | |
314 |
|
321 | |||
@@ -322,6 +329,8 b' class TestUpdateGlobalHookSettings(objec' | |||||
322 | session_patcher = mock.patch('rhodecode.model.settings.Session') |
|
329 | session_patcher = mock.patch('rhodecode.model.settings.Session') | |
323 | with get_settings_patcher as get_settings_mock, session_patcher: |
|
330 | with get_settings_patcher as get_settings_mock, session_patcher: | |
324 | model.update_global_hook_settings(HOOKS_FORM_DATA) |
|
331 | model.update_global_hook_settings(HOOKS_FORM_DATA) | |
|
332 | Session().commit() | |||
|
333 | ||||
325 | assert setting_mock.ui_active is True |
|
334 | assert setting_mock.ui_active is True | |
326 | assert get_settings_mock.call_count == 3 |
|
335 | assert get_settings_mock.call_count == 3 | |
327 |
|
336 | |||
@@ -333,6 +342,8 b' class TestCreateOrUpdateRepoGeneralSetti' | |||||
333 | model, '_create_or_update_general_settings') |
|
342 | model, '_create_or_update_general_settings') | |
334 | with create_patch as create_mock: |
|
343 | with create_patch as create_mock: | |
335 | model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA) |
|
344 | model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA) | |
|
345 | Session().commit() | |||
|
346 | ||||
336 | create_mock.assert_called_once_with( |
|
347 | create_mock.assert_called_once_with( | |
337 | model.repo_settings, GENERAL_FORM_DATA) |
|
348 | model.repo_settings, GENERAL_FORM_DATA) | |
338 |
|
349 | |||
@@ -380,6 +391,7 b' class TestCreateOrUpdateGeneralSettings(' | |||||
380 |
|
391 | |||
381 | with pytest.raises(ValueError) as exc_info: |
|
392 | with pytest.raises(ValueError) as exc_info: | |
382 | model._create_or_update_general_settings(model.repo_settings, data) |
|
393 | model._create_or_update_general_settings(model.repo_settings, data) | |
|
394 | Session().commit() | |||
383 |
|
395 | |||
384 | msg = 'The given data does not contain {} key'.format(deleted_key) |
|
396 | msg = 'The given data does not contain {} key'.format(deleted_key) | |
385 | assert str(exc_info.value) == msg |
|
397 | assert str(exc_info.value) == msg | |
@@ -392,6 +404,7 b' class TestCreateOrUpdateGeneralSettings(' | |||||
392 |
|
404 | |||
393 | model._create_or_update_general_settings( |
|
405 | model._create_or_update_general_settings( | |
394 | model.repo_settings, GENERAL_FORM_DATA) |
|
406 | model.repo_settings, GENERAL_FORM_DATA) | |
|
407 | Session().commit() | |||
395 |
|
408 | |||
396 | for name in model.GENERAL_SETTINGS: |
|
409 | for name in model.GENERAL_SETTINGS: | |
397 | setting = model.repo_settings.get_setting_by_name(name) |
|
410 | setting = model.repo_settings.get_setting_by_name(name) | |
@@ -403,12 +416,16 b' class TestCreateRepoSvnSettings(object):' | |||||
403 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
416 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
404 | with mock.patch.object(model, '_create_svn_settings') as create_mock: |
|
417 | with mock.patch.object(model, '_create_svn_settings') as create_mock: | |
405 | model.create_repo_svn_settings(SVN_FORM_DATA) |
|
418 | model.create_repo_svn_settings(SVN_FORM_DATA) | |
|
419 | Session().commit() | |||
|
420 | ||||
406 | create_mock.assert_called_once_with(model.repo_settings, SVN_FORM_DATA) |
|
421 | create_mock.assert_called_once_with(model.repo_settings, SVN_FORM_DATA) | |
407 |
|
422 | |||
408 | def test_raises_exception_when_repository_is_not_specified(self): |
|
423 | def test_raises_exception_when_repository_is_not_specified(self): | |
409 | model = VcsSettingsModel() |
|
424 | model = VcsSettingsModel() | |
410 | with pytest.raises(Exception) as exc_info: |
|
425 | with pytest.raises(Exception) as exc_info: | |
411 | model.create_repo_svn_settings(SVN_FORM_DATA) |
|
426 | model.create_repo_svn_settings(SVN_FORM_DATA) | |
|
427 | Session().commit() | |||
|
428 | ||||
412 | assert str(exc_info.value) == 'Repository is not specified' |
|
429 | assert str(exc_info.value) == 'Repository is not specified' | |
413 |
|
430 | |||
414 |
|
431 | |||
@@ -547,6 +564,8 b' class TestCreateOrUpdateRepoHgSettings(o' | |||||
547 | data.pop(field_to_remove) |
|
564 | data.pop(field_to_remove) | |
548 | with pytest.raises(ValueError) as exc_info: |
|
565 | with pytest.raises(ValueError) as exc_info: | |
549 | model.create_or_update_repo_hg_settings(data) |
|
566 | model.create_or_update_repo_hg_settings(data) | |
|
567 | Session().commit() | |||
|
568 | ||||
550 | expected_message = 'The given data does not contain {} key'.format( |
|
569 | expected_message = 'The given data does not contain {} key'.format( | |
551 | field_to_remove) |
|
570 | field_to_remove) | |
552 | assert str(exc_info.value) == expected_message |
|
571 | assert str(exc_info.value) == expected_message | |
@@ -555,6 +574,8 b' class TestCreateOrUpdateRepoHgSettings(o' | |||||
555 | model = VcsSettingsModel() |
|
574 | model = VcsSettingsModel() | |
556 | with pytest.raises(Exception) as exc_info: |
|
575 | with pytest.raises(Exception) as exc_info: | |
557 | model.create_or_update_repo_hg_settings(self.FORM_DATA) |
|
576 | model.create_or_update_repo_hg_settings(self.FORM_DATA) | |
|
577 | Session().commit() | |||
|
578 | ||||
558 | assert str(exc_info.value) == 'Repository is not specified' |
|
579 | assert str(exc_info.value) == 'Repository is not specified' | |
559 |
|
580 | |||
560 |
|
581 | |||
@@ -563,6 +584,8 b' class TestUpdateGlobalSslSetting(object)' | |||||
563 | model = VcsSettingsModel() |
|
584 | model = VcsSettingsModel() | |
564 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: |
|
585 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: | |
565 | model.update_global_ssl_setting('False') |
|
586 | model.update_global_ssl_setting('False') | |
|
587 | Session().commit() | |||
|
588 | ||||
566 | create_mock.assert_called_once_with( |
|
589 | create_mock.assert_called_once_with( | |
567 | model.global_settings, 'web', 'push_ssl', value='False') |
|
590 | model.global_settings, 'web', 'push_ssl', value='False') | |
568 |
|
591 | |||
@@ -572,6 +595,8 b' class TestUpdateGlobalPathSetting(object' | |||||
572 | model = VcsSettingsModel() |
|
595 | model = VcsSettingsModel() | |
573 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: |
|
596 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: | |
574 | model.update_global_path_setting('False') |
|
597 | model.update_global_path_setting('False') | |
|
598 | Session().commit() | |||
|
599 | ||||
575 | create_mock.assert_called_once_with( |
|
600 | create_mock.assert_called_once_with( | |
576 | model.global_settings, 'paths', '/', value='False') |
|
601 | model.global_settings, 'paths', '/', value='False') | |
577 |
|
602 | |||
@@ -589,6 +614,8 b' class TestCreateOrUpdateGlobalHgSettings' | |||||
589 | model = VcsSettingsModel() |
|
614 | model = VcsSettingsModel() | |
590 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: |
|
615 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: | |
591 | model.create_or_update_global_hg_settings(self.FORM_DATA) |
|
616 | model.create_or_update_global_hg_settings(self.FORM_DATA) | |
|
617 | Session().commit() | |||
|
618 | ||||
592 | expected_calls = [ |
|
619 | expected_calls = [ | |
593 | mock.call(model.global_settings, 'extensions', 'largefiles', active=False, value=''), |
|
620 | mock.call(model.global_settings, 'extensions', 'largefiles', active=False, value=''), | |
594 | mock.call(model.global_settings, 'largefiles', 'usercache', value='/example/largefiles-store'), |
|
621 | mock.call(model.global_settings, 'largefiles', 'usercache', value='/example/largefiles-store'), | |
@@ -609,6 +636,8 b' class TestCreateOrUpdateGlobalHgSettings' | |||||
609 | data.pop(field_to_remove) |
|
636 | data.pop(field_to_remove) | |
610 | with pytest.raises(Exception) as exc_info: |
|
637 | with pytest.raises(Exception) as exc_info: | |
611 | model.create_or_update_global_hg_settings(data) |
|
638 | model.create_or_update_global_hg_settings(data) | |
|
639 | Session().commit() | |||
|
640 | ||||
612 | expected_message = 'The given data does not contain {} key'.format( |
|
641 | expected_message = 'The given data does not contain {} key'.format( | |
613 | field_to_remove) |
|
642 | field_to_remove) | |
614 | assert str(exc_info.value) == expected_message |
|
643 | assert str(exc_info.value) == expected_message | |
@@ -624,6 +653,8 b' class TestCreateOrUpdateGlobalGitSetting' | |||||
624 | model = VcsSettingsModel() |
|
653 | model = VcsSettingsModel() | |
625 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: |
|
654 | with mock.patch.object(model, '_create_or_update_ui') as create_mock: | |
626 | model.create_or_update_global_git_settings(self.FORM_DATA) |
|
655 | model.create_or_update_global_git_settings(self.FORM_DATA) | |
|
656 | Session().commit() | |||
|
657 | ||||
627 | expected_calls = [ |
|
658 | expected_calls = [ | |
628 | mock.call(model.global_settings, 'vcs_git_lfs', 'enabled', active=False, value=False), |
|
659 | mock.call(model.global_settings, 'vcs_git_lfs', 'enabled', active=False, value=False), | |
629 | mock.call(model.global_settings, 'vcs_git_lfs', 'store_location', value='/example/lfs-store'), |
|
660 | mock.call(model.global_settings, 'vcs_git_lfs', 'store_location', value='/example/lfs-store'), | |
@@ -649,6 +680,8 b' class TestDeleteRepoSvnPattern(object):' | |||||
649 | delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui') |
|
680 | delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui') | |
650 | with delete_ui_patch as delete_ui_mock: |
|
681 | with delete_ui_patch as delete_ui_mock: | |
651 | model.delete_repo_svn_pattern(123) |
|
682 | model.delete_repo_svn_pattern(123) | |
|
683 | Session().commit() | |||
|
684 | ||||
652 | delete_ui_mock.assert_called_once_with(-1) |
|
685 | delete_ui_mock.assert_called_once_with(-1) | |
653 |
|
686 | |||
654 | def test_raises_exception_when_repository_is_not_specified(self): |
|
687 | def test_raises_exception_when_repository_is_not_specified(self): | |
@@ -748,6 +781,8 b' class TestGetRepoUiSettings(object):' | |||||
748 | for section in svn_sections: |
|
781 | for section in svn_sections: | |
749 | settings_util.create_rhodecode_ui( |
|
782 | settings_util.create_rhodecode_ui( | |
750 | section, 'repo', key='deadbeef' + section, active=False) |
|
783 | section, 'repo', key='deadbeef' + section, active=False) | |
|
784 | Session().commit() | |||
|
785 | ||||
751 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
786 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
752 | result = model.get_repo_ui_settings() |
|
787 | result = model.get_repo_ui_settings() | |
753 | for setting in result: |
|
788 | for setting in result: | |
@@ -795,6 +830,8 b' class TestGetRepoGeneralSettings(object)' | |||||
795 | for key in VcsSettingsModel.GENERAL_SETTINGS: |
|
830 | for key in VcsSettingsModel.GENERAL_SETTINGS: | |
796 | settings_util.create_repo_rhodecode_setting( |
|
831 | settings_util.create_repo_rhodecode_setting( | |
797 | repo_stub, key, 'abcde', type_='unicode') |
|
832 | repo_stub, key, 'abcde', type_='unicode') | |
|
833 | Session().commit() | |||
|
834 | ||||
798 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
835 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
799 | result = model.get_repo_ui_settings() |
|
836 | result = model.get_repo_ui_settings() | |
800 | for key in result: |
|
837 | for key in result: | |
@@ -820,6 +857,8 b' class TestGetGlobalGeneralSettings(objec' | |||||
820 | for key in VcsSettingsModel.GENERAL_SETTINGS: |
|
857 | for key in VcsSettingsModel.GENERAL_SETTINGS: | |
821 | settings_util.create_repo_rhodecode_setting( |
|
858 | settings_util.create_repo_rhodecode_setting( | |
822 | repo_stub, key, 'abcde', type_='unicode') |
|
859 | repo_stub, key, 'abcde', type_='unicode') | |
|
860 | Session().commit() | |||
|
861 | ||||
823 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
862 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
824 | result = model.get_global_general_settings() |
|
863 | result = model.get_global_general_settings() | |
825 | expected_result = model.global_settings.get_all_settings() |
|
864 | expected_result = model.global_settings.get_all_settings() | |
@@ -838,6 +877,8 b' class TestGetGlobalUiSettings(object):' | |||||
838 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: |
|
877 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: | |
839 | settings_util.create_repo_rhodecode_ui( |
|
878 | settings_util.create_repo_rhodecode_ui( | |
840 | repo_stub, section, 'repo', key=key, active=False) |
|
879 | repo_stub, section, 'repo', key=key, active=False) | |
|
880 | Session().commit() | |||
|
881 | ||||
841 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
882 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
842 | result = model.get_global_ui_settings() |
|
883 | result = model.get_global_ui_settings() | |
843 | expected_result = model.global_settings.get_ui() |
|
884 | expected_result = model.global_settings.get_ui() | |
@@ -868,6 +909,8 b' class TestGetGeneralSettings(object):' | |||||
868 | for key in VcsSettingsModel.GENERAL_SETTINGS: |
|
909 | for key in VcsSettingsModel.GENERAL_SETTINGS: | |
869 | settings_util.create_repo_rhodecode_setting( |
|
910 | settings_util.create_repo_rhodecode_setting( | |
870 | repo_stub, key, 'abcde', type_='unicode') |
|
911 | repo_stub, key, 'abcde', type_='unicode') | |
|
912 | Session().commit() | |||
|
913 | ||||
871 | result = model.get_general_settings() |
|
914 | result = model.get_general_settings() | |
872 | expected_result = model.get_global_general_settings() |
|
915 | expected_result = model.get_global_general_settings() | |
873 | assert sorted(result) == sorted(expected_result) |
|
916 | assert sorted(result) == sorted(expected_result) | |
@@ -879,6 +922,8 b' class TestGetGeneralSettings(object):' | |||||
879 | for key in VcsSettingsModel.GENERAL_SETTINGS: |
|
922 | for key in VcsSettingsModel.GENERAL_SETTINGS: | |
880 | settings_util.create_repo_rhodecode_setting( |
|
923 | settings_util.create_repo_rhodecode_setting( | |
881 | repo_stub, key, 'abcde', type_='unicode') |
|
924 | repo_stub, key, 'abcde', type_='unicode') | |
|
925 | Session().commit() | |||
|
926 | ||||
882 | result = model.get_general_settings() |
|
927 | result = model.get_general_settings() | |
883 | expected_result = model.get_repo_general_settings() |
|
928 | expected_result = model.get_repo_general_settings() | |
884 | assert sorted(result) == sorted(expected_result) |
|
929 | assert sorted(result) == sorted(expected_result) | |
@@ -898,6 +943,8 b' class TestGetUiSettings(object):' | |||||
898 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: |
|
943 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: | |
899 | settings_util.create_repo_rhodecode_ui( |
|
944 | settings_util.create_repo_rhodecode_ui( | |
900 | repo_stub, section, 'repo', key=key, active=True) |
|
945 | repo_stub, section, 'repo', key=key, active=True) | |
|
946 | Session().commit() | |||
|
947 | ||||
901 | result = model.get_ui_settings() |
|
948 | result = model.get_ui_settings() | |
902 | expected_result = model.get_global_ui_settings() |
|
949 | expected_result = model.get_global_ui_settings() | |
903 | assert sorted(result) == sorted(expected_result) |
|
950 | assert sorted(result) == sorted(expected_result) | |
@@ -909,6 +956,8 b' class TestGetUiSettings(object):' | |||||
909 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: |
|
956 | for section, key in VcsSettingsModel.HOOKS_SETTINGS: | |
910 | settings_util.create_repo_rhodecode_ui( |
|
957 | settings_util.create_repo_rhodecode_ui( | |
911 | repo_stub, section, 'repo', key=key, active=True) |
|
958 | repo_stub, section, 'repo', key=key, active=True) | |
|
959 | Session().commit() | |||
|
960 | ||||
912 | result = model.get_ui_settings() |
|
961 | result = model.get_ui_settings() | |
913 | expected_result = model.get_repo_ui_settings() |
|
962 | expected_result = model.get_repo_ui_settings() | |
914 | assert sorted(result) == sorted(expected_result) |
|
963 | assert sorted(result) == sorted(expected_result) | |
@@ -916,9 +965,12 b' class TestGetUiSettings(object):' | |||||
916 | def test_repo_settings_filtered_by_section_and_key(self, repo_stub): |
|
965 | def test_repo_settings_filtered_by_section_and_key(self, repo_stub): | |
917 | model = VcsSettingsModel(repo=repo_stub.repo_name) |
|
966 | model = VcsSettingsModel(repo=repo_stub.repo_name) | |
918 | model.inherit_global_settings = False |
|
967 | model.inherit_global_settings = False | |
|
968 | ||||
919 | args = ('section', 'key') |
|
969 | args = ('section', 'key') | |
920 | with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock: |
|
970 | with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock: | |
921 | model.get_ui_settings(*args) |
|
971 | model.get_ui_settings(*args) | |
|
972 | Session().commit() | |||
|
973 | ||||
922 | settings_mock.assert_called_once_with(*args) |
|
974 | settings_mock.assert_called_once_with(*args) | |
923 |
|
975 | |||
924 | def test_global_settings_filtered_by_section_and_key(self): |
|
976 | def test_global_settings_filtered_by_section_and_key(self): | |
@@ -942,6 +994,8 b' class TestGetSvnPatterns(object):' | |||||
942 | args = ('section', ) |
|
994 | args = ('section', ) | |
943 | with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock: |
|
995 | with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock: | |
944 | model.get_svn_patterns(*args) |
|
996 | model.get_svn_patterns(*args) | |
|
997 | ||||
|
998 | Session().commit() | |||
945 | settings_mock.assert_called_once_with(*args) |
|
999 | settings_mock.assert_called_once_with(*args) | |
946 |
|
1000 | |||
947 | def test_global_settings_filtered_by_section_and_key(self): |
|
1001 | def test_global_settings_filtered_by_section_and_key(self): | |
@@ -990,6 +1044,8 b' class TestCreateOrUpdateRepoSettings(obj' | |||||
990 | model = VcsSettingsModel() |
|
1044 | model = VcsSettingsModel() | |
991 | with pytest.raises(Exception) as exc_info: |
|
1045 | with pytest.raises(Exception) as exc_info: | |
992 | model.create_or_update_repo_settings(data=self.FORM_DATA) |
|
1046 | model.create_or_update_repo_settings(data=self.FORM_DATA) | |
|
1047 | Session().commit() | |||
|
1048 | ||||
993 | assert str(exc_info.value) == 'Repository is not specified' |
|
1049 | assert str(exc_info.value) == 'Repository is not specified' | |
994 |
|
1050 | |||
995 | def test_only_svn_settings_are_updated_when_type_is_svn(self, backend_svn): |
|
1051 | def test_only_svn_settings_are_updated_when_type_is_svn(self, backend_svn): | |
@@ -998,6 +1054,8 b' class TestCreateOrUpdateRepoSettings(obj' | |||||
998 | with self._patch_model(model) as mocks: |
|
1054 | with self._patch_model(model) as mocks: | |
999 | model.create_or_update_repo_settings( |
|
1055 | model.create_or_update_repo_settings( | |
1000 | data=self.FORM_DATA, inherit_global_settings=False) |
|
1056 | data=self.FORM_DATA, inherit_global_settings=False) | |
|
1057 | Session().commit() | |||
|
1058 | ||||
1001 | mocks['create_repo_svn_settings'].assert_called_once_with( |
|
1059 | mocks['create_repo_svn_settings'].assert_called_once_with( | |
1002 | self.FORM_DATA) |
|
1060 | self.FORM_DATA) | |
1003 | non_called_methods = ( |
|
1061 | non_called_methods = ( | |
@@ -1013,6 +1071,7 b' class TestCreateOrUpdateRepoSettings(obj' | |||||
1013 | with self._patch_model(model) as mocks: |
|
1071 | with self._patch_model(model) as mocks: | |
1014 | model.create_or_update_repo_settings( |
|
1072 | model.create_or_update_repo_settings( | |
1015 | data=self.FORM_DATA, inherit_global_settings=False) |
|
1073 | data=self.FORM_DATA, inherit_global_settings=False) | |
|
1074 | Session().commit() | |||
1016 |
|
1075 | |||
1017 | assert mocks['create_repo_svn_settings'].call_count == 0 |
|
1076 | assert mocks['create_repo_svn_settings'].call_count == 0 | |
1018 | called_methods = ( |
|
1077 | called_methods = ( | |
@@ -1060,6 +1119,8 b' class TestCreateOrUpdateRepoSettings(obj' | |||||
1060 | with invalidation_patcher as invalidation_mock: |
|
1119 | with invalidation_patcher as invalidation_mock: | |
1061 | model.create_or_update_repo_settings( |
|
1120 | model.create_or_update_repo_settings( | |
1062 | data=self.FORM_DATA, inherit_global_settings=True) |
|
1121 | data=self.FORM_DATA, inherit_global_settings=True) | |
|
1122 | Session().commit() | |||
|
1123 | ||||
1063 | invalidation_mock.assert_called_once_with( |
|
1124 | invalidation_mock.assert_called_once_with( | |
1064 | repo_stub.repo_name, delete=True) |
|
1125 | repo_stub.repo_name, delete=True) | |
1065 |
|
1126 | |||
@@ -1069,6 +1130,8 b' class TestCreateOrUpdateRepoSettings(obj' | |||||
1069 | with self._patch_model(model): |
|
1130 | with self._patch_model(model): | |
1070 | model.create_or_update_repo_settings( |
|
1131 | model.create_or_update_repo_settings( | |
1071 | data=self.FORM_DATA, inherit_global_settings=False) |
|
1132 | data=self.FORM_DATA, inherit_global_settings=False) | |
|
1133 | Session().commit() | |||
|
1134 | ||||
1072 | assert model.inherit_global_settings is False |
|
1135 | assert model.inherit_global_settings is False | |
1073 |
|
1136 | |||
1074 | def _patch_model(self, model): |
|
1137 | def _patch_model(self, model): |
@@ -79,21 +79,23 b' class TestPermissions(object):' | |||||
79 | def cleanup(self): |
|
79 | def cleanup(self): | |
80 | if hasattr(self, 'test_repo'): |
|
80 | if hasattr(self, 'test_repo'): | |
81 | RepoModel().delete(repo=self.test_repo) |
|
81 | RepoModel().delete(repo=self.test_repo) | |
|
82 | Session().commit() | |||
82 |
|
83 | |||
83 | if hasattr(self, 'g1'): |
|
84 | if hasattr(self, 'g1'): | |
84 | RepoGroupModel().delete(self.g1.group_id) |
|
85 | RepoGroupModel().delete(self.g1.group_id) | |
85 | if hasattr(self, 'g2'): |
|
86 | if hasattr(self, 'g2'): | |
86 | RepoGroupModel().delete(self.g2.group_id) |
|
87 | RepoGroupModel().delete(self.g2.group_id) | |
|
88 | Session().commit() | |||
87 |
|
89 | |||
88 | UserModel().delete(self.u1) |
|
90 | UserModel().delete(self.u1, handle_repos='delete', handle_repo_groups='delete') | |
89 | UserModel().delete(self.u2) |
|
91 | UserModel().delete(self.u2, handle_repos='delete', handle_repo_groups='delete') | |
90 | UserModel().delete(self.u3) |
|
92 | UserModel().delete(self.u3, handle_repos='delete', handle_repo_groups='delete') | |
91 | UserModel().delete(self.a1) |
|
93 | UserModel().delete(self.a1, handle_repos='delete', handle_repo_groups='delete') | |
|
94 | Session().commit() | |||
92 |
|
95 | |||
93 | if hasattr(self, 'ug1'): |
|
96 | if hasattr(self, 'ug1'): | |
94 | UserGroupModel().delete(self.ug1, force=True) |
|
97 | UserGroupModel().delete(self.ug1, force=True) | |
95 |
|
98 | Session().commit() | ||
96 | Session().commit() |
|
|||
97 |
|
99 | |||
98 | def test_default_perms_set(self, repo_name): |
|
100 | def test_default_perms_set(self, repo_name): | |
99 | assert repo_perms(self.u1)[repo_name] == 'repository.read' |
|
101 | assert repo_perms(self.u1)[repo_name] == 'repository.read' | |
@@ -183,6 +185,7 b' class TestPermissions(object):' | |||||
183 | new_perm_gr = 'repository.write' |
|
185 | new_perm_gr = 'repository.write' | |
184 | RepoModel().grant_user_group_permission( |
|
186 | RepoModel().grant_user_group_permission( | |
185 | repo=repo_name, group_name=self.ug1, perm=new_perm_gr) |
|
187 | repo=repo_name, group_name=self.ug1, perm=new_perm_gr) | |
|
188 | Session().commit() | |||
186 |
|
189 | |||
187 | assert repo_perms(self.u1)[repo_name] == new_perm |
|
190 | assert repo_perms(self.u1)[repo_name] == new_perm | |
188 | assert group_perms(self.u1) == {} |
|
191 | assert group_perms(self.u1) == {} | |
@@ -197,6 +200,7 b' class TestPermissions(object):' | |||||
197 | new_perm_gr = 'repository.write' |
|
200 | new_perm_gr = 'repository.write' | |
198 | RepoModel().grant_user_group_permission( |
|
201 | RepoModel().grant_user_group_permission( | |
199 | repo=repo_name, group_name=self.ug1, perm=new_perm_gr) |
|
202 | repo=repo_name, group_name=self.ug1, perm=new_perm_gr) | |
|
203 | Session().commit() | |||
200 |
|
204 | |||
201 | assert repo_perms(self.u3)[repo_name] == new_perm_gr |
|
205 | assert repo_perms(self.u3)[repo_name] == new_perm_gr | |
202 | assert group_perms(self.u3) == {} |
|
206 | assert group_perms(self.u3) == {} | |
@@ -220,6 +224,7 b' class TestPermissions(object):' | |||||
220 | new_perm_l = 'repository.read' |
|
224 | new_perm_l = 'repository.read' | |
221 | RepoModel().grant_user_group_permission( |
|
225 | RepoModel().grant_user_group_permission( | |
222 | repo=repo_name, group_name=self.ug1, perm=new_perm_l) |
|
226 | repo=repo_name, group_name=self.ug1, perm=new_perm_l) | |
|
227 | Session().commit() | |||
223 |
|
228 | |||
224 | assert repo_perms(self.u1)[repo_name] == new_perm_h |
|
229 | assert repo_perms(self.u1)[repo_name] == new_perm_h | |
225 | assert group_perms(self.u1) == {} |
|
230 | assert group_perms(self.u1) == {} | |
@@ -281,6 +286,8 b' class TestPermissions(object):' | |||||
281 | # set default permission to none |
|
286 | # set default permission to none | |
282 | RepoGroupModel().grant_user_permission( |
|
287 | RepoGroupModel().grant_user_permission( | |
283 | repo_group=self.g1, user=self.anon, perm='group.none') |
|
288 | repo_group=self.g1, user=self.anon, perm='group.none') | |
|
289 | Session().commit() | |||
|
290 | ||||
284 | # make group |
|
291 | # make group | |
285 | self.ug1 = fixture.create_user_group('G1') |
|
292 | self.ug1 = fixture.create_user_group('G1') | |
286 | # add user to group |
|
293 | # add user to group | |
@@ -501,6 +508,7 b' class TestPermissions(object):' | |||||
501 | UserGroupModel().add_user_to_group(self.ug1, self.u1) |
|
508 | UserGroupModel().add_user_to_group(self.ug1, self.u1) | |
502 | RepoGroupModel().grant_user_group_permission( |
|
509 | RepoGroupModel().grant_user_group_permission( | |
503 | repo_group=self.g1, group_name=self.ug1, perm='group.write') |
|
510 | repo_group=self.g1, group_name=self.ug1, perm='group.write') | |
|
511 | Session().commit() | |||
504 |
|
512 | |||
505 | # Verify that user does not get any special permission if he is not |
|
513 | # Verify that user does not get any special permission if he is not | |
506 | # owner |
|
514 | # owner | |
@@ -515,6 +523,7 b' class TestPermissions(object):' | |||||
515 | self.g1 = fixture.create_repo_group('test1') |
|
523 | self.g1 = fixture.create_repo_group('test1') | |
516 | RepoGroupModel().grant_user_permission( |
|
524 | RepoGroupModel().grant_user_permission( | |
517 | repo_group=self.g1, user=self.u1, perm='group.write') |
|
525 | repo_group=self.g1, user=self.u1, perm='group.write') | |
|
526 | Session().commit() | |||
518 |
|
527 | |||
519 | # Verify that user does not get any special permission if he is not |
|
528 | # Verify that user does not get any special permission if he is not | |
520 | # owner |
|
529 | # owner | |
@@ -524,7 +533,7 b' class TestPermissions(object):' | |||||
524 | self.g1.user = self.u1 |
|
533 | self.g1.user = self.u1 | |
525 | assert group_perms(self.u1) == {u'test1': 'group.admin'} |
|
534 | assert group_perms(self.u1) == {u'test1': 'group.admin'} | |
526 |
|
535 | |||
527 |
def |
|
536 | def assert_user_perm_equal( | |
528 | self, user, change_factor=0, compare_keys=None): |
|
537 | self, user, change_factor=0, compare_keys=None): | |
529 | perms = UserToPerm.query().filter(UserToPerm.user == user).all() |
|
538 | perms = UserToPerm.query().filter(UserToPerm.user == user).all() | |
530 | assert len(perms) == \ |
|
539 | assert len(perms) == \ | |
@@ -533,7 +542,7 b' class TestPermissions(object):' | |||||
533 | assert set( |
|
542 | assert set( | |
534 | x.permissions.permission_name for x in perms) == compare_keys |
|
543 | x.permissions.permission_name for x in perms) == compare_keys | |
535 |
|
544 | |||
536 |
def |
|
545 | def assert_def_user_group_perm_equal( | |
537 | self, user_group, change_factor=0, compare_keys=None): |
|
546 | self, user_group, change_factor=0, compare_keys=None): | |
538 | perms = UserGroupToPerm.query().filter( |
|
547 | perms = UserGroupToPerm.query().filter( | |
539 | UserGroupToPerm.users_group == user_group).all() |
|
548 | UserGroupToPerm.users_group == user_group).all() | |
@@ -545,21 +554,21 b' class TestPermissions(object):' | |||||
545 |
|
554 | |||
546 | def test_set_default_permissions(self): |
|
555 | def test_set_default_permissions(self): | |
547 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
556 | PermissionModel().create_default_user_permissions(user=self.u1) | |
548 |
self. |
|
557 | self.assert_user_perm_equal(user=self.u1) | |
549 |
|
558 | |||
550 | def test_set_default_permissions_after_one_is_missing(self): |
|
559 | def test_set_default_permissions_after_one_is_missing(self): | |
551 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
560 | PermissionModel().create_default_user_permissions(user=self.u1) | |
552 |
self. |
|
561 | self.assert_user_perm_equal(user=self.u1) | |
553 | # now we delete one, it should be re-created after another call |
|
562 | # now we delete one, it should be re-created after another call | |
554 | perms = UserToPerm.query().filter(UserToPerm.user == self.u1).all() |
|
563 | perms = UserToPerm.query().filter(UserToPerm.user == self.u1).all() | |
555 | Session().delete(perms[0]) |
|
564 | Session().delete(perms[0]) | |
556 | Session().commit() |
|
565 | Session().commit() | |
557 |
|
566 | |||
558 |
self. |
|
567 | self.assert_user_perm_equal(user=self.u1, change_factor=-1) | |
559 |
|
568 | |||
560 | # create missing one ! |
|
569 | # create missing one ! | |
561 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
570 | PermissionModel().create_default_user_permissions(user=self.u1) | |
562 |
self. |
|
571 | self.assert_user_perm_equal(user=self.u1) | |
563 |
|
572 | |||
564 | @pytest.mark.parametrize("perm, modify_to", [ |
|
573 | @pytest.mark.parametrize("perm, modify_to", [ | |
565 | ('repository.read', 'repository.none'), |
|
574 | ('repository.read', 'repository.none'), | |
@@ -571,7 +580,7 b' class TestPermissions(object):' | |||||
571 | ]) |
|
580 | ]) | |
572 | def test_set_default_permissions_after_modification(self, perm, modify_to): |
|
581 | def test_set_default_permissions_after_modification(self, perm, modify_to): | |
573 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
582 | PermissionModel().create_default_user_permissions(user=self.u1) | |
574 |
self. |
|
583 | self.assert_user_perm_equal(user=self.u1) | |
575 |
|
584 | |||
576 | old = Permission.get_by_key(perm) |
|
585 | old = Permission.get_by_key(perm) | |
577 | new = Permission.get_by_key(modify_to) |
|
586 | new = Permission.get_by_key(modify_to) | |
@@ -587,28 +596,28 b' class TestPermissions(object):' | |||||
587 | Session().commit() |
|
596 | Session().commit() | |
588 |
|
597 | |||
589 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
598 | PermissionModel().create_default_user_permissions(user=self.u1) | |
590 |
self. |
|
599 | self.assert_user_perm_equal(user=self.u1) | |
591 |
|
600 | |||
592 | def test_clear_user_perms(self): |
|
601 | def test_clear_user_perms(self): | |
593 | PermissionModel().create_default_user_permissions(user=self.u1) |
|
602 | PermissionModel().create_default_user_permissions(user=self.u1) | |
594 |
self. |
|
603 | self.assert_user_perm_equal(user=self.u1) | |
595 |
|
604 | |||
596 | # now clear permissions |
|
605 | # now clear permissions | |
597 | cleared = PermissionModel()._clear_user_perms(self.u1.user_id) |
|
606 | cleared = PermissionModel()._clear_user_perms(self.u1.user_id) | |
598 |
self. |
|
607 | self.assert_user_perm_equal(user=self.u1, | |
599 |
|
|
608 | change_factor=len(cleared)*-1) | |
600 |
|
609 | |||
601 | def test_clear_user_group_perms(self): |
|
610 | def test_clear_user_group_perms(self): | |
602 | self.ug1 = fixture.create_user_group('G1') |
|
611 | self.ug1 = fixture.create_user_group('G1') | |
603 | PermissionModel().create_default_user_group_permissions( |
|
612 | PermissionModel().create_default_user_group_permissions( | |
604 | user_group=self.ug1) |
|
613 | user_group=self.ug1) | |
605 |
self. |
|
614 | self.assert_def_user_group_perm_equal(user_group=self.ug1) | |
606 |
|
615 | |||
607 | # now clear permissions |
|
616 | # now clear permissions | |
608 | cleared = PermissionModel()._clear_user_group_perms( |
|
617 | cleared = PermissionModel()._clear_user_group_perms( | |
609 | self.ug1.users_group_id) |
|
618 | self.ug1.users_group_id) | |
610 |
self. |
|
619 | self.assert_def_user_group_perm_equal(user_group=self.ug1, | |
611 | change_factor=len(cleared)*-1) |
|
620 | change_factor=len(cleared)*-1) | |
612 |
|
621 | |||
613 | @pytest.mark.parametrize("form_result", [ |
|
622 | @pytest.mark.parametrize("form_result", [ | |
614 | {}, |
|
623 | {}, | |
@@ -626,7 +635,7 b' class TestPermissions(object):' | |||||
626 | Session().commit() |
|
635 | Session().commit() | |
627 | change_factor = -1 * (len(Permission.DEFAULT_USER_PERMISSIONS) |
|
636 | change_factor = -1 * (len(Permission.DEFAULT_USER_PERMISSIONS) | |
628 | - len(form_result.keys())) |
|
637 | - len(form_result.keys())) | |
629 |
self. |
|
638 | self.assert_user_perm_equal( | |
630 | self.u1, change_factor=change_factor) |
|
639 | self.u1, change_factor=change_factor) | |
631 |
|
640 | |||
632 | @pytest.mark.parametrize("form_result", [ |
|
641 | @pytest.mark.parametrize("form_result", [ | |
@@ -646,7 +655,7 b' class TestPermissions(object):' | |||||
646 | Session().commit() |
|
655 | Session().commit() | |
647 | change_factor = -1 * (len(Permission.DEFAULT_USER_PERMISSIONS) |
|
656 | change_factor = -1 * (len(Permission.DEFAULT_USER_PERMISSIONS) | |
648 | - len(form_result.keys())) |
|
657 | - len(form_result.keys())) | |
649 |
self. |
|
658 | self.assert_def_user_group_perm_equal( | |
650 | self.ug1, change_factor=change_factor) |
|
659 | self.ug1, change_factor=change_factor) | |
651 |
|
660 | |||
652 | @pytest.mark.parametrize("group_active, expected_perm", [ |
|
661 | @pytest.mark.parametrize("group_active, expected_perm", [ |
@@ -124,6 +124,8 b' class TestPullRequestModel(object):' | |||||
124 | PullRequestModel().update_reviewers( |
|
124 | PullRequestModel().update_reviewers( | |
125 | pull_request, [(pull_request.author, ['author'], False, [])], |
|
125 | pull_request, [(pull_request.author, ['author'], False, [])], | |
126 | pull_request.author) |
|
126 | pull_request.author) | |
|
127 | Session().commit() | |||
|
128 | ||||
127 | prs = PullRequestModel().get_awaiting_my_review( |
|
129 | prs = PullRequestModel().get_awaiting_my_review( | |
128 | pull_request.target_repo, user_id=pull_request.author.user_id) |
|
130 | pull_request.target_repo, user_id=pull_request.author.user_id) | |
129 | assert isinstance(prs, list) |
|
131 | assert isinstance(prs, list) | |
@@ -133,6 +135,8 b' class TestPullRequestModel(object):' | |||||
133 | PullRequestModel().update_reviewers( |
|
135 | PullRequestModel().update_reviewers( | |
134 | pull_request, [(pull_request.author, ['author'], False, [])], |
|
136 | pull_request, [(pull_request.author, ['author'], False, [])], | |
135 | pull_request.author) |
|
137 | pull_request.author) | |
|
138 | Session().commit() | |||
|
139 | ||||
136 | pr_count = PullRequestModel().count_awaiting_my_review( |
|
140 | pr_count = PullRequestModel().count_awaiting_my_review( | |
137 | pull_request.target_repo, user_id=pull_request.author.user_id) |
|
141 | pull_request.target_repo, user_id=pull_request.author.user_id) | |
138 | assert pr_count == 1 |
|
142 | assert pr_count == 1 | |
@@ -140,6 +144,7 b' class TestPullRequestModel(object):' | |||||
140 | def test_delete_calls_cleanup_merge(self, pull_request): |
|
144 | def test_delete_calls_cleanup_merge(self, pull_request): | |
141 | repo_id = pull_request.target_repo.repo_id |
|
145 | repo_id = pull_request.target_repo.repo_id | |
142 | PullRequestModel().delete(pull_request, pull_request.author) |
|
146 | PullRequestModel().delete(pull_request, pull_request.author) | |
|
147 | Session().commit() | |||
143 |
|
148 | |||
144 | self.workspace_remove_mock.assert_called_once_with( |
|
149 | self.workspace_remove_mock.assert_called_once_with( | |
145 | repo_id, self.workspace_id) |
|
150 | repo_id, self.workspace_id) | |
@@ -147,6 +152,8 b' class TestPullRequestModel(object):' | |||||
147 | def test_close_calls_cleanup_and_hook(self, pull_request): |
|
152 | def test_close_calls_cleanup_and_hook(self, pull_request): | |
148 | PullRequestModel().close_pull_request( |
|
153 | PullRequestModel().close_pull_request( | |
149 | pull_request, pull_request.author) |
|
154 | pull_request, pull_request.author) | |
|
155 | Session().commit() | |||
|
156 | ||||
150 | repo_id = pull_request.target_repo.repo_id |
|
157 | repo_id = pull_request.target_repo.repo_id | |
151 |
|
158 | |||
152 | self.workspace_remove_mock.assert_called_once_with( |
|
159 | self.workspace_remove_mock.assert_called_once_with( | |
@@ -286,6 +293,7 b' class TestPullRequestModel(object):' | |||||
286 | merge_extras['repository'] = pull_request.target_repo.repo_name |
|
293 | merge_extras['repository'] = pull_request.target_repo.repo_name | |
287 | PullRequestModel().merge_repo( |
|
294 | PullRequestModel().merge_repo( | |
288 | pull_request, pull_request.author, extras=merge_extras) |
|
295 | pull_request, pull_request.author, extras=merge_extras) | |
|
296 | Session().commit() | |||
289 |
|
297 | |||
290 | message = ( |
|
298 | message = ( | |
291 | u'Merge pull request #{pr_id} from {source_repo} {source_ref_name}' |
|
299 | u'Merge pull request #{pr_id} from {source_repo} {source_ref_name}' | |
@@ -327,6 +335,7 b' class TestPullRequestModel(object):' | |||||
327 | assert pull_request.pull_request_state == PullRequest.STATE_UPDATING |
|
335 | assert pull_request.pull_request_state == PullRequest.STATE_UPDATING | |
328 | PullRequestModel().merge_repo( |
|
336 | PullRequestModel().merge_repo( | |
329 | pull_request, pull_request.author, extras=merge_extras) |
|
337 | pull_request, pull_request.author, extras=merge_extras) | |
|
338 | Session().commit() | |||
330 |
|
339 | |||
331 | assert pull_request.pull_request_state == PullRequest.STATE_CREATED |
|
340 | assert pull_request.pull_request_state == PullRequest.STATE_CREATED | |
332 |
|
341 | |||
@@ -367,6 +376,7 b' class TestPullRequestModel(object):' | |||||
367 | merge_extras['repository'] = pull_request.target_repo.repo_name |
|
376 | merge_extras['repository'] = pull_request.target_repo.repo_name | |
368 | PullRequestModel().merge_repo( |
|
377 | PullRequestModel().merge_repo( | |
369 | pull_request, pull_request.author, extras=merge_extras) |
|
378 | pull_request, pull_request.author, extras=merge_extras) | |
|
379 | Session().commit() | |||
370 |
|
380 | |||
371 | message = ( |
|
381 | message = ( | |
372 | u'Merge pull request #{pr_id} from {source_repo} {source_ref_name}' |
|
382 | u'Merge pull request #{pr_id} from {source_repo} {source_ref_name}' | |
@@ -442,6 +452,7 b' class TestIntegrationMerge(object):' | |||||
442 | with mock.patch.dict(rhodecode.CONFIG, extra_config, clear=False): |
|
452 | with mock.patch.dict(rhodecode.CONFIG, extra_config, clear=False): | |
443 | merge_state = PullRequestModel().merge_repo( |
|
453 | merge_state = PullRequestModel().merge_repo( | |
444 | pull_request, user_admin, extras=merge_extras) |
|
454 | pull_request, user_admin, extras=merge_extras) | |
|
455 | Session().commit() | |||
445 |
|
456 | |||
446 | assert merge_state.executed |
|
457 | assert merge_state.executed | |
447 | assert '_pre_push_hook' in capture_rcextensions |
|
458 | assert '_pre_push_hook' in capture_rcextensions | |
@@ -459,6 +470,7 b' class TestIntegrationMerge(object):' | |||||
459 | pre_pull.side_effect = RepositoryError("Disallow push!") |
|
470 | pre_pull.side_effect = RepositoryError("Disallow push!") | |
460 | merge_status = PullRequestModel().merge_repo( |
|
471 | merge_status = PullRequestModel().merge_repo( | |
461 | pull_request, user_admin, extras=merge_extras) |
|
472 | pull_request, user_admin, extras=merge_extras) | |
|
473 | Session().commit() | |||
462 |
|
474 | |||
463 | assert not merge_status.executed |
|
475 | assert not merge_status.executed | |
464 | assert 'pre_push' not in capture_rcextensions |
|
476 | assert 'pre_push' not in capture_rcextensions | |
@@ -479,6 +491,8 b' class TestIntegrationMerge(object):' | |||||
479 | Session().commit() |
|
491 | Session().commit() | |
480 | merge_status = PullRequestModel().merge_repo( |
|
492 | merge_status = PullRequestModel().merge_repo( | |
481 | pull_request, user_regular, extras=merge_extras) |
|
493 | pull_request, user_regular, extras=merge_extras) | |
|
494 | Session().commit() | |||
|
495 | ||||
482 | assert not merge_status.executed |
|
496 | assert not merge_status.executed | |
483 |
|
497 | |||
484 |
|
498 | |||
@@ -889,6 +903,7 b' def test_link_comments_to_version_only_u' | |||||
889 | version2 = pr_util.create_version_of_pull_request() |
|
903 | version2 = pr_util.create_version_of_pull_request() | |
890 |
|
904 | |||
891 | PullRequestModel()._link_comments_to_version(version2) |
|
905 | PullRequestModel()._link_comments_to_version(version2) | |
|
906 | Session().commit() | |||
892 |
|
907 | |||
893 | # Expect that only the new comment is linked to version2 |
|
908 | # Expect that only the new comment is linked to version2 | |
894 | assert ( |
|
909 | assert ( |
@@ -395,7 +395,7 b' class TestVCSOperations(object):' | |||||
395 |
|
395 | |||
396 | user = user_util.create_user() |
|
396 | user = user_util.create_user() | |
397 | auth_token = AuthTokenModel().create( |
|
397 | auth_token = AuthTokenModel().create( | |
398 | user.user_id, 'test-token', -10, AuthTokenModel.cls.ROLE_VCS) |
|
398 | user.user_id, u'test-token', -10, AuthTokenModel.cls.ROLE_VCS) | |
399 | token = auth_token.api_key |
|
399 | token = auth_token.api_key | |
400 |
|
400 | |||
401 | clone_url = rc_web_server.repo_clone_url( |
|
401 | clone_url = rc_web_server.repo_clone_url( | |
@@ -412,7 +412,7 b' class TestVCSOperations(object):' | |||||
412 |
|
412 | |||
413 | user = user_util.create_user() |
|
413 | user = user_util.create_user() | |
414 | auth_token = AuthTokenModel().create( |
|
414 | auth_token = AuthTokenModel().create( | |
415 | user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_API) |
|
415 | user.user_id, u'test-token', -1, AuthTokenModel.cls.ROLE_API) | |
416 | token = auth_token.api_key |
|
416 | token = auth_token.api_key | |
417 |
|
417 | |||
418 | clone_url = rc_web_server.repo_clone_url( |
|
418 | clone_url = rc_web_server.repo_clone_url( | |
@@ -445,7 +445,7 b' class TestVCSOperations(object):' | |||||
445 | 'egg:rhodecode-enterprise-ce#rhodecode']) |
|
445 | 'egg:rhodecode-enterprise-ce#rhodecode']) | |
446 | user = user_util.create_user() |
|
446 | user = user_util.create_user() | |
447 | auth_token = AuthTokenModel().create( |
|
447 | auth_token = AuthTokenModel().create( | |
448 | user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS) |
|
448 | user.user_id, u'test-token', -1, AuthTokenModel.cls.ROLE_VCS) | |
449 | token = auth_token.api_key |
|
449 | token = auth_token.api_key | |
450 |
|
450 | |||
451 | # manually set scope |
|
451 | # manually set scope | |
@@ -466,7 +466,7 b' class TestVCSOperations(object):' | |||||
466 | 'egg:rhodecode-enterprise-ce#rhodecode']) |
|
466 | 'egg:rhodecode-enterprise-ce#rhodecode']) | |
467 | user = user_util.create_user() |
|
467 | user = user_util.create_user() | |
468 | auth_token = AuthTokenModel().create( |
|
468 | auth_token = AuthTokenModel().create( | |
469 | user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS) |
|
469 | user.user_id, u'test-token', -1, AuthTokenModel.cls.ROLE_VCS) | |
470 | token = auth_token.api_key |
|
470 | token = auth_token.api_key | |
471 |
|
471 | |||
472 | # manually set scope |
|
472 | # manually set scope |
General Comments 0
You need to be logged in to leave comments.
Login now