Test cases for name_normalization

pull/550/head
kompotkot 2022-03-09 13:05:31 +00:00
rodzic b408c20b0b
commit 4412a5789a
3 zmienionych plików z 24 dodań i 1 usunięć

Wyświetl plik

@ -62,6 +62,7 @@ class NameNormalizationException(Exception):
Raised on actions when slugify can't normalize name.
"""
class ResourceQueryFetchException(Exception):
"""
Exception in queries API
@ -560,7 +561,9 @@ def name_normalization(query_name: str) -> str:
Sanitize provided query name.
"""
try:
normalized_query_name = slugify(query_name, max_length=50)
normalized_query_name = slugify(
query_name, max_length=50, lowercase=False, separator="_"
)
except Exception as e:
logger.error(f"Error in query normalization. Error: {e}")
raise NameNormalizationException(f"Can't normalize name:{query_name}")

Wyświetl plik

@ -33,6 +33,7 @@ router = APIRouter(
prefix="/queries",
)
@router.get("/list", tags=["queries"])
async def get_list_of_queries_handler(request: Request) -> List[Dict[str, Any]]:

Wyświetl plik

@ -0,0 +1,19 @@
import unittest
from . import actions
class TestActions(unittest.TestCase):
def test_name_normalization(self):
names = [
["test", "test"],
["test_Name", "test_Name"],
["%20UNION", "20UNION"],
["UNION ALL", "UNION_ALL"],
["$_REQUEST", "REQUEST"],
["id=1", "id_1"],
["Lo" * 30, "Lo" * 25],
]
for name in names:
query_name = actions.name_normalization(name[0])
self.assertEqual(query_name, name[1])