viktor.testing
mock_ParamsFromFile
- viktor.testing.mock_ParamsFromFile(controller)¶
Decorator that can be used for testing methods decorated with
viktor.core.ParamsFromFile
.Example:
import unittest from viktor.testing import mock_ParamsFromFile from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_ParamsFromFile(MyEntityController) def test_process_file(self): file = File.from_data("abc") returned_dict = MyEntityController().process_file(file) self.assertDictEqual(returned_dict, {...})
- Parameters
controller (
Type
[ViktorController
]) – Controller class on which the ParamsFromFile should be mocked- Return type
Callable
mock_Storage
- viktor.testing.mock_Storage(*, get=None, list=None)¶
Decorator that can be used for testing methods which invoke the
viktor.core.Storage
.Use the get and list arguments to instruct which file(s) the respective Storage().get(…) and Storage().list(…) methods should return.
Example:
import unittest from viktor.testing import mock_Storage from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_Storage( get=[File.from_data("abc"), File.from_data("def")], list=[{'data_key_3': File.from_data("ghi")}] ) def test_process_analysis_result(self): # Storage().get(...) invoked twice, Storage().list(...) invoked once result = MyEntityController().process_analysis_result() ...
- Parameters
- Return type
Callable
MockedEntityType
- class viktor.testing.MockedEntityType(name='MockedEntityType', entity_type_id=1)¶
Bases:
EntityType
New in v13.3.0To mock a EntityType.
MockedEntityRevision
- class viktor.testing.MockedEntityRevision(params=None, created_date=None)¶
Bases:
EntityRevision
New in v13.3.0To mock an EntityRevision.
Example:
from viktor.testing import MockedEntityRevision, MockedEntity, MockedFileResource params = { 'number': 1, 'entity': MockedEntity(name="MyEntity"), 'file': MockedFileResource(File.from_data("content"), "file.txt") } mocked_entity_revision = MockedEntityRevision(params)
params can be passed from a JSON file by making use of
mock_params()
:from viktor import File from viktor.testing import MockedEntityRevision, MockedEntity, MockedFileResource, mock_params from app.my_entity.controller import MyEntityController json_file = File.from_path("path to JSON file") params = mock_params( json_file, MyEntityController.parametrization, entities={1: MockedEntity(name="MyEntity")}, file_resources={1: MockedFileResource(File.from_data("content"), "file")} ) mocked_entity_revision = MockedEntityRevision(params)
- Parameters
params (
Union
[dict
,Munch
,None
]) – Return value of EntityRevision.params. Must be the deserialized params (seemock_params()
). None to set default (empty) params.created_date (
Optional
[datetime
]) – Return value of EntityRevision.created_date. None to set default date (2000, 1, 1).
MockedUser
MockedFileResource
- class viktor.testing.MockedFileResource(file=None, filename='mocked_file.txt')¶
- New in v13.3.0
To mock a FileResource.
- Parameters
file (
Optional
[File
]) – Return value of FileResource.file. None to set default file with content = “mocked content”.filename (
str
) – Return value of FileResource.filename.
MockedEntity
- class viktor.testing.MockedEntity(*, entity_id=1, name='Mocked Entity', entity_type=None, last_saved_params=None, last_saved_summary=None, get_file=None, parent=None, children=None, siblings=None, revisions=None, invalid=False)¶
- New in v13.3.0
To mock an Entity. All arguments are optional: instantiating MockedEntity without parameters returns a default MockedEntity.
Example:
from viktor.testing import MockedEntity, MockedEntityRevision mocked_entity = MockedEntity(last_saved_params=params, revisions=[MockedEntityRevision(params)])
last_saved_params can be passed from a JSON file by making use of
mock_params()
:from viktor import File from viktor.testing import MockedEntity, MockedEntityRevision, MockedFileResource, mock_params from app.my_entity.controller import MyEntityController json_file = File.from_path("path to JSON file") params = mock_params( json_file, MyEntityController.parametrization, entities={1: MockedEntity(name="MyEntity")}, file_resources={1: MockedFileResource(File.from_data("content"), "file")} ) mocked_entity = MockedEntity(last_saved_params=params, revisions=[MockedEntityRevision(params)])
- Parameters
entity_id (
int
) – Return value of Entity.id.name (
str
) – Return value of Entity.name.entity_type (
Optional
[MockedEntityType
]) – Return value of Entity.entity_type. None for default MockedEntityType.last_saved_params (
Union
[dict
,Munch
,None
]) – Return value of Entity.last_saved_params(). Must be the deserialized params (seemock_params()
). None to simulate an entity without params.last_saved_summary (
Optional
[dict
]) – Return value of Entity.last_saved_summary(). None to simulate an entity without summary.get_file (
Optional
[File
]) – Return value of Entity.get_file. None to simulate an entity without file.parent (
Optional
[MockedEntity
]) – Return value of Entity.parent. None to simulate an entity without parent.children (
Optional
[Sequence
[MockedEntity
]]) – Return value of Entity.children. None to simulate an entity without children.siblings (
Optional
[Sequence
[MockedEntity
]]) – Return value of Entity.siblings. None to simulate an entity without siblings.revisions (
Optional
[Sequence
[MockedEntityRevision
]]) – Return value of Entity.revisions. None to simulate an entity without revisions.invalid (
bool
) – Set to True to simulate failing API calls on this Entity.
- property id: int¶
- Return type
int
- property name: str¶
- Return type
str
- property entity_type: MockedEntityType¶
- Return type
- property last_saved_params: munch.Munch¶
- Return type
Munch
- property last_saved_summary: munch.Munch¶
- Return type
Munch
- parent(*args, **kwargs)¶
- Return type
- children(*args, entity_type_names=None, **kwargs)¶
- Return type
- siblings(*args, entity_type_names=None, **kwargs)¶
- Return type
- create_child(entity_type_name, name, *args, params=None, **kwargs)¶
- Return type
- delete(*args, **kwargs)¶
- Return type
None
- rename(name, *args, **kwargs)¶
- Return type
- revisions(*args, **kwargs)¶
- Return type
List
[MockedEntityRevision
]
- set_params(params, *args, **kwargs)¶
- Return type
MockedEntityList
- class viktor.testing.MockedEntityList(entities, *, error=None)¶
mock_API
- viktor.testing.mock_API(*, get_entity=None, create_child_entity=None, generate_upload_url=None, get_current_user=None, get_entities_by_type=None, get_entity_children=None, get_entity_siblings=None, get_root_entities=None, get_entity_parent=None, get_entity_revisions=None, get_entity_file=None, rename_entity=None, set_entity_params=None)¶
- New in v13.3.0
Decorator that can be used to mock API() method calls, to facilitate easier testing.
Example:
import unittest from viktor import File from viktor.testing import mock_API, MockedEntity from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_API( get_entity=[MockedEntity(entity_id=98), MockedEntity(entity_id=99)], get_entity_file=File.from_data("fake content") ) def test_api_calls(self): MyEntityController().api_calls()
Note that last_saved_params can be passed to MockedEntity from a JSON file by making use of
mock_params()
:import unittest from viktor import File from viktor.testing import mock_API, MockedEntity, mock_params, MockedFileResource from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): json_file = File.from_path("path to JSON file") params = mock_params( json_file, MyEntityController.parametrization, entities={1: MockedEntity(name="MyEntity")}, file_resources={1: MockedFileResource(File.from_data("content"), "file")} ) @mock_API( get_entity=MockedEntity(last_saved_params=params, revisions=[MockedEntityRevision(params)]) ) def test_api_calls(self): MyEntityController().api_calls()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding API method call. When an API method is called on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding API method is called (endlessly).
If None is provided (default), a default object is returned each time the corresponding API method is called (endlessly).
- Parameters
get_entity (
Union
[Sequence
[MockedEntity
],MockedEntity
,None
]) – Return value of API.get_entity.create_child_entity (
Union
[Sequence
[MockedEntity
],MockedEntity
,None
]) – Return value of API.create_child_entity.generate_upload_url (
Union
[Sequence
[dict
],dict
,None
]) – Return value of API.generate_upload_url.get_current_user (
Union
[Sequence
[MockedUser
],MockedUser
,None
]) – Return value of API.get_current_user.get_entities_by_type (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
],None
]) – Return value of API.get_entities_by_type.get_entity_children (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
],None
]) – Return value of API.get_entity_children.get_entity_siblings (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
],None
]) – Return value of API.get_entity_siblings.get_root_entities (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
],None
]) – Return value of API.get_root_entities.get_entity_parent (
Union
[Sequence
[MockedEntity
],MockedEntity
,None
]) – Return value of API.get_entity_parent.get_entity_revisions (
Union
[Sequence
[Sequence
[MockedEntityRevision
]],Sequence
[MockedEntityRevision
],None
]) – Return value of API.get_entity_revisions.get_entity_file (
Union
[Sequence
[File
],File
,None
]) – Return value of API.get_entity_file.rename_entity (
Union
[Sequence
[MockedEntity
],MockedEntity
,None
]) – Return value of API.rename_entity.set_entity_params (
Union
[Sequence
[MockedEntity
],MockedEntity
,None
]) – Return value of API.set_entity_params.
- Return type
Callable
mock_params
- viktor.testing.mock_params(params, parametrization, file_resources=None, entities=None)¶
Convert a plain dict to the (deserialized) params, replacing FileResource and Entity objects with their mocked counterpart (MockedFileResource, MockedEntity). Can be used to test methods with params in their signature that are called by the VIKTOR platform (e.g. view methods, button methods).
Example:
import unittest from viktor import File from viktor.testing import mock_params, MockedEntity, MockedFileResource from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): def test_button_method(self): // provide the params manually... params_dict = {'number': 1, 'entity': 2, 'file': 3} // or from a JSON file... params_dict = File.from_path("path to my JSON file") mocked_params = mock_params( params, MyEntityController.parametrization entities={2: MockedEntity(entity_id=2, name="My Entity")} file_resources={3: MockedFileResource(File.from_data("content"), "file.txt")}, ) MyEntityController().button_method(mocked_params)
Deserialization only affects the raw values associated with the following fields:
DateField
EntityOptionField
ChildEntityOptionField
SiblingEntityOptionField
EntityMultiSelectField
ChildEntityMultiSelectField
SiblingEntityMultiSelectField
GeoPointField
GeoPolylineField
GeoPolygonField
FileField
MultiFileField
- Parameters
params (
Union
[dict
,File
]) – Plain dict or JSON file (with serialized params) to be converted to the (deserialized) params.parametrization (
Parametrization
) – Parametrization corresponding to the params.file_resources (
Optional
[Dict
[int
,MockedFileResource
]]) – Maps FileResource source id in params to mocked file resource. If source id is not in file_resources, a default MockedFileResource (with default filename and File) is returned.entities (
Optional
[Dict
[int
,MockedEntity
]]) – Maps entity id in params to mocked entity. If entity id is not in entities, a default MockedEntity is returned.
- Return type
Munch
mock_View
- viktor.testing.mock_View(controller)¶
- New in v13.3.0
Decorator that can be used to mock @View decorators (any subclass of
viktor.views.View
), to facilitate easier testing of view methods.Example:
import unittest from viktor.testing import mock_View from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_View(MyEntityController) def test_geometry_view(self): params = ... geometry_result = MyEntityController().geometry_view(params=params) self.assertIsInstance(geometry_result.geometry, TransformableObject) self.assertEqual(geometry_result.labels, ...)
- Parameters
controller (
Type
[ViktorController
]) – Controller class on which the @View decorator should be mocked- Return type
Callable
mock_SciaAnalysis
- viktor.testing.mock_SciaAnalysis(get_engineering_report=None, get_updated_esa_model=None, get_xml_output_file=None)¶
- New in v13.3.0
Decorator that can be used to mock
viktor.external.scia.SciaAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_SciaAnalysis from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_SciaAnalysis( get_engineering_report=File.from_path(Path(__file__).parent / 'test_file.pdf'), get_updated_esa_model=File.from_path(Path(__file__).parent / 'test_file.esa'), get_xml_output_file=File.from_path(Path(__file__).parent / 'test_output.xml') ) def test_scia_analysis(self): MyEntityController().scia_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
- Parameters
get_engineering_report (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
,None
]) – Return value of SciaAnalysis.get_engineering_report.get_updated_esa_model (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
,None
]) – Return value of SciaAnalysis.get_updated_esa_model.get_xml_output_file (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
,None
]) – Return value of SciaAnalysis.get_xml_output_file.
- Return type
Callable
mock_DSettlementAnalysis
- viktor.testing.mock_DSettlementAnalysis(get_output_file=None, get_sld_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.dsettlement.DSettlementAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_DSettlementAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DSettlementAnalysis(get_output_file={ '.sld': File.from_path(Path(__file__).parent / 'test_output.sld'), '.slo': File.from_path(Path(__file__).parent / 'test_output.slo') }) def test_dsettlement_analysis(self): MyEntityTypeController().dsettlement_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File or StringIO/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
- Parameters
- Return type
Callable
mock_DSheetPilingAnalysis
- viktor.testing.mock_DSheetPilingAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.dsheetpiling.DSheetPilingAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_DSheetPilingAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DSheetPilingAnalysis(get_output_file={ '.shd': File.from_path(Path(__file__).parent / 'test_output.shd'), '.shl': File.from_path(Path(__file__).parent / 'test_output.shl'), '.shs': File.from_path(Path(__file__).parent / 'test_output.shs'), '.sho': File.from_path(Path(__file__).parent / 'test_output.sho') }) def test_dsheetpiling_analysis(self): MyEntityTypeController().dsheetpiling_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_DStabilityAnalysis
- viktor.testing.mock_DStabilityAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.dstability.DStabilityAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_DStabilityAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DStabilityAnalysis(get_output_file={ '.stix': File.from_path(Path(__file__).parent / 'test_output.stix') }) def test_dstability_analysis(self): MyEntityTypeController().dstability_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_DGeoStabilityAnalysis
- viktor.testing.mock_DGeoStabilityAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.dgeostability.DGeoStabilityAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_DGeoStabilityAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DGeoStabilityAnalysis(get_output_file={ '.sto': File.from_path(Path(__file__).parent / 'test_output.sto') }) def test_dgeostability_analysis(self): MyEntityTypeController().dgeostability_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_DFoundationsAnalysis
- viktor.testing.mock_DFoundationsAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.dfoundations.DFoundationsAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_DFoundationsAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DFoundationsAnalysis(get_output_file={ '.fod': File.from_path(Path(__file__).parent / 'test_output.fod'), '.fos': File.from_path(Path(__file__).parent / 'test_output.fos') }) def test_dfoundations_analysis(self): MyEntityTypeController().dfoundations_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_GRLWeapAnalysis
- viktor.testing.mock_GRLWeapAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.grlweap.GRLWeapAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_GRLWeapAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_GRLWeapAnalysis( get_output_file=File.from_path(Path(__file__).parent / 'test_output.GWO') ) def test_grlweap_analysis(self): MyEntityTypeController().grlweap_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_IdeaRcsAnalysis
- viktor.testing.mock_IdeaRcsAnalysis(get_output_file=None, get_idea_rcs_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.idea_rcs.IdeaRcsAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_IdeaRcsAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_IdeaRcsAnalysis( get_output_file=File.from_path(Path(__file__).parent / 'test_output.xml'), get_idea_rcs_file=File.from_path(Path(__file__).parent / 'test_rcs.ideaRcs') ) def test_idea_rcs_analysis(self): MyEntityTypeController().idea_rcs_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_RobotAnalysis
- viktor.testing.mock_RobotAnalysis(get_model_file=None, get_results=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.robot.RobotAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_RobotAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_RobotAnalysis( get_model_file=File.from_path(Path(__file__).parent / 'test_model.rtd'), get_results={'bar_forces': {...}, ...} ) def test_robot_analysis(self): MyEntityTypeController().robot_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/dict object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_AxisVMAnalysis
- viktor.testing.mock_AxisVMAnalysis(get_model_file=None, get_result_file=None, get_results=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.axisvm.AxisVMAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_AxisVMAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_AxisVMAnalysis( get_model_file=File.from_path(Path(__file__).parent / 'test_model.axs'), get_result_file=File.from_path(Path(__file__).parent / 'test_model.axe'), get_results={'Forces': ...} ) def test_axisvm_analysis(self): MyEntityTypeController().axisvm_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File/BytesIO/dict object (with empty content) is returned each time the corresponding method is called (endlessly).
- Parameters
get_model_file (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
,None
]) – Return value of AxisVMAnalysis.get_model_file.get_result_file (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
,None
]) – Return value of AxisVMAnalysis.get_result_file.get_results (
Union
[Sequence
[dict
],dict
,None
]) – Return value of AxisVMAnalysis.get_results.
- Return type
Callable
mock_GenericAnalysis
- viktor.testing.mock_GenericAnalysis(get_output_file=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.generic.GenericAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_GenericAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_GenericAnalysis(get_output_file={ 'data.out': File.from_path(Path(__file__).parent / 'data.out'), 'info.log': File.from_path(Path(__file__).parent / 'info.log') }) def test_generic_analysis(self): MyEntityTypeController().generic_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File or BytesIO object (with empty content) is returned each time the corresponding method is called (endlessly).
mock_Excel
- viktor.testing.mock_Excel(get_named_cell_result=None, get_direct_cell_result=None, get_filled_template=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.excel.Excel
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_Excel from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_Excel( get_filled_template=File.from_path(Path(__file__).parent / 'test_model.xlsx'), get_named_cell_result={"cell name": 5.5}, get_direct_cell_result={ ("Sheet1", "A", 5): "cell value", ("Sheet2", "B", 1): 1.4, } ) def test_excel_analysis(self): MyEntityTypeController().excel_analysis()
- For all parameters the following holds:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default File object (with empty content) is returned for the template, whereas None is returned for the cell values, each time the corresponding method is called (endlessly).
- Parameters
get_named_cell_result (
Optional
[Dict
[str
,Union
[Sequence
[Union
[str
,int
,float
,bool
]],str
,int
,float
,bool
]]]) – Return value of Excel.get_named_cell_result.get_direct_cell_result (
Optional
[Dict
[Tuple
[str
,str
,int
],Union
[Sequence
[Union
[str
,int
,float
,bool
]],str
,int
,float
,bool
]]]) – Return value of Excel.get_direct_cell_result.get_filled_template (
Union
[Sequence
[File
],File
,None
]) – Return value of Excel.get_filled_template.
- Return type
Callable
mock_RFEMAnalysis
- viktor.testing.mock_RFEMAnalysis(get_model=None, get_result=None)¶
- New in v13.5.0
Decorator that can be used to mock
viktor.external.rfem.RFEMAnalysis
, to facilitate easier testing.Example:
import unittest from viktor.testing import mock_RFEMAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_RFEMAnalysis( get_model=File.from_path(Path(__file__).parent / 'test_model.rfx') get_result={ 3: File.from_path(Path(__file__).parent / 'load_case_3.json'), 5: File.from_path(Path(__file__).parent / 'load_case_5.json') } ) def test_rfem_analysis(self): MyEntityTypeController().rfem_analysis() }) def test_rfem_analysis(self): MyEntityTypeController().rfem_analysis()
- For all parameters the following can be provided:
If a Sequence type is provided, the next entry is returned for each corresponding method call. When a call is performed on a depleted iterable, an Exception is raised.
If a single object is provided, the object is returned each time the corresponding method is called (endlessly).
If None is provided (default), a default BytesIO/File object (with empty content) is returned each time the corresponding method is called (endlessly).