summaryrefslogtreecommitdiff
path: root/test/test_substription_state.py
blob: 9718f6af4614894c8237024b9a0eb4060899d61b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# pylint: skip-file
from __future__ import absolute_import

import pytest

from kafka.consumer.subscription_state import SubscriptionState

@pytest.mark.parametrize(('topic_name', 'expectation'), [
    (0, pytest.raises(TypeError)),
    (None, pytest.raises(TypeError)),
    ('', pytest.raises(ValueError)),
    ('.', pytest.raises(ValueError)),
    ('..', pytest.raises(ValueError)),
    ('a' * 250, pytest.raises(ValueError)),
    ('abc/123', pytest.raises(ValueError)),
    ('/abc/123', pytest.raises(ValueError)),
    ('/abc123', pytest.raises(ValueError)),
    ('name with space', pytest.raises(ValueError)),
    ('name*with*stars', pytest.raises(ValueError)),
    ('name+with+plus', pytest.raises(ValueError)),
])
def test_topic_name_validation(topic_name, expectation):
    state = SubscriptionState()
    with expectation:
        state._ensure_valid_topic_name(topic_name)