From 30ba2c1dbd22eff5f202bbbf2ecd8b42d242b1b0 Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Sat, 7 Oct 2017 23:43:29 +0200 Subject: Add method to ensure a valid topic name (#1238) --- test/test_substription_state.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/test_substription_state.py (limited to 'test') diff --git a/test/test_substription_state.py b/test/test_substription_state.py new file mode 100644 index 0000000..9718f6a --- /dev/null +++ b/test/test_substription_state.py @@ -0,0 +1,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) -- cgit v1.2.1