| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# aioimaplib : an IMAPrev4 lib using python asyncio |
| 3 |
# Copyright (C) 2016 Bruno Thomas |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
import pytest |
| 18 |
from unittest import TestCase |
| 19 |
from aioimaplib import quoted, arguments_rfs2971, ID_MAX_FIELD_LEN, ID_MAX_VALUE_LEN |
| 20 |
|
| 21 |
|
| 22 |
class TestQuote(TestCase): |
| 23 |
def test_quote_encloses_string_in_dquote_character(self): |
| 24 |
assert '"hello"' == quoted('hello') |
| 25 |
|
| 26 |
def test_quote_escapes_dquote_character(self): |
| 27 |
assert '"hello\\"world"' == quoted('hello"world') |
| 28 |
|
| 29 |
def test_quote_escapes_backlash_character(self): |
| 30 |
assert '"hello\\\\world"' == quoted('hello\\world') |
| 31 |
|
| 32 |
def test_quote_returns_str_when_input_is_str(self): |
| 33 |
assert isinstance(quoted('hello'), str) |
| 34 |
|
| 35 |
|
| 36 |
class TestArgument(TestCase): |
| 37 |
def test_arguments_rfs2971_empty(self): |
| 38 |
assert ['NIL'] == arguments_rfs2971() |
| 39 |
|
| 40 |
def test_arguments_rfs2971_with_kwargs(self): |
| 41 |
assert ['(', '"name"', '"test"', ')'] == arguments_rfs2971(name='test') |
| 42 |
|
| 43 |
def test_arguments_rfs2971_with_max_items(self): |
| 44 |
with pytest.raises(ValueError): |
| 45 |
fields = range(31) |
| 46 |
arguments_rfs2971(**{str(field): field for field in fields}) |
| 47 |
|
| 48 |
def test_arguments_rfs2971_with_max_field_length(self): |
| 49 |
with pytest.raises(ValueError): |
| 50 |
field = 'test' * (ID_MAX_FIELD_LEN + 1) |
| 51 |
arguments_rfs2971(**{field: 'test'}) |
| 52 |
|
| 53 |
def test_arguments_rfs2971_with_max_value_length(self): |
| 54 |
with pytest.raises(ValueError): |
| 55 |
value = 'test' * (ID_MAX_VALUE_LEN + 1) |
| 56 |
arguments_rfs2971(field=value) |