Skip to content

Commit

Permalink
Merge 4d792b5 into 21065f6
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Jan 30, 2018
2 parents 21065f6 + 4d792b5 commit 719b69b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions miio/click_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


def validate_ip(ctx, param, value):
if value is None:
return None
try:
ipaddress.ip_address(value)
return value
Expand All @@ -25,6 +27,8 @@ def validate_ip(ctx, param, value):


def validate_token(ctx, param, value):
if value is None:
return None
token_len = len(value)
if token_len != 32:
raise click.BadParameter("Token length != 32 chars: %s" % token_len)
Expand Down
10 changes: 10 additions & 0 deletions miio/tests/test_click_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from miio.click_common import validate_token, validate_ip


def test_validate_token_empty():
assert not validate_token(None, None, None)


def test_validate_ip_empty():
assert validate_ip(None, None, None) is None

0 comments on commit 719b69b

Please sign in to comment.