Skip to content

Commit

Permalink
Merge branch 'dev' into wangbill/pystein-feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vrdmr authored Apr 19, 2022
2 parents 8579b2c + 4bb65c1 commit 372a799
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 1 addition & 6 deletions azure/functions/_cosmosdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from . import _abc


# Internal properties of CosmosDB documents.
_SYSTEM_KEYS = {'_etag', '_lsn', '_rid', '_self', '_ts'}


class Document(_abc.Document, collections.UserDict):
"""An Azure Document.
Expand All @@ -25,8 +21,7 @@ def from_json(cls, json_data: str) -> 'Document':
@classmethod
def from_dict(cls, dct: dict) -> 'Document':
"""Create a Document from a dict object."""
filtered = {k: v for k, v in dct.items() if k not in _SYSTEM_KEYS}
return cls(filtered)
return cls({k: v for k, v in dct.items()})

def to_json(self) -> str:
"""Return the JSON representation of the document."""
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cosmosdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ def test_cosmosdb_convert_json_name_is_null(self):
self.assertEqual(len(result), 1)
self.assertEqual(result[0]['name'], None)

def test_cosmosdb_convert_json_internal_fields_assigned(self):
datum: Datum = Datum("""
{
"id": "1",
"name": null,
"_rid": "dummy12344",
"_self": "7U4=/docs/gpU4AJcm7U4KAAAAAAAAAA==/",
"_etag": "000-0500-0000-62598ff00000",
"_attachments": "attachments/",
"_ts": 1650036720
}
""", "json")
result: func.DocumentList = cdb.CosmosDBConverter.decode(
data=datum, trigger_metadata=None)
self.assertIsNotNone(result)
self.assertEqual(len(result), 1)
self.assertEqual(result[0]['name'], None)
self.assertEqual(result[0]['_rid'], "dummy12344")
self.assertEqual(result[0]['_self'],
"7U4=/docs/gpU4AJcm7U4KAAAAAAAAAA==/")
self.assertEqual(result[0]['_etag'], "000-0500-0000-62598ff00000")
self.assertEqual(result[0]['_attachments'], "attachments/")
self.assertEqual(result[0]['_ts'], 1650036720)

def test_cosmosdb_convert_json_multiple_entries(self):
datum: Datum = Datum("""
[
Expand Down

0 comments on commit 372a799

Please sign in to comment.