todoist-taskwarrior/tests/test_validation.py

37 lines
1.1 KiB
Python
Raw Normal View History

2019-03-30 18:34:29 +01:00
""" Validation Tests
Test argument/option validations
"""
import click
import pytest
from todoist_taskwarrior import validation
2019-03-30 18:34:29 +01:00
def validate(fn, value):
"""Calls the validation with None for `ctx` and `param`.
Note: This could definitely be an issue for validations that
use either param, but at the moment it's a simplification
which works.
"""
return fn(None, None, value)
def test_validate_map():
2019-03-30 18:34:29 +01:00
# Simple
assert validate(validation.validate_map, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'}
2019-03-30 18:34:29 +01:00
# Missing DST
assert validate(validation.validate_map, ('HELLO=',)) == {'HELLO': None}
2019-03-30 18:34:29 +01:00
# Multiple
assert validate(validation.validate_map, ('FOO=BAR', 'BAR=BAZZ')) == {'FOO': 'BAR', 'BAR': 'BAZZ'}
2019-03-30 18:34:29 +01:00
# Invalid, no '='
with pytest.raises(click.BadParameter):
assert validate(validation.validate_map, ('FOO',)) == None
2019-03-30 18:34:29 +01:00
2019-06-21 01:25:14 +02:00
# Hierarchical src
assert validate(validation.validate_map, ('foo.bar=bazz',)) == {'foo.bar': 'bazz'}
assert validate(validation.validate_map, ('foo bar.bazz=bazz',)) == {'foo bar.bazz': 'bazz'}