Skip to content

Commit 5f310e6

Browse files
committed
MPT-18065 WIP - Fix backward incompatible issues related to RQL: Support of property comparison
1 parent 1587b9e commit 5f310e6

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-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 Literal, RQLQuery
22

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

mpt_api_client/rql/query_builder.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66

77
Numeric = int | float | Decimal
88

9-
QueryValue = str | bool | dt.date | dt.datetime | Numeric
9+
10+
class Literal:
11+
"""Wrapper for literal values in RQL queries."""
12+
13+
def __init__(self, value: str):
14+
self.value = value
15+
16+
@override
17+
def __str__(self) -> str:
18+
return f"'{self.value}'"
19+
20+
21+
QueryValue = str | bool | dt.date | dt.datetime | Numeric | Literal # noqa: WPS221
1022

1123

1224
def parse_kwargs(query_dict: dict[str, QueryValue]) -> list[str]: # noqa: WPS231
@@ -71,6 +83,7 @@ def query_value_str(value: QueryValue) -> str:
7183

7284
if isinstance(value, dt.date | dt.datetime):
7385
return value.isoformat()
86+
7487
# Matching: if isinstance(value, int | float | Decimal):
7588
return str(value)
7689

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

0 commit comments

Comments
 (0)