This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import json | ||
|
||
|
||
def get_val(obj): | ||
if hasattr(obj, 'as_dict'): | ||
as_attr = getattr(obj, 'as_dict') | ||
if hasattr(obj, "as_dict"): | ||
as_attr = getattr(obj, "as_dict") | ||
return as_attr() | ||
return obj | ||
|
||
|
||
class DataModel(object): | ||
def toJson(self): | ||
return json.dumps(self.as_dict()) | ||
|
||
def as_dict(self): | ||
return {k: get_val(getattr(self, k)) for k, v in self.__class__.__dict__.items() if isinstance(v, property)} | ||
return { | ||
k: get_val(getattr(self, k)) | ||
for k, v in self.__class__.__dict__.items() | ||
if isinstance(v, property) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pygrocy.data_models.product import ProductBarcode | ||
from pygrocy.grocy_api_client import ProductBarcodeData | ||
|
||
|
||
class TestMisc: | ||
def test_158_productbarcode_deserialization(self): | ||
parsed_data = {"barcode": "123"} | ||
data = ProductBarcodeData(parsed_data) | ||
|
||
barcode = ProductBarcode(data) | ||
result = barcode.toJson() | ||
|
||
assert result is not None | ||
assert "barcode" in result | ||
assert "123" in result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters