diff options
Diffstat (limited to 'tests/test_subcmds_upload.py')
-rw-r--r-- | tests/test_subcmds_upload.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test_subcmds_upload.py b/tests/test_subcmds_upload.py new file mode 100644 index 00000000..75811996 --- /dev/null +++ b/tests/test_subcmds_upload.py | |||
@@ -0,0 +1,69 @@ | |||
1 | # Copyright (C) 2023 The Android Open Source Project | ||
2 | # | ||
3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | # you may not use this file except in compliance with the License. | ||
5 | # You may obtain a copy of the License at | ||
6 | # | ||
7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | # | ||
9 | # Unless required by applicable law or agreed to in writing, software | ||
10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | # See the License for the specific language governing permissions and | ||
13 | # limitations under the License. | ||
14 | |||
15 | """Unittests for the subcmds/upload.py module.""" | ||
16 | |||
17 | import unittest | ||
18 | from unittest import mock | ||
19 | |||
20 | from subcmds import upload | ||
21 | from error import UploadError, GitError | ||
22 | |||
23 | |||
24 | class UnexpectedError(Exception): | ||
25 | """An exception not expected by upload command.""" | ||
26 | |||
27 | |||
28 | class UploadCommand(unittest.TestCase): | ||
29 | """Check registered all_commands.""" | ||
30 | |||
31 | def setUp(self): | ||
32 | self.cmd = upload.Upload() | ||
33 | self.branch = mock.MagicMock() | ||
34 | self.people = mock.MagicMock() | ||
35 | self.opt, _ = self.cmd.OptionParser.parse_args([]) | ||
36 | mock.patch.object( | ||
37 | self.cmd, "_AppendAutoList", return_value=None | ||
38 | ).start() | ||
39 | mock.patch.object(self.cmd, "git_event_log").start() | ||
40 | |||
41 | def tearDown(self): | ||
42 | mock.patch.stopall() | ||
43 | |||
44 | def test_UploadAndReport_UploadError(self): | ||
45 | """Check UploadExitError raised when UploadError encountered.""" | ||
46 | side_effect = UploadError("upload error") | ||
47 | with mock.patch.object( | ||
48 | self.cmd, "_UploadBranch", side_effect=side_effect | ||
49 | ): | ||
50 | with self.assertRaises(upload.UploadExitError): | ||
51 | self.cmd._UploadAndReport(self.opt, [self.branch], self.people) | ||
52 | |||
53 | def test_UploadAndReport_GitError(self): | ||
54 | """Check UploadExitError raised when GitError encountered.""" | ||
55 | side_effect = GitError("some git error") | ||
56 | with mock.patch.object( | ||
57 | self.cmd, "_UploadBranch", side_effect=side_effect | ||
58 | ): | ||
59 | with self.assertRaises(upload.UploadExitError): | ||
60 | self.cmd._UploadAndReport(self.opt, [self.branch], self.people) | ||
61 | |||
62 | def test_UploadAndReport_UnhandledError(self): | ||
63 | """Check UnexpectedError passed through.""" | ||
64 | side_effect = UnexpectedError("some os error") | ||
65 | with mock.patch.object( | ||
66 | self.cmd, "_UploadBranch", side_effect=side_effect | ||
67 | ): | ||
68 | with self.assertRaises(type(side_effect)): | ||
69 | self.cmd._UploadAndReport(self.opt, [self.branch], self.people) | ||