Skip to content

Commit 3a8c9b8

Browse files
committed
Fix faulty tests
1 parent c679571 commit 3a8c9b8

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/PRIP/prip_station_mock.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def query_products():
6969
cond['op'],
7070
cond['value']
7171
)
72-
72+
if not products:
73+
# If a search doesn't return products, then the whole search result is empty
74+
return Response(status=HTTPStatus.OK, response=json.dumps({"value": []}))
7375
# store only id of the result
7476
ids = {p['Id'] for p in products}
7577
all_id_sets.append(ids)
@@ -91,14 +93,16 @@ def query_products():
9193
def process_products(field, op, value) -> Response:
9294
# handle special case:
9395
match field:
94-
case "Name":
96+
case "Name" | "Online":
9597
match op.lower():
9698
case "contains":
9799
results = [product for product in data if value in product[field]]
98100
case "startswith":
99101
results = [product for product in data if product[field].startswith(value)]
100102
case "endswith":
101103
results = [product for product in data if product[field].endswith(value)]
104+
case "eq":
105+
results = [product for product in data if str(product[field]).lower() == str(value).lower()]
102106
case _:
103107
return []
104108
return results

src/PRIP/tests/test_prip_station_mock.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
("/Products?$filter=endswith(Name, 'INVALID')&$expand=Attributes", None),
1515
("/Products?$filter=startswith(Name, 'S1A_IW') and endswith(Name, 'SAFE.zip')&$expand=Attributes", PRIP_PRODUCT),
1616
("/Products?$filter=contains(Name, 'IW_RAW__0NSH') and endswith(Name, 'SAFE.zip')&$expand=Attributes", PRIP_PRODUCT),
17-
#("/Products?$filter=startswith(Name, 'INVALID') and endswith(Name, 'SAFE.zip')&$expand=Attributes", None),
17+
("/Products?$filter=startswith(Name, 'INVALID') and endswith(Name, 'SAFE.zip')&$expand=Attributes", None),
1818
("/Products?$filter=startswith(Name, 'S1A_IW') and endswith(Name, 'INVALID')&$expand=Attributes", None),
1919
("/Products?$filter=EvictionDate eq 9999-12-31T23:59:59.999Z&$expand=Attributes", PRIP_PRODUCT),
2020
("/Products?$filter=ModificationDate eq 2022-06-26T06:30:34.558Z&$expand=Attributes", PRIP_PRODUCT),
2121
("/Products?$filter=OriginDate eq 2022-06-26T06:14:55.468Z&$expand=Attributes", PRIP_PRODUCT),
2222
("/Products?$filter=PublicationDate eq 2022-06-26T06:30:34.558Z&$expand=Attributes", PRIP_PRODUCT),
23-
#("/Products?$filter=Online eq true&$expand=Attributes", PRIP_PRODUCT),
23+
("/Products?$filter=Online eq true&$expand=Attributes", PRIP_PRODUCT),
2424
("/Products?$filter=ContentDate/Start eq 2022-06-26T05:05:33.863Z&$expand=Attributes", PRIP_PRODUCT),
2525
("/Products?$filter=ContentDate/End eq 2022-06-26T05:10:38.849Z&$expand=Attributes", PRIP_PRODUCT),
2626
("/Products?$filter=OData.CSC.Intersects(area=geography'SRID=4326;POLYGON((-60 0,-62 -10,-58 -10,-56 0,-60 0))')&$expand=Attributes", PRIP_PRODUCT),
@@ -67,7 +67,6 @@
6767
("/Products?$filter=contains(Name, 'IW_RAW__0NSH') and endswith(Name, 'SAFE.zip')&$expand=Attributes", PRIP_PRODUCT),
6868
("/Products?$filter=startswith(Name, 'S1A_IW') and ContentDate/End eq 2022-06-26T05:10:38.849Z and orbitDirection eq 'ASCENDING'&$expand=Attributes", PRIP_PRODUCT),
6969
("/Products?$filter=cycleNumber eq 265 and productType eq 'IW_RAW__0N' and orbitDirection eq 'ASCENDING'&$expand=Attributes", PRIP_PRODUCT),
70-
#("/Products?$filter=orbitNumber eq 43829 and relativeOrbitNumber eq 43829&$expand=Attributes", PRIP_PRODUCT),
7170
("/Products?$filter=instrumentShortName eq 'SAR' and platformShortName eq 'SENTINEL-1' and platformSerialIdentifier eq 'A'&$expand=Attributes", PRIP_PRODUCT),
7271
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'productClass' and att/OData.CSC.StringAttribute/Value eq 'N') and Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'productType' and att/OData.CSC.StringAttribute/Value eq 'IW_RAW__0N')&$expand=Attributes", PRIP_PRODUCT),
7372
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'platformShortName' and att/OData.CSC.StringAttribute/Value eq 'INVALID')&$expand=Attributes", None),
@@ -81,7 +80,7 @@
8180
("/Products?$filter=startswith(Name, 'S1A_IW') and Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'datatakeID' and att/OData.CSC.StringAttribute/Value eq '000000')&$expand=Attributes", None),
8281
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'coordinates' and att/OData.CSC.StringAttribute/Value eq 'INVALID')&$expand=Attributes", None),
8382
("/Products?$filter=orbitNumber eq 99999 and cycleNumber eq 999&$expand=Attributes", None),
84-
#("/Products?$filter=originDate eq 2000-01-01T00:00:00.000Z&$expand=Attributes", None),
83+
("/Products?$filter=OriginDate eq 2000-01-01T00:00:00.000Z&$expand=Attributes", None),
8584
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'sliceProductFlag' and att/OData.CSC.StringAttribute/Value eq 'INVALID')&$expand=Attributes", None),
8685
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'instrumentConfigurationID' and att/OData.CSC.StringAttribute/Value eq '999')&$expand=Attributes", None),
8786
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'startTimeFromAscendingNode' and att/OData.CSC.StringAttribute/Value eq '9999999')&$expand=Attributes", None),
@@ -90,12 +89,10 @@
9089
("/Products?$filter=startswith(Name, 'S1A_IW') and endswith(Name, 'INVALID')&$expand=Attributes", None),
9190
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'processingCenter' and att/OData.CSC.StringAttribute/Value eq 'INVALID') and processingDate eq 2000-01-01T00:00:00.000Z&$expand=Attributes", None),
9291
("/Products?$filter=OData.CSC.Intersects(area=geography'SRID=4326;POLYGON((-80 40,-82 30,-78 30,-76 40,-80 40))')&$expand=Attributes", None),
93-
#("/Products?$filter=contains(Name, 'INVALID') and endswith(Name, 'SAFE.zip')&$expand=Attributes", None),
92+
("/Products?$filter=contains(Name, 'INVALID') and endswith(Name, 'SAFE.zip')&$expand=Attributes", None),
9493
("/Products?$filter=orbitNumber eq 123 and productType eq 'INVALID' and platformSerialIdentifier eq 'Z'&$expand=Attributes", None),
9594
("/Products?$filter=Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'orbitDirection' and att/OData.CSC.StringAttribute/Value eq 'INVALID') and Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'productConsolidation' and att/OData.CSC.StringAttribute/Value eq 'INVALID')&$expand=Attributes", None),
9695
("/Products?$filter=ContentDate/Start eq 2000-01-01T00:00:00.000Z&$expand=Attributes", None),
97-
98-
9996
])
10097
def test_query_products(prip_client, url, response):
10198
assert prip_client.get(url).status_code == HTTPStatus.OK # Should return all products

