Show More
@@ -1,67 +1,66 b'' | |||||
1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
1 | # RhodeCode VCSServer provides access to different vcs backends via network. | |
2 | # Copyright (C) 2014-2018 RhodeCode GmbH |
|
2 | # Copyright (C) 2014-2018 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or modify |
|
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by |
|
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or |
|
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. |
|
7 | # (at your option) any later version. | |
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 General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import io |
|
18 | import io | |
19 | import mock |
|
19 | import mock | |
20 | import pytest |
|
20 | import pytest | |
21 | import sys |
|
21 | import sys | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | class MockPopen(object): |
|
24 | class MockPopen(object): | |
25 | def __init__(self, stderr): |
|
25 | def __init__(self, stderr): | |
26 | self.stdout = io.BytesIO('') |
|
26 | self.stdout = io.BytesIO('') | |
27 | self.stderr = io.BytesIO(stderr) |
|
27 | self.stderr = io.BytesIO(stderr) | |
28 | self.returncode = 1 |
|
28 | self.returncode = 1 | |
29 |
|
29 | |||
30 | def wait(self): |
|
30 | def wait(self): | |
31 | pass |
|
31 | pass | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | INVALID_CERTIFICATE_STDERR = '\n'.join([ |
|
34 | INVALID_CERTIFICATE_STDERR = '\n'.join([ | |
35 | 'svnrdump: E230001: Unable to connect to a repository at URL url', |
|
35 | 'svnrdump: E230001: Unable to connect to a repository at URL url', | |
36 | 'svnrdump: E230001: Server SSL certificate verification failed: issuer is not trusted', |
|
36 | 'svnrdump: E230001: Server SSL certificate verification failed: issuer is not trusted', | |
37 | ]) |
|
37 | ]) | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | @pytest.mark.parametrize('stderr,expected_reason', [ |
|
40 | @pytest.mark.parametrize('stderr,expected_reason', [ | |
41 | (INVALID_CERTIFICATE_STDERR, 'INVALID_CERTIFICATE'), |
|
41 | (INVALID_CERTIFICATE_STDERR, 'INVALID_CERTIFICATE'), | |
42 | ('svnrdump: E123456', 'UNKNOWN'), |
|
42 | ('svnrdump: E123456', 'UNKNOWN:svnrdump: E123456'), | |
43 | ], ids=['invalid-cert-stderr', 'svnrdump-err-123456']) |
|
43 | ], ids=['invalid-cert-stderr', 'svnrdump-err-123456']) | |
44 | @pytest.mark.xfail(sys.platform == "cygwin", |
|
44 | @pytest.mark.xfail(sys.platform == "cygwin", | |
45 | reason="SVN not packaged for Cygwin") |
|
45 | reason="SVN not packaged for Cygwin") | |
46 | def test_import_remote_repository_certificate_error(stderr, expected_reason): |
|
46 | def test_import_remote_repository_certificate_error(stderr, expected_reason): | |
47 | from vcsserver import svn |
|
47 | from vcsserver import svn | |
48 |
|
48 | |||
49 | remote = svn.SvnRemote(None) |
|
49 | remote = svn.SvnRemote(None) | |
50 | remote.is_path_valid_repository = lambda wire, path: True |
|
50 | remote.is_path_valid_repository = lambda wire, path: True | |
51 |
|
51 | |||
52 | with mock.patch('subprocess.Popen', |
|
52 | with mock.patch('subprocess.Popen', | |
53 | return_value=MockPopen(stderr)): |
|
53 | return_value=MockPopen(stderr)): | |
54 | with pytest.raises(Exception) as excinfo: |
|
54 | with pytest.raises(Exception) as excinfo: | |
55 | remote.import_remote_repository({'path': 'path'}, 'url') |
|
55 | remote.import_remote_repository({'path': 'path'}, 'url') | |
56 |
|
56 | |||
57 | expected_error_args = ( |
|
57 | expected_error_args = ( | |
58 | 'Failed to dump the remote repository from url.', |
|
58 | 'Failed to dump the remote repository from url. Reason:{}'.format(expected_reason),) | |
59 | expected_reason) |
|
|||
60 |
|
59 | |||
61 | assert excinfo.value.args == expected_error_args |
|
60 | assert excinfo.value.args == expected_error_args | |
62 |
|
61 | |||
63 |
|
62 | |||
64 | def test_svn_libraries_can_be_imported(): |
|
63 | def test_svn_libraries_can_be_imported(): | |
65 | import svn |
|
64 | import svn | |
66 | import svn.client |
|
65 | import svn.client | |
67 | assert svn.client is not None |
|
66 | assert svn.client is not None |
General Comments 0
You need to be logged in to leave comments.
Login now