@@ -261,10 +261,10 @@ def test_entity_update(self):
261
261
entity_init = self .entity .model_copy (deep = True )
262
262
attr_init = entity_init .get_attribute ("temperature" )
263
263
attr_init .metadata = {
264
- "metadata_init" : {
265
- "type" : "Text" ,
266
- "value" : "something" }
267
- }
264
+ "metadata_init" : {
265
+ "type" : "Text" ,
266
+ "value" : "something" }
267
+ }
268
268
attr_append = NamedContextAttribute (** {
269
269
"name" : 'pressure' ,
270
270
"type" : 'Number' ,
@@ -393,6 +393,62 @@ def test_entity_update(self):
393
393
clear_all (fiware_header = self .fiware_header ,
394
394
cb_url = settings .CB_URL )
395
395
396
+ # 4) update only property or relationship
397
+ if "update_entity_properties" or "update_entity_relationship" :
398
+ # post entity with a relationship attribute
399
+ entity_init = self .entity .model_copy (deep = True )
400
+ attrs = [
401
+ NamedContextAttribute (name = 'in' , type = 'Relationship' , value = 'dummy1' )]
402
+ entity_init .add_attributes (attrs = attrs )
403
+ client .post_entity (entity = entity_init , update = True )
404
+
405
+ # create entity that differs in both attributes
406
+ entity_update = entity_init .model_copy (deep = True )
407
+ attrs = [NamedContextAttribute (name = 'temperature' ,
408
+ type = 'Number' ,
409
+ value = 21 ),
410
+ NamedContextAttribute (name = 'in' , type = 'Relationship' ,
411
+ value = 'dummy2' )]
412
+ entity_update .update_attribute (attrs = attrs )
413
+
414
+ # update only properties and compare
415
+ client .update_entity_properties (entity_update )
416
+ entity_db = client .get_entity (entity_update .id )
417
+ db_attrs = entity_db .get_attribute (attribute_name = 'temperature' )
418
+ update_attrs = entity_update .get_attribute (attribute_name = 'temperature' )
419
+ self .assertEqual (db_attrs , update_attrs )
420
+ db_attrs = entity_db .get_attribute (attribute_name = 'in' )
421
+ update_attrs = entity_update .get_attribute (attribute_name = 'in' )
422
+ self .assertNotEqual (db_attrs , update_attrs )
423
+
424
+ # update only relationship and compare
425
+ attrs = [
426
+ NamedContextAttribute (name = 'temperature' , type = 'Number' , value = 22 )]
427
+ entity_update .update_attribute (attrs = attrs )
428
+ client .update_entity_relationships (entity_update )
429
+ entity_db = client .get_entity (entity_update .id )
430
+ self .assertEqual (entity_db .get_attribute (attribute_name = 'in' ),
431
+ entity_update .get_attribute (attribute_name = 'in' ))
432
+ self .assertNotEqual (entity_db .get_attribute (attribute_name = 'temperature' ),
433
+ entity_update .get_attribute (
434
+ attribute_name = 'temperature' ))
435
+
436
+ # change both, update both, compare
437
+ attrs = [NamedContextAttribute (name = 'temperature' ,
438
+ type = 'Number' ,
439
+ value = 23 ),
440
+ NamedContextAttribute (name = 'in' , type = 'Relationship' ,
441
+ value = 'dummy3' )]
442
+ entity_update .update_attribute (attrs = attrs )
443
+ client .update_entity (entity_update )
444
+ entity_db = client .get_entity (entity_update .id )
445
+ db_attrs = entity_db .get_attribute (attribute_name = 'in' )
446
+ update_attrs = entity_update .get_attribute (attribute_name = 'in' )
447
+ self .assertEqual (db_attrs , update_attrs )
448
+ db_attrs = entity_db .get_attribute (attribute_name = 'temperature' )
449
+ update_attrs = entity_update .get_attribute (attribute_name = 'temperature' )
450
+ self .assertEqual (db_attrs , update_attrs )
451
+
396
452
@clean_test (fiware_service = settings .FIWARE_SERVICE ,
397
453
fiware_servicepath = settings .FIWARE_SERVICEPATH ,
398
454
cb_url = settings .CB_URL )
@@ -1460,9 +1516,11 @@ def test_send_receive_string(self):
1460
1516
self .client .post_entity (entity = entity )
1461
1517
1462
1518
testData = "hello_test"
1463
- self .client .update_attribute_value (entity_id = "string_test" , attr_name = "data" , value = testData )
1519
+ self .client .update_attribute_value (entity_id = "string_test" , attr_name = "data" ,
1520
+ value = testData )
1464
1521
1465
- readback = self .client .get_attribute_value (entity_id = "string_test" , attr_name = "data" )
1522
+ readback = self .client .get_attribute_value (entity_id = "string_test" ,
1523
+ attr_name = "data" )
1466
1524
1467
1525
self .assertEqual (testData , readback )
1468
1526
0 commit comments