@@ -228,7 +228,7 @@ def test_using_href(self):
228
228
}
229
229
)
230
230
231
- def test_primary_data_without_id (self ):
231
+ def test_primary_data_without_id_or_lid (self ):
232
232
data = {
233
233
ATOMIC_OPERATIONS : [
234
234
{
@@ -242,7 +242,7 @@ def test_primary_data_without_id(self):
242
242
stream = BytesIO (json .dumps (data ).encode ("utf-8" ))
243
243
self .assertRaisesRegex (
244
244
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 " ,
246
246
self .parser .parse ,
247
247
** {
248
248
"stream" : stream ,
@@ -263,7 +263,7 @@ def test_primary_data_without_id(self):
263
263
stream = BytesIO (json .dumps (data ).encode ("utf-8" ))
264
264
self .assertRaisesRegex (
265
265
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 " ,
267
267
self .parser .parse ,
268
268
** {
269
269
"stream" : stream ,
@@ -284,7 +284,7 @@ def test_primary_data_without_id(self):
284
284
stream = BytesIO (json .dumps (data ).encode ("utf-8" ))
285
285
self .assertRaisesRegex (
286
286
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 " ,
288
288
self .parser .parse ,
289
289
** {
290
290
"stream" : stream ,
@@ -365,3 +365,95 @@ def test_is_atomic_operations(self):
365
365
"parser_context" : self .parser_context
366
366
}
367
367
)
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