Beispiel #1
0
    def test_validate_failed(self):
        message = '[]'
        authenticator = Mock()
        authenticator.validate.side_effect = ValidationFailed

        # functional test
        try:
            validate(authenticator, message)
            self.assertTrue(False, msg='validation exception expected')
        except ValidationFailed, e:
            self.assertEqual(e.document, message)
Beispiel #2
0
    def test_validate_exception(self):
        message = '[]'
        reason = 'this is bad'
        authenticator = Mock()
        authenticator.validate.side_effect = ValueError(reason)

        # functional test
        try:
            validate(authenticator, message)
            self.assertTrue(False, msg='validation exception expected')
        except ValidationFailed, e:
            self.assertEqual(e.details, reason)
            self.assertEqual(e.document, message)
Beispiel #3
0
    def test_validate(self, decode):
        signature = 'S0xBSkRGOTg4Ug=='
        message = '{"message": "{\\"A\\":1}", "signature": "%s"}' % signature
        authenticator = Mock()

        # functional test
        validated = validate(authenticator, message)

        # validation
        decode.assert_called_once_with(signature)
        self.assertEqual(1, validated['A'])
Beispiel #4
0
    def test_validate(self, decode):
        signature = 'S0xBSkRGOTg4Ug=='
        message = '{"message": "{\\"A\\":1}", "signature": "%s"}' % signature
        authenticator = Mock()

        # functional test
        validated = validate(authenticator, message)

        # validation
        decode.assert_called_once_with(signature)
        self.assertEqual(1, validated['A'])
Beispiel #5
0
 def next(self, timeout=90):
     """
     Get the next valid *document* from the queue.
     :param timeout: The read timeout in seconds.
     :type timeout: int
     :return: The next document.
     :rtype: tuple: (Message, Document)
     :raises: model.DocumentError
     """
     message = self.get(timeout)
     if message:
         try:
             document = auth.validate(self.authenticator, message.body)
             validate(document)
         except ModelError:
             message.ack()
             raise
         log.debug('read next: %s', document)
         return message, document
     else:
         return None, None
Beispiel #6
0
 def test_no_message(self, _document):
     validated = validate(None, None)
     self.assertEqual(validated, _document.return_value)
Beispiel #7
0
 def test_no_message(self):
     validated = validate(None, None)
     self.assertEqual(validated, None)
Beispiel #8
0
 def test_no_message(self, _document):
     validated = validate(None, None)
     self.assertEqual(validated, _document.return_value)