kopia lustrzana https://github.com/bugout-dev/moonstream
Test cases for name_normalization
rodzic
b408c20b0b
commit
4412a5789a
|
@ -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}")
|
||||
|
|
|
@ -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]]:
|
||||
|
||||
|
|
|
@ -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])
|
Ładowanie…
Reference in New Issue