From cbe6dd7401d11596818e97d55bfe85cdce179830 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Tue, 15 Mar 2016 13:20:43 -0400 Subject: [PATCH] Here's a test suite for slugize --- tests/py/test_teams.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/py/test_teams.py b/tests/py/test_teams.py index 47c1c1b874..d2c8ad9950 100644 --- a/tests/py/test_teams.py +++ b/tests/py/test_teams.py @@ -8,7 +8,7 @@ from aspen.testing.client import FileUpload from gratipay.testing import Harness -from gratipay.models.team import Team, AlreadyMigrated +from gratipay.models.team import Team, AlreadyMigrated, slugize, InvalidTeamName REVIEW_URL = "https://github.com/gratipay/test-gremlin/issues/9" @@ -495,3 +495,39 @@ def test_update_updates_object_attributes(self): team.update(name='Enterprise', product_or_service='We save galaxies.') assert team.name == 'Enterprise' assert team.product_or_service == 'We save galaxies.' + + + # slugize + + def test_slugize_slugizes(self): + assert slugize('Foo') == 'Foo' + + def test_slugize_requires_a_letter(self): + assert pytest.raises(InvalidTeamName, slugize, '123') + + def test_slugize_accepts_letter_in_middle(self): + assert slugize('1a23') == '1a23' + + def test_slugize_converts_comma_to_dash(self): + assert slugize('foo,bar') == 'foo-bar' + + def test_slugize_converts_space_to_dash(self): + assert slugize('foo bar') == 'foo-bar' + + def test_slugize_allows_underscore(self): + assert slugize('foo_bar') == 'foo_bar' + + def test_slugize_allows_period(self): + assert slugize('foo.bar') == 'foo.bar' + + def test_slugize_trims_whitespace(self): + assert slugize(' Foo Bar ') == 'Foo-Bar' + + def test_slugize_trims_dashes(self): + assert slugize('--Foo Bar--') == 'Foo-Bar' + + def test_slugize_trims_replacement_dashes(self): + assert slugize(',,Foo Bar,,') == 'Foo-Bar' + + def test_slugize_folds_dashes_together(self): + assert slugize('1a----------------23') == '1a-23'