Skip to content

Commit

Permalink
test: update attr with keyvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
djs0109 committed Aug 27, 2024
1 parent 70172d9 commit 6c082ea
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/clients/test_ngsi_v2_cb.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,48 @@ def test_update_entity_keyvalues(self):
response_format=AttrsFormat.KEY_VALUES).model_dump()
)

@clean_test(fiware_service=settings.FIWARE_SERVICE,
fiware_servicepath=settings.FIWARE_SERVICEPATH,
cb_url=settings.CB_URL)
def test_update_attributes_keyvalues(self):
entity1 = self.entity.model_copy(deep=True)
# initial entity
self.client.post_entity(entity1)

# update existing attributes
self.client.update_or_append_entity_attributes(
entity_id=entity1.id,
attrs={"temperature": 30},
key_values=True)
self.assertEqual(30, self.client.get_attribute_value(entity_id=entity1.id,
attr_name="temperature"))

# update not existing attributes
self.client.update_or_append_entity_attributes(
entity_id=entity1.id,
attrs={"humidity": 40},
key_values=True)
self.assertEqual(40, self.client.get_attribute_value(entity_id=entity1.id,
attr_name="humidity"))

# update both existing and not existing attributes
with self.assertRaises(RequestException):
self.client.update_or_append_entity_attributes(
entity_id=entity1.id,
attrs={"humidity": 50, "co2": 300},
append_strict=True,
key_values=True)
self.client.update_or_append_entity_attributes(
entity_id=entity1.id,
attrs={"humidity": 50, "co2": 300},
key_values=True)
self.assertEqual(50, self.client.get_attribute_value(entity_id=entity1.id,
attr_name="humidity"))
self.assertEqual(300, self.client.get_attribute_value(entity_id=entity1.id,
attr_name="co2"))
self.assertEqual(30, self.client.get_attribute_value(entity_id=entity1.id,
attr_name="temperature"))

@clean_test(fiware_service=settings.FIWARE_SERVICE,
fiware_servicepath=settings.FIWARE_SERVICEPATH,
cb_url=settings.CB_URL)
Expand Down

0 comments on commit 6c082ea

Please sign in to comment.