2018-06-09 02:35:44 +03:00
|
|
|
import pytest
|
2018-07-19 20:51:47 +03:00
|
|
|
|
2018-06-09 02:35:44 +03:00
|
|
|
from iotedgedev.azurecli import get_query_argument_for_id_and_name
|
|
|
|
|
2018-06-29 21:12:00 +03:00
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
2018-07-19 20:51:47 +03:00
|
|
|
|
2018-06-09 02:35:44 +03:00
|
|
|
def get_terms(query):
|
2018-07-19 20:51:47 +03:00
|
|
|
# These tests are all asserting that the query contains two terms enclosed in
|
|
|
|
# [?], separated by ||
|
|
|
|
# They don't care about the order. Tests will fail if the square brackets and ||
|
2018-06-09 02:35:44 +03:00
|
|
|
# contract is violated, but we'd want them to fail in that case.
|
|
|
|
return query[2:len(query)-1].split(" || ")
|
|
|
|
|
2018-07-19 20:51:47 +03:00
|
|
|
|
2018-06-09 02:35:44 +03:00
|
|
|
def test_lowercase_token_should_be_lowercase_for_name_and_id():
|
|
|
|
token = "abc123"
|
|
|
|
query = get_query_argument_for_id_and_name(token)
|
|
|
|
terms = get_terms(query)
|
|
|
|
|
|
|
|
assert len(terms) == 2
|
2018-07-19 20:51:47 +03:00
|
|
|
assert "starts_with(@.id,'abc123')" in terms
|
2018-06-11 18:53:20 +03:00
|
|
|
assert "contains(@.name,'abc123')" in terms
|
2018-06-09 02:35:44 +03:00
|
|
|
|
2018-07-19 20:51:47 +03:00
|
|
|
|
2018-06-09 02:35:44 +03:00
|
|
|
def test_mixedcase_token_should_be_lowercase_for_id_but_unmodified_for_name():
|
|
|
|
token = "AbC123"
|
|
|
|
query = get_query_argument_for_id_and_name(token)
|
|
|
|
terms = get_terms(query)
|
|
|
|
|
|
|
|
assert len(terms) == 2
|
2018-07-19 20:51:47 +03:00
|
|
|
assert "starts_with(@.id,'abc123')" in terms
|
|
|
|
assert "contains(@.name,'AbC123')" in terms
|