Commit 8cee4655 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[test] updated and refactored tests

parent a469913c
Pipeline #27638 passed with stage
in 5 minutes and 57 seconds
...@@ -58,30 +58,28 @@ class MockAssetEditor(AbstractAssetEditor): ...@@ -58,30 +58,28 @@ class MockAssetEditor(AbstractAssetEditor):
def set_dataformat_model(self, model): def set_dataformat_model(self, model):
self.dataformat_model = model self.dataformat_model = model
def load_json(self, json_object, widget_type): def load_json(self, json_object):
"""Load the json object passed as parameter""" """Load the json object passed as parameter"""
if widget_type == "field": for name, type_ in json_object["field"].items():
for name, type_ in json_object.items(): field = FieldWidget(self.dataformat_model)
field = FieldWidget(self.dataformat_model) field.format_name = name
field.format_name = name field.format_type = type_
field.format_type = type_ self.layout().addWidget(field)
self.layout().addWidget(field)
elif widget_type == "description": short_text = json_object["description"]
short_text = json_object["short_description"] self.description.form_description.setText(short_text)
self.description.form_description.setText(short_text)
def dump_json(self):
def dump_json(self, widget_type):
"""Returns the json representation of the asset""" """Returns the json representation of the asset"""
json_data = {} json_data = {}
if widget_type == "field": field_list = self.findChildren(FieldWidget)
field_list = self.findChildren(FieldWidget) json_data["field"] = {}
for field in field_list: for field in field_list:
json_data[field.format_name] = field.format_type json_data["field"][field.format_name] = field.format_type
elif widget_type == "description": json_data["description"] = self.description.short_description()
json_data["short_description"] = self.description.short_description()
return json_data return json_data
...@@ -95,13 +93,16 @@ class TestMockEditor: ...@@ -95,13 +93,16 @@ class TestMockEditor:
"""Test that the mock editor works correctly""" """Test that the mock editor works correctly"""
def test_json_load_and_dump_field_widget(self, qtbot, dataformat_model): def test_json_load_and_dump_field_widget(self, qtbot, dataformat_model):
json_reference = {"value32": "float32", "value64": "float64"} json_reference = {
"field": {"value32": "float32", "value64": "float64"},
"description": "Short description test",
}
widget = MockAssetEditor() widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model) widget.set_dataformat_model(dataformat_model)
widget.load_json(json_reference, "field") widget.load_json(json_reference)
assert widget.dump_json("field") == json_reference assert widget.dump_json() == json_reference
def test_dataformat_creation_field_widget(self, qtbot, dataformat_model): def test_dataformat_creation_field_widget(self, qtbot, dataformat_model):
widget = MockAssetEditor() widget = MockAssetEditor()
...@@ -117,7 +118,10 @@ class TestMockEditor: ...@@ -117,7 +118,10 @@ class TestMockEditor:
field.format_name = "value32" field.format_name = "value32"
field.format_type = "float32" field.format_type = "float32"
assert widget.dump_json("field") == {"value32": "float32"} assert widget.dump_json() == {
"field": {"value32": "float32"},
"description": "",
}
qtbot.mouseClick(widget.add_field_button, QtCore.Qt.LeftButton) qtbot.mouseClick(widget.add_field_button, QtCore.Qt.LeftButton)
fields = widget.findChildren(FieldWidget) fields = widget.findChildren(FieldWidget)
...@@ -129,13 +133,7 @@ class TestMockEditor: ...@@ -129,13 +133,7 @@ class TestMockEditor:
field.format_name = "value64" field.format_name = "value64"
field.format_type = "float64" field.format_type = "float64"
assert widget.dump_json("field") == {"value32": "float32", "value64": "float64"} assert widget.dump_json() == {
"field": {"value32": "float32", "value64": "float64"},
def test_json_load_and_dump_description_widget(self, qtbot): "description": "",
json_reference = {"short_description": "Short description test"} }
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
widget.load_json(json_reference, "description")
assert widget.dump_json("description") == json_reference
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment