Skip to content

Commit 81e972f

Browse files
committed
Merge branch 'frbor-python3.6-dataclasses'
2 parents 8fd47d7 + b822b48 commit 81e972f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ orjson = "^3.2.1"
1717
shortuuid = "^1.0.1"
1818
wrapt = "^1.12.1"
1919
cachetools = "^4.1.1"
20+
dataclasses = {version = "^0.8.0", python = "<3.7"}
2021

2122
[tool.poetry.dev-dependencies]
2223
pytest = "^6.2"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from dataclasses import dataclass
2+
3+
from django_unicorn.components import UnicornView
4+
from django_unicorn.views import _set_property_value
5+
6+
7+
@dataclass
8+
class InventoryItem:
9+
"""Class for keeping track of an item in inventory."""
10+
name: str
11+
unit_price: float
12+
quantity_on_hand: int = 0
13+
14+
15+
class NestedPropertyView(UnicornView):
16+
inventory = InventoryItem("Hammer", 20)
17+
18+
19+
def test_set_property_value_dataclass():
20+
component = NestedPropertyView(component_name="test", component_id="12345678")
21+
assert InventoryItem("Hammer", 20) == component.inventory
22+
23+
_set_property_value(
24+
component, "inventory",
25+
InventoryItem("Hammer", 20, 1),
26+
{"inventory": InventoryItem("Hammer", 20, 1)}
27+
)
28+
29+
assert InventoryItem("Hammer", 20, 1) == component.inventory

0 commit comments

Comments
 (0)