Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit e5150c7

Browse files
authored
LEXIO-37880 Caches properties, includes test for quote in string (#3)
1 parent 36f837a commit e5150c7

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

crma_api_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .client import CRMAAPIClient
44

5-
__version__ = "0.3.0"
5+
__version__ = "0.4.0"

crma_api_client/resources/query.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
from enum import Enum
5+
from functools import cached_property
56
from typing import Any, Dict, List
67

78
from pydantic import BaseModel
@@ -22,11 +23,16 @@ class ProjectionField(BaseModel):
2223
id: str
2324
type: str
2425

25-
@property
26+
@cached_property
2627
def name(self) -> str:
2728
"""Return field name that omits stream reference"""
2829
return self.id.split(".")[-1]
2930

31+
class Config:
32+
"""Model configuration"""
33+
34+
keep_untouched = (cached_property,)
35+
3036

3137
class LineageProjection(BaseModel):
3238
"""Field projection metadata container"""
@@ -72,7 +78,7 @@ class QueryResponse(BaseModel):
7278
query: str
7379
response_time: int
7480

75-
@property
81+
@cached_property
7682
def fields(self) -> List[ProjectionField]:
7783
"""Return the fields from the query response metadata
7884
@@ -84,3 +90,4 @@ class Config:
8490
"""Model configuration"""
8591

8692
alias_generator = to_camel
93+
keep_untouched = (cached_property,)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "crma-api-client"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "CRM Analytics REST API Client"
55
authors = ["Jonathan Drake <[email protected]>"]
66
license = "BSD-3-Clause"

tests/functional/test_query.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ async def test_query(client: CRMAAPIClient):
1515
[
1616
f"""q = load "{version.dataset.id}/{version.id}";""",
1717
"""q = group q by 'Category';""",
18-
"""q = foreach q generate q.'Category' as 'Category', sum(q.'Sales') as 'Sales';""",
19-
"""q = order q by 'Category' asc;""",
18+
"""q = foreach q generate q.'Category' as 'Jon\\'s Category', sum(q.'Sales') as 'Sales';""",
19+
"""q = order q by 'Jon\\'s Category' asc;""",
2020
]
2121
)
2222
response = await client.query(query)
2323
assert response.results.records == [
24-
{"Category": "Furniture", "Sales": 741999.7953},
25-
{"Category": "Office Supplies", "Sales": 719047.032},
26-
{"Category": "Technology", "Sales": 836154.033},
24+
{"Jon's Category": "Furniture", "Sales": 741999.7953},
25+
{"Jon's Category": "Office Supplies", "Sales": 719047.032},
26+
{"Jon's Category": "Technology", "Sales": 836154.033},
2727
]
2828
assert response.fields == [
29-
ProjectionField(id="q.Category", type="string"),
29+
ProjectionField(id="q.Jon's Category", type="string"),
3030
ProjectionField(id="q.Sales", type="numeric"),
3131
]
32-
assert response.fields[0].name == "Category"
32+
assert response.fields[0].name == "Jon's Category"

0 commit comments

Comments
 (0)