server/misc: add icase_unique

This commit is contained in:
rr- 2016-04-15 22:49:55 +02:00
parent 063b0c4799
commit 025dff62dd
2 changed files with 20 additions and 0 deletions

View file

@ -28,3 +28,14 @@ def test_parsing_empty_date_time():
def test_parsing_date_time(input, output):
misc.datetime.datetime = FakeDatetime
assert misc.parse_time_range(input) == output
@pytest.mark.parametrize('input,output', [
([], []),
(['a', 'b', 'c'], ['a', 'b', 'c']),
(['a', 'b', 'a'], ['a', 'b']),
(['a', 'a', 'b'], ['a', 'b']),
(['a', 'A', 'b'], ['a', 'b']),
(['a', 'A', 'b', 'B'], ['a', 'b']),
])
def test_icase_unique(input, output):
assert misc.icase_unique(input) == output

View file

@ -61,3 +61,12 @@ def parse_time_range(value, timezone=datetime.timezone(datetime.timedelta())):
datetime.datetime(year, month, day + 1) - one_second)
raise ValidationError('Invalid date format: %r.' % value)
def icase_unique(source):
target = []
target_low = []
for source_item in source:
if source_item.lower() not in target_low:
target.append(source_item)
target_low.append(source_item.lower())
return target