mock.call.decode

Here are the examples of the python api mock.call.decode taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: pyzor
Source File: test_digest.py
View license
    def test_text(self):
        mock_part, mock_msg, result = self.check_msg()
        self.assertEqual(result, ["decoded"])

        expected = [call.decode('utf8', 'ignore')]
        payload = mock_part.get_payload.return_value
        payload.assert_has_calls(expected, True)

Example 2

Project: pyzor
Source File: test_digest.py
View license
    def test_text_no_charset(self):
        self.config["get_content_charset.return_value"] = None
        mock_part, mock_msg, result = self.check_msg()
        self.assertEqual(result, ["decoded"])

        expected = [call.decode('ascii', 'ignore')]
        payload = mock_part.get_payload.return_value
        payload.assert_has_calls(expected)

Example 3

Project: pyzor
Source File: test_digest.py
View license
    def test_text_quopri(self):
        self.config["get_content_charset.return_value"] = "quopri"
        mock_part, mock_msg, result = self.check_msg()
        self.assertEqual(result, ["decoded"])

        expected = [call.decode('quopri', 'strict')]
        payload = mock_part.get_payload.return_value
        payload.assert_has_calls(expected)

Example 4

Project: pyzor
Source File: test_digest.py
View license
    def test_text_lookuperror(self):
        def _decode(encoding, errors):
            if encoding not in ("ascii",):
                raise LookupError()
            return "decoded"
        self.config["get_payload.return_value.decode.side_effect"] = _decode
        mock_part, mock_msg, result = self.check_msg()
        self.assertEqual(result, ["decoded"])

        expected = [call.decode('utf8', 'ignore'),
                    call.decode('ascii', 'ignore')]
        payload = mock_part.get_payload.return_value
        payload.assert_has_calls(expected)

Example 5

Project: pyzor
Source File: test_digest.py
View license
    def test_text_unicodeerror(self):
        self.config["get_payload.return_value.decode.side_effect"] = UnicodeError
        mock_part, mock_msg, result = self.check_msg()
        self.assertEqual(result, [])

        expected = [call.decode('utf8', 'ignore'),
                    call.decode('ascii', 'ignore')]
        payload = mock_part.get_payload.return_value
        payload.assert_has_calls(expected)