Skip to content

Commit ea23e8e

Browse files
committed
MPT-18065 WIP
1 parent 1587b9e commit ea23e8e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

mpt_api_client/rql/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from mpt_api_client.rql.query_builder import RQLQuery
1+
from mpt_api_client.rql.query_builder import RQLQuery, Literal
22

3-
__all__ = ["RQLQuery"] # noqa: WPS410
3+
__all__ = ["RQLQuery", "Literal"] # noqa: WPS410

mpt_api_client/rql/query_builder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
Numeric = int | float | Decimal
88

9-
QueryValue = str | bool | dt.date | dt.datetime | Numeric
9+
class Literal:
10+
def __init__(self, value):
11+
self.value = value
1012

13+
def __str__(self):
14+
return f"'{self.value}'"
15+
16+
17+
QueryValue = str | bool | dt.date | dt.datetime | Numeric | Literal
1118

1219
def parse_kwargs(query_dict: dict[str, QueryValue]) -> list[str]: # noqa: WPS231
1320
"""
@@ -71,6 +78,7 @@ def query_value_str(value: QueryValue) -> str:
7178

7279
if isinstance(value, dt.date | dt.datetime):
7380
return value.isoformat()
81+
7482
# Matching: if isinstance(value, int | float | Decimal):
7583
return str(value)
7684

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from mpt_api_client.rql import RQLQuery, Literal
2+
3+
def test_compare_property():
4+
query = RQLQuery(agreement__product__id="order.product.id")
5+
6+
result = str(query)
7+
8+
assert result == "eq(agreement.product.id,order.product.id)"
9+
10+
def test_compare_quoted():
11+
query = RQLQuery(agreement__product__id=Literal("order.product.id"))
12+
13+
result = str(query)
14+
15+
assert result == "eq(agreement.product.id,'order.product.id')"
16+
17+
def test_ne_quoted():
18+
query = RQLQuery("agreement.product.id")
19+
20+
result = str(query.ne(Literal("order.product.id")))
21+
22+
assert result == "ne(agreement.product.id,'order.product.id')"

0 commit comments

Comments
 (0)