-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: include context conversion methods and test #393
base: master
Are you sure you want to change the base?
chore: include context conversion methods and test #393
Conversation
tests/models/test_ngsi_v2_context.py
Outdated
@@ -623,6 +623,12 @@ def test_get_attributes(self): | |||
self.assertNotEqual(entity.get_attributes(strict_data_type=True), attributes) | |||
self.assertNotEqual(entity.get_attributes(), attributes) | |||
|
|||
def test_context_conversion(self): | |||
entity_normalized = ContextEntity(**self.entity_data) | |||
entity_key_values = ContextEntityKeyValues(**self.entity_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this way the created entity_key_values
is not really in keyvalue format.
Expected entity_key_values.model_dump_json()
{"id": "MyId", "type": "MyType", "temperature": 20, "relation": "OtherEntity"}
Right now
{"id": "MyId", "type": "MyType", "temperature": {"value": 20, "type": "Number"}, "relation": {"value": "OtherEntity", "type": "Relationship"}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made adjustments accordingly. However, the test is failing, so the conversion functionality needs to be checked again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, now I am thinking, shouldn't the constructor of ContextEntityKeyValues
class take care of the right format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I think the implementation was quite simple. There is no need to create model for AttributeKeyvalue
. Because the entity can simply takes whatever it gets, as long as it is JSON serializable. It would be nice to have a simple validation mechanism for the AttributeKeyvalue
, but not necessarily
For example, if we create an entity with keyvalue like that
{"id": "MyId", "type": "MyType", "temperature": {"value": 20, "type": "Number"}
Orion will understand it as
{"id": "MyId", "type": "MyType",
"temperature": {
"type": "StructuredValue",
"value": {"value": 20, "type": "Number"}
}
No description provided.