Exemple #1
0
    def test_restlib_exception_uses_custom_message(self):
        expected_message = "Expected MESSAGE"
        mapper = ExceptionMapper()

        err = RestlibException(404, expected_message)
        self.assertEqual("HTTP error code 404: %s" % expected_message,
                         mapper.get_message(err))
 def test_restlib_exception_with_markup(self):
     exception_mapper = utils.GuiExceptionMapper()
     unescaped_input = '<a=3>&'
     bad_restlib_exception = RestlibException(404, unescaped_input)
     expected_output = '&lt;a=3&gt;&amp;'
     actual_output = exception_mapper.get_message(bad_restlib_exception)
     self.assertEqual(expected_output, actual_output)
Exemple #3
0
    def test_send_current_report_with_429(self, fromConfig, fromOptions,
                                          getLogger, time):
        initial = 0
        start_time = 0
        end_time = 2
        send_after_start_time = 0
        retry_after = 2
        expected_429_count = 1
        time.side_effect = [
            initial, initial, start_time, send_after_start_time
        ]

        fromOptions.return_value = Mock()
        options = Mock()
        options.interval = 6
        options.oneshot = True
        options.print_ = False
        options.log_dir = ''
        options.log_file = ''
        virtwho = VirtWho(Mock(), options, config_dir="/nonexistant")

        expected_queue_timeout = retry_after**expected_429_count
        expected_send_after = expected_queue_timeout + send_after_start_time

        config = Mock()
        config.hash = "config_hash"
        config.name = "config_name"
        virtwho.configs_ready.append(config)
        virtwho.reports_to_send[config.hash] = sentinel.report

        virtwho.send = Mock()
        virtwho.send.return_value = False
        virtwho.send.side_effect = RestlibException(
            "429", "429", {"Retry-After": retry_after})

        result_config, result_report = virtwho.send_current_report()

        self.assertEquals(expected_queue_timeout, virtwho.queue_timeout)
        self.assertEquals(expected_send_after, virtwho.send_after)
        self.assertEquals(result_config, config)
        self.assertEquals(None, result_report)
        self.assertEquals(len(virtwho.reports_to_send), 1)
        self.assertTrue(config in virtwho.configs_ready)
 def test_cache_fails_server_issues_gracefully(self):
     self.mock_uep.getAccessibleContent = Mock(side_effect=RestlibException(404))
     self.cache.check_for_update()
 def test_server_no_compliance_call(self):
     uep = Mock()
     uep.getCompliance = Mock(side_effect=RestlibException("boom"))
     status = self.status_cache.load_status(uep, "SOMEUUID")
     self.assertEqual(None, status)
    def test_server_no_release_call(self):
        uep = Mock()
        uep.getRelease = Mock(side_effect=RestlibException("boom"))

        status = self.release_cache.read_status(uep, "SOMEUUID")
        self.assertEqual(None, status)