Skip to content

Commit

Permalink
Update tests for lid support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie Greenbaum committed Nov 6, 2024
1 parent e85eb80 commit 13bdc72
Show file tree
Hide file tree
Showing 2 changed files with 548 additions and 5 deletions.
100 changes: 96 additions & 4 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_using_href(self):
}
)

def test_primary_data_without_id(self):
def test_primary_data_without_id_or_lid(self):
data = {
ATOMIC_OPERATIONS: [
{
Expand All @@ -242,7 +242,7 @@ def test_primary_data_without_id(self):
stream = BytesIO(json.dumps(data).encode("utf-8"))
self.assertRaisesRegex(
JsonApiParseError,
"The resource identifier object must contain an `id` member",
"The resource identifier object must contain an `id` member or a `lid` member",
self.parser.parse,
**{
"stream": stream,
Expand All @@ -263,7 +263,7 @@ def test_primary_data_without_id(self):
stream = BytesIO(json.dumps(data).encode("utf-8"))
self.assertRaisesRegex(
JsonApiParseError,
"The resource identifier object must contain an `id` member",
"The resource identifier object must contain an `id` member or a `lid` member",
self.parser.parse,
**{
"stream": stream,
Expand All @@ -284,7 +284,7 @@ def test_primary_data_without_id(self):
stream = BytesIO(json.dumps(data).encode("utf-8"))
self.assertRaisesRegex(
JsonApiParseError,
"The resource identifier object must contain an `id` member",
"The resource identifier object must contain an `id` member or a `lid` member",
self.parser.parse,
**{
"stream": stream,
Expand Down Expand Up @@ -365,3 +365,95 @@ def test_is_atomic_operations(self):
"parser_context": self.parser_context
}
)

def test_parse_with_lid(self):
data = {
ATOMIC_OPERATIONS: [
{
"op": "add",
"data": {
"lid": "1",
"type": "articles",
"attributes": {
"title": "JSON API paints my bikeshed!"
}
}
},
{
"op": "update",
"data": {
"lid": "1",
"type": "articles",
"attributes": {
"title": "JSON API supports lids!"
}
}
},
{
"op": "remove",
"ref": {
"lid": "1",
"type": "articles",
}
}
]
}
stream = BytesIO(json.dumps(data).encode("utf-8"))

result = self.parser.parse(stream, parser_context=self.parser_context)
expected_result = [
{
"add": {
"type": "articles",
"lid": "1",
"title": "JSON API paints my bikeshed!"
}
},
{
"update": {
"lid": "1",
"type": "articles",
"title": "JSON API supports lids!"
}
},
{
"remove": {
"lid": "1",
"type": "articles"
}
}
]
self.assertEqual(expected_result, result)

def test_primary_data_with_id_and_lid(self):
data = {
ATOMIC_OPERATIONS: [
{
"op": "add",
"data": {
"lid": "1",
"type": "articles",
"title": "JSON API paints my bikeshed!"
}
},
{
"op": "update",
"data": {
"lid": "1",
"id": "1",
"type": "articles",
"title": "JSON API supports lids!"
}
}
]
}
stream = BytesIO(json.dumps(data).encode("utf-8"))
self.assertRaisesRegex(
JsonApiParseError,
"Only one of `id`, `lid` may be specified",
self.parser.parse,
**{
"stream": stream,
"parser_context": self.parser_context
}
)
Loading

0 comments on commit 13bdc72

Please sign in to comment.