Show More
@@ -1,62 +1,62 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2017 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import pytest |
|
21 | import pytest | |
22 | import random |
|
22 | import random | |
23 |
|
23 | |||
24 | from rhodecode.model import db |
|
24 | from rhodecode.model import db | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | @pytest.mark.parametrize("DBModel, id_attr", [ |
|
27 | @pytest.mark.parametrize("DBModel, klass, id_attr", [ | |
28 | (db.ChangesetComment, 'comment_id'), |
|
28 | (db.ChangesetComment, 'Comment', 'comment_id'), | |
29 | (db.PullRequest, 'pull_request_id'), |
|
29 | (db.PullRequest, db.PullRequest.__name__, 'pull_request_id'), | |
30 | (db.PullRequestVersion, 'pull_request_version_id'), |
|
30 | (db.PullRequestVersion, db.PullRequestVersion.__name__, 'pull_request_version_id'), | |
31 | ]) |
|
31 | ]) | |
32 | class TestModelReprImplementation: |
|
32 | class TestModelReprImplementation(object): | |
33 |
|
33 | |||
34 | def test_repr_without_id(self, DBModel, id_attr): |
|
34 | def test_repr_without_id(self, DBModel, klass, id_attr): | |
35 | instance = DBModel() |
|
35 | instance = DBModel() | |
36 |
expected_repr = '<DB:%s at %#x>' % ( |
|
36 | expected_repr = '<DB:%s at %#x>' % (klass, id(instance)) | |
37 | assert repr(instance) == expected_repr |
|
37 | assert repr(instance) == expected_repr | |
38 |
|
38 | |||
39 | def test_repr_with_id(self, DBModel, id_attr): |
|
39 | def test_repr_with_id(self, DBModel, klass, id_attr): | |
40 | test_id = random.randint(1, 10) |
|
40 | test_id = random.randint(1, 10) | |
41 | instance = DBModel() |
|
41 | instance = DBModel() | |
42 | setattr(instance, id_attr, test_id) |
|
42 | setattr(instance, id_attr, test_id) | |
43 | expected_repr = ( |
|
43 | expected_repr = ( | |
44 |
'<DB:%s #%d>' % ( |
|
44 | '<DB:%s #%d>' % (klass, test_id)) | |
45 | assert repr(instance) == expected_repr |
|
45 | assert repr(instance) == expected_repr | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def test_get_locking_state_invalid_action(user_regular): |
|
48 | def test_get_locking_state_invalid_action(user_regular): | |
49 | repo = db.Repository() |
|
49 | repo = db.Repository() | |
50 | action = 'not_push_neither_pull' |
|
50 | action = 'not_push_neither_pull' | |
51 | with pytest.raises(ValueError): |
|
51 | with pytest.raises(ValueError): | |
52 | repo.get_locking_state(action, user_id=user_regular.user_id) |
|
52 | repo.get_locking_state(action, user_id=user_regular.user_id) | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | def test_get_locking_state_valid_action(user_regular): |
|
55 | def test_get_locking_state_valid_action(user_regular): | |
56 | repo = db.Repository() |
|
56 | repo = db.Repository() | |
57 | action = 'push' |
|
57 | action = 'push' | |
58 | make_lock, locked, lock_info = repo.get_locking_state( |
|
58 | make_lock, locked, lock_info = repo.get_locking_state( | |
59 | action, user_id=user_regular.user_id) |
|
59 | action, user_id=user_regular.user_id) | |
60 | assert not make_lock |
|
60 | assert not make_lock | |
61 | assert not locked |
|
61 | assert not locked | |
62 | assert lock_info == [None, None, None] |
|
62 | assert lock_info == [None, None, None] |
General Comments 0
You need to be logged in to leave comments.
Login now