Skip to content

Commit 13bdc72

Browse files
author
Jackie Greenbaum
committed
Update tests for lid support
1 parent e85eb80 commit 13bdc72

File tree

2 files changed

+548
-5
lines changed

2 files changed

+548
-5
lines changed

tests/test_parsers.py

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_using_href(self):
228228
}
229229
)
230230

231-
def test_primary_data_without_id(self):
231+
def test_primary_data_without_id_or_lid(self):
232232
data = {
233233
ATOMIC_OPERATIONS: [
234234
{
@@ -242,7 +242,7 @@ def test_primary_data_without_id(self):
242242
stream = BytesIO(json.dumps(data).encode("utf-8"))
243243
self.assertRaisesRegex(
244244
JsonApiParseError,
245-
"The resource identifier object must contain an `id` member",
245+
"The resource identifier object must contain an `id` member or a `lid` member",
246246
self.parser.parse,
247247
**{
248248
"stream": stream,
@@ -263,7 +263,7 @@ def test_primary_data_without_id(self):
263263
stream = BytesIO(json.dumps(data).encode("utf-8"))
264264
self.assertRaisesRegex(
265265
JsonApiParseError,
266-
"The resource identifier object must contain an `id` member",
266+
"The resource identifier object must contain an `id` member or a `lid` member",
267267
self.parser.parse,
268268
**{
269269
"stream": stream,
@@ -284,7 +284,7 @@ def test_primary_data_without_id(self):
284284
stream = BytesIO(json.dumps(data).encode("utf-8"))
285285
self.assertRaisesRegex(
286286
JsonApiParseError,
287-
"The resource identifier object must contain an `id` member",
287+
"The resource identifier object must contain an `id` member or a `lid` member",
288288
self.parser.parse,
289289
**{
290290
"stream": stream,
@@ -365,3 +365,95 @@ def test_is_atomic_operations(self):
365365
"parser_context": self.parser_context
366366
}
367367
)
368+
369+
def test_parse_with_lid(self):
370+
data = {
371+
ATOMIC_OPERATIONS: [
372+
{
373+
"op": "add",
374+
"data": {
375+
"lid": "1",
376+
"type": "articles",
377+
"attributes": {
378+
"title": "JSON API paints my bikeshed!"
379+
}
380+
}
381+
},
382+
{
383+
"op": "update",
384+
"data": {
385+
"lid": "1",
386+
"type": "articles",
387+
"attributes": {
388+
"title": "JSON API supports lids!"
389+
}
390+
}
391+
},
392+
{
393+
"op": "remove",
394+
"ref": {
395+
"lid": "1",
396+
"type": "articles",
397+
}
398+
}
399+
]
400+
}
401+
stream = BytesIO(json.dumps(data).encode("utf-8"))
402+
403+
result = self.parser.parse(stream, parser_context=self.parser_context)
404+
expected_result = [
405+
{
406+
"add": {
407+
"type": "articles",
408+
"lid": "1",
409+
"title": "JSON API paints my bikeshed!"
410+
}
411+
},
412+
{
413+
"update": {
414+
"lid": "1",
415+
"type": "articles",
416+
"title": "JSON API supports lids!"
417+
}
418+
},
419+
{
420+
"remove": {
421+
"lid": "1",
422+
"type": "articles"
423+
}
424+
}
425+
]
426+
self.assertEqual(expected_result, result)
427+
428+
def test_primary_data_with_id_and_lid(self):
429+
data = {
430+
ATOMIC_OPERATIONS: [
431+
{
432+
"op": "add",
433+
"data": {
434+
"lid": "1",
435+
"type": "articles",
436+
"title": "JSON API paints my bikeshed!"
437+
}
438+
},
439+
{
440+
"op": "update",
441+
"data": {
442+
"lid": "1",
443+
"id": "1",
444+
"type": "articles",
445+
"title": "JSON API supports lids!"
446+
}
447+
}
448+
]
449+
}
450+
stream = BytesIO(json.dumps(data).encode("utf-8"))
451+
self.assertRaisesRegex(
452+
JsonApiParseError,
453+
"Only one of `id`, `lid` may be specified",
454+
self.parser.parse,
455+
**{
456+
"stream": stream,
457+
"parser_context": self.parser_context
458+
}
459+
)

0 commit comments

Comments
 (0)