~doanac/ubuntu-ci-services-itself/lander-integration-bugs

« back to all changes in this revision

Viewing changes to cli/tests/test_cli.py

[r=Chris Johnston, PS Jenkins bot] Better error messages for the user in case ticket system server is down or unreachable or data store fails somehow  from Ursula Junque

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# You should have received a copy of the GNU General Public License along with
16
16
# this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
 
import os
19
 
import mock
20
18
import imp
 
19
import json
21
20
import logging
22
 
import json
 
21
import mock
 
22
import os
 
23
import socket
 
24
 
23
25
from testfixtures import LogCapture
 
26
from urllib2 import URLError
24
27
 
 
28
from ci_libs import utils
25
29
from ci_libs.ticket import new_ticket
26
30
from tests import (CLITestCase, capture_stderr, capture_stdout,
27
31
                   mock_load_config)
68
72
                cm)
69
73
        mock_urlopen.assert_called_once()
70
74
 
 
75
    @mock.patch('urllib2.urlopen')
 
76
    @mock.patch('ci_libs.utils.load_config', side_effect=mock_load_config())
 
77
    def test_ticket_status_server_unreachable(self, mock_load_config,
 
78
                                              mock_urlopen):
 
79
        mock_urlopen.side_effect = URLError(reason=socket.error(111,
 
80
                                            "Connection refused"))
 
81
        args = ['status']
 
82
        with LogCapture() as lc:
 
83
            logger = logging.getLogger()
 
84
            self.cli.main(args, log=logger)
 
85
        mock_urlopen.assert_called_once()
 
86
        self.assertTrue("Cannot reach the server at %s." % utils.CI_URL in
 
87
                        lc.records[0].msg)
 
88
        self.assertTrue("Connection refused" in lc.records[0].msg)
 
89
 
71
90
    @mock.patch('ci_libs.ticket.SubTicket._process')
72
91
    @mock.patch('ci_libs.utils.post',
73
92
                return_value='http://www.example.com/api/v1/ticket/38/')