Exemplo n.º 1
0
    def setUp(self):
        self.handler = DigestHandler(mock.MagicMock(), mock.MagicMock())
        self.handler._start = time.time()
        self.handler.application.cache.get_av = mock.MagicMock()
        self.handler.finish = mock.MagicMock()
        self.handler.send_error = mock.MagicMock()

        # Mock out zmq so we don't fail if we try to report stats during the
        # test.
        self.real_zmq = base.zmq
        base.zmq = mock.MagicMock()
Exemplo n.º 2
0
class TestDigestHandler(unittest.TestCase):
    def setUp(self):
        self.handler = DigestHandler(mock.MagicMock(), mock.MagicMock())
        self.handler._start = time.time()
        self.handler.application.cache.get_av = mock.MagicMock()
        self.handler.finish = mock.MagicMock()
        self.handler.send_error = mock.MagicMock()

        # Mock out zmq so we don't fail if we try to report stats during the
        # test.
        self.real_zmq = base.zmq
        base.zmq = mock.MagicMock()

    def tearDown(self):
        base.zmq = self.real_zmq
        del self.real_zmq

    def test_cache_success_output(self):
        self.handler.application.cache.get_av.return_value = DigestAuthVector("ha1_test", None, None, True)
        self.handler.get("private_id")
        self.handler.finish.assert_called_once_with({"digest_ha1": "ha1_test"})

    def test_backend_success_output(self):
        self.handler.application.cache.get_av.return_value = None
        self.handler.application.backend.get_av.return_value = DigestAuthVector("ha1_test", None, None, True)
        self.handler.get("private_id")
        self.handler.finish.assert_called_once_with({"digest_ha1": "ha1_test"})

    def test_failure_output(self):
        self.handler.application.cache.get_av.return_value = None
        self.handler.application.backend.get_av.return_value = None
        self.handler.get("private_id")
        self.handler.send_error.assert_called_once_with(404)