src/common/odata_lexer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from odata_query.grammar import ODataLexer, ODataParser
22
from odata_query.visitor import NodeVisitor
3-
from odata_query.ast import *
3+
from odata_query.ast import String, DateTime, Boolean, Compare, Identifier, Attribute, BoolOp, Call, CollectionLambda
44

55

66
class FilterExtractor(NodeVisitor):
@@ -21,7 +21,7 @@ def _get_attr_path(self, node):
2121
"""
2222
Recursively constructs the full attribute path from AST nodes.
2323
24-
For example, given nodes representing ContentDate and Start, it returns 'ContentDate/Start'.
24+
ContentDate['Start'] -> 'ContentDate/Start'.
2525
2626
Args:
2727
node (Attribute | Identifier): The AST node representing an attribute or identifier.
@@ -53,7 +53,8 @@ def visit_Compare(self, node: Compare):
5353
"""
5454
attr_path = self._get_attr_path(node.left)
5555
# Only handle comparisons where right side is a string or datetime literal
56-
if isinstance(node.right, (String, DateTime)):
56+
57+
if isinstance(node.right, (String, DateTime, Boolean)):
5758
cond = {
5859
"op": type(node.comparator).__name__,
5960
"value": node.right.val
@@ -119,7 +120,7 @@ def visit_CollectionLambda(self, node: CollectionLambda):
119120
Visits collection lambda expressions (e.g. any() in OData).
120121
121122
Specifically extracts key-value pairs from lambdas that compare 'Name' and 'Value' properties,
122-
such as:
123+
123124
any(att: att/Name eq 'productType' and att/Value eq 'MSI_L1C_TL')
124125
125126
Args:
@@ -154,7 +155,6 @@ def extract_key_and_value(expr):
154155
}
155156

156157
else:
157-
# For other lambda expressions, recurse into the expression
158158
self.visit(node.lambda_.expression)
159159

160160

0 commit comments

Comments
 (0)