From d07ad6aa4091c318dc62ac41975ef0590ce11f2c Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Wed, 4 Jul 2018 12:38:11 +0200 Subject: Allow numbers in channel names. --- pysite/views/api/bot/off_topic_names.py | 2 +- tests/test_api_bot_off_topic_names.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pysite/views/api/bot/off_topic_names.py b/pysite/views/api/bot/off_topic_names.py index e0871067..f353ab02 100644 --- a/pysite/views/api/bot/off_topic_names.py +++ b/pysite/views/api/bot/off_topic_names.py @@ -13,7 +13,7 @@ POST_SCHEMA = Schema({ 'name': And( str, len, - lambda name: all(c.isalpha() or c == '-' for c in name), + lambda name: all(c.isalnum() or c == '-' for c in name), str.islower, lambda name: len(name) <= 96, error=( diff --git a/tests/test_api_bot_off_topic_names.py b/tests/test_api_bot_off_topic_names.py index 4c9c782b..74146bc5 100644 --- a/tests/test_api_bot_off_topic_names.py +++ b/tests/test_api_bot_off_topic_names.py @@ -36,7 +36,7 @@ class AddingANameOffTopicEndpointTests(SiteTest): self.assert200(response) -class AddingChannelNameToDatabaseEndpointTests(SiteTest): +class AddingChannelNamesToDatabaseEndpointTests(SiteTest): """Tests fetching names from the database with GET.""" CHANNEL_NAME = 'bisks-disks' @@ -58,6 +58,14 @@ class AddingChannelNameToDatabaseEndpointTests(SiteTest): self.assert200(response) self.assertIn(self.CHANNEL_NAME, response.json) + def test_allows_numbers_in_names(self): + response = self.client.post( + f'/bot/off-topic-names?name=totallynot42', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + class RandomSampleEndpointTests(SiteTest): """Tests fetching random names from the website with GET.""" -- cgit v1.2.3 From ae96901fee1653b35f5494a8d546cd768edd1e77 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 8 Jul 2018 01:42:11 +0200 Subject: Fix duplicate channel names in test. --- tests/test_api_bot_off_topic_names.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_api_bot_off_topic_names.py b/tests/test_api_bot_off_topic_names.py index 74146bc5..f0d0fe3e 100644 --- a/tests/test_api_bot_off_topic_names.py +++ b/tests/test_api_bot_off_topic_names.py @@ -58,6 +58,10 @@ class AddingChannelNamesToDatabaseEndpointTests(SiteTest): self.assert200(response) self.assertIn(self.CHANNEL_NAME, response.json) + +class AllowsNumbersInNames(SiteTest): + """Tests that the site allows names with numbers in them.""" + def test_allows_numbers_in_names(self): response = self.client.post( f'/bot/off-topic-names?name=totallynot42', -- cgit v1.2.3