Move remaining util tests into pytest
This commit is contained in:
parent
fa354d695a
commit
69406c6aec
4 changed files with 198 additions and 226 deletions
20
util/test/test_util.py
Normal file
20
util/test/test_util.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import pytest
|
||||
|
||||
from util import slash_join
|
||||
|
||||
@pytest.mark.parametrize('pieces, expected', [
|
||||
(['https://github.com', '/coreos-inc/' 'quay/pull/1092/files'],
|
||||
'https://github.com/coreos-inc/quay/pull/1092/files'),
|
||||
|
||||
(['https://', 'github.com/', '/coreos-inc', '/quay/pull/1092/files/'],
|
||||
'https://github.com/coreos-inc/quay/pull/1092/files'),
|
||||
|
||||
(['https://somegithub.com/', '/api/v3/'],
|
||||
'https://somegithub.com/api/v3'),
|
||||
|
||||
(['https://github.somedomain.com/', '/api/v3/'],
|
||||
'https://github.somedomain.com/api/v3'),
|
||||
])
|
||||
def test_slash_join(pieces, expected):
|
||||
joined_url = slash_join(*pieces)
|
||||
assert joined_url == expected
|
|
@ -1,6 +1,32 @@
|
|||
from itertools import islice
|
||||
|
||||
import pytest
|
||||
|
||||
from util.validation import is_json, validate_label_key
|
||||
from util.validation import is_json, validate_label_key, generate_valid_usernames, validate_username
|
||||
|
||||
@pytest.mark.parametrize('username, is_valid', [
|
||||
('ja', True),
|
||||
('jak', True),
|
||||
('jake', True),
|
||||
('ja_ke', True),
|
||||
('te-st', True),
|
||||
('te.st', True),
|
||||
|
||||
('z' * 30, True),
|
||||
('z' * 255, True),
|
||||
|
||||
('j', False),
|
||||
|
||||
('z' * 256, False),
|
||||
|
||||
('_test', False),
|
||||
('Test', False),
|
||||
('hello world', False),
|
||||
('te---st', False),
|
||||
])
|
||||
def test_validate_username(username, is_valid):
|
||||
valid, _ = validate_username(username)
|
||||
assert valid == is_valid
|
||||
|
||||
|
||||
@pytest.mark.parametrize('string_value,expected', [
|
||||
|
@ -48,3 +74,56 @@ def test_is_json(string_value, expected):
|
|||
])
|
||||
def test_validate_label_key(key, is_valid):
|
||||
assert validate_label_key(key) == is_valid
|
||||
|
||||
|
||||
@pytest.mark.parametrize('input_username, expected_output', [
|
||||
('jake', 'jake'),
|
||||
('frank', 'frank'),
|
||||
('fra-nk', 'fra_nk'),
|
||||
|
||||
('Jake', 'jake'),
|
||||
('FranK', 'frank'),
|
||||
|
||||
('ja__ke', 'ja_ke'),
|
||||
('ja___ke', 'ja_ke'),
|
||||
|
||||
('ja__', 'ja'),
|
||||
('jake__', 'jake'),
|
||||
|
||||
('_jake', 'jake'),
|
||||
|
||||
('a', 'a0'),
|
||||
('ab', 'ab'),
|
||||
('abc', 'abc'),
|
||||
|
||||
('abcdefghijklmnopqrstuvwxyz1234567890', 'abcdefghijklmnopqrstuvwxyz1234567890'),
|
||||
('c' * 256, 'c' * 255),
|
||||
|
||||
(u'\xc6neid', 'aeneid'),
|
||||
(u'\xe9tude', 'etude'),
|
||||
(u'\u5317\u4eb0', 'bei_jing'),
|
||||
(u'\u1515\u14c7\u14c7', 'shanana'),
|
||||
(u'\u13d4\u13b5\u13c6', 'taliqua'),
|
||||
(u'\u0726\u071b\u073d\u0710\u073a', 'ptu_i'),
|
||||
(u'\u0905\u092d\u093f\u091c\u0940\u0924', 'abhijiit'),
|
||||
(u'\u0985\u09ad\u09bf\u099c\u09c0\u09a4', 'abhijiit'),
|
||||
(u'\u0d05\u0d2d\u0d3f\u0d1c\u0d40\u0d24', 'abhijiit'),
|
||||
(u'\u0d2e\u0d32\u0d2f\u0d3e\u0d32\u0d2e\u0d4d', 'mlyaalm'),
|
||||
(u'\ue000', '00'),
|
||||
(u'\u03ff', '00'),
|
||||
|
||||
(u'\u0d2e\u0d32\u03ff\u03ff\u0d2e\u0d32', 'mlml'),
|
||||
])
|
||||
def test_generate_valid_usernames(input_username, expected_output):
|
||||
name_gen = generate_valid_usernames(input_username)
|
||||
generated_output = list(islice(name_gen, 1))[0]
|
||||
assert generated_output == expected_output
|
||||
|
||||
|
||||
def test_multiple_suggestions():
|
||||
name_gen = generate_valid_usernames('a')
|
||||
generated_output = list(islice(name_gen, 4))
|
||||
assert generated_output[0] == 'a0'
|
||||
assert generated_output[1] == 'a1'
|
||||
assert generated_output[2] == 'a2'
|
||||
assert generated_output[3] == 'a3'
|
||||
|
|
Reference in a new issue