Пример #1
0
    def test_main_with_url_error(self, mock_print):
        args = '-H localhost'.split(' ')

        with self.assertRaises(SystemExit) as test:
            main(args)

        self.assertTrue('URLError' in str(mock_print.call_args))
        self.assertEqual(test.exception.code, 3)
Пример #2
0
    def test_main_version(self, mock_print):
        args = ['--version']

        with self.assertRaises(SystemExit) as test:
            main(args)

        mock_print.assert_called_once()
        self.assertEqual(test.exception.code, 0)
Пример #3
0
    def test_main_with_http_error_valid_json(self, mock_request, mock_print):
        args = '-H localhost'.split(' ')

        mock_request.return_value = MockResponse(status_code=503)

        with self.assertRaises(SystemExit) as test:
            main(args)

        self.assertEqual(test.exception.code, 0)
Пример #4
0
    def test_main_with_ssl(self, mock_request, mock_print):
        args = '-H localhost --ssl'.split(' ')

        mock_request.return_value = MockResponse()

        with self.assertRaises(SystemExit) as test:
            main(args)

        self.assertEqual(test.exception.code, 0)
Пример #5
0
    def test_main_with_parse_error(self, mock_request, mock_print):
        args = '-H localhost'.split(' ')

        mock_request.return_value = MockResponse(content='not JSON')

        with self.assertRaises(SystemExit) as test:
            main(args)

        self.assertTrue('Parser error' in str(mock_print.call_args))
        self.assertEqual(test.exception.code, 3)