Tester for url increment/decrement with zeroes

This commit is contained in:
Michael Ilsaas 2016-01-20 19:38:03 +01:00
parent d6cda0ed27
commit c33e9555a1
2 changed files with 29 additions and 1 deletions

View File

@ -528,7 +528,7 @@ def incdec_number(url, incdec, segments=None):
if len(number) < len(str(val)):
zeroes = zeroes[1:]
if len(number) > len(str(val)):
zeroes = ''.join([zeroes,'0'])
zeroes = ''.join([zeroes, '0'])
new_value = ''.join([pre, zeroes, str(val), post])
setter(new_value)

View File

@ -586,6 +586,34 @@ class TestIncDecNumber:
base_url, incdec, segments={'host', 'path', 'query', 'anchor'})
assert new_url == expected_url
@pytest.mark.parametrize('number, expected', [
('01', '02'),
('09', '10'),
('009', '010')
])
def test_increment_leading_zeroes(self, number, expected):
"""Test incdec_number with leading zeroes."""
url = 'http://example.com/{}'
base_url = QUrl(url.format(number))
expected_url = QUrl(url.format(expected))
new_url = urlutils.incdec_number(
base_url, 'increment', segments={'path'})
assert new_url == expected_url
@pytest.mark.parametrize('number, expected', [
('02', '01'),
('10', '9'),
('010', '009')
])
def test_decrement_leading_zeroes(self, number, expected):
"""Test incdec_number with leading zeroes."""
url = 'http://example.com/{}'
base_url = QUrl(url.format(number))
expected_url = QUrl(url.format(expected))
new_url = urlutils.incdec_number(
base_url, 'increment', segments={'path'})
assert new_url == expected_url
@pytest.mark.parametrize('url, segments, expected', [
('http://ex4mple.com/test_4?page=3#anchor2', {'host'},
'http://ex5mple.com/test_4?page=3#anchor2'),