viktor.testing
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, workspace_id=1)
- 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()
:import viktor as vkt from viktor.testing import MockedEntity, MockedEntityRevision, MockedFileResource, mock_params from app.my_entity.controller import MyEntityController json_file = vkt.File.from_path("path to JSON file") params = mock_params(json_file, MyEntityController.parametrization) 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 (
MockedEntityType
) – Return value of Entity.entity_type. None for default MockedEntityType.last_saved_params (
Union
[dict
,Munch
]) – Return value of Entity.last_saved_params(). Must be the deserialized params (seemock_params()
). None to simulate an entity without params.last_saved_summary (
dict
) – Return value of Entity.last_saved_summary(). None to simulate an entity without summary.get_file (
File
) – Return value of Entity.get_file. None to simulate an entity without file.parent (
MockedEntity
) – Return value of Entity.parent. None to simulate an entity without parent.children (
Sequence
[MockedEntity
]) – Return value of Entity.children. None to simulate an entity without children.siblings (
Sequence
[MockedEntity
]) – Return value of Entity.siblings. None to simulate an entity without siblings.revisions (
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.
- children(*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
- property entity_type: MockedEntityType
- property id: int
- property last_saved_params: munch.Munch
- property last_saved_summary: munch.Munch
- property name: str
- parent(*args, **kwargs)
- Return type:
- rename(name, *args, **kwargs)
- Return type:
- revisions(*args, **kwargs)
- Return type:
List
[MockedEntityRevision
]
- set_params(params, *args, **kwargs)
- Return type:
- siblings(*args, entity_type_names=None, **kwargs)
- Return type:
MockedEntityList
- class viktor.testing.MockedEntityList(entities, *, error=None)
MockedEntityRevision
- class viktor.testing.MockedEntityRevision(params=None, created_date=None, entity_revision_id=1)
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(vkt.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()
:import viktor as vkt from viktor.testing import MockedEntityRevision, MockedEntity, MockedFileResource, mock_params from app.my_entity.controller import MyEntityController json_file = vkt.File.from_path("path to JSON file") params = mock_params( json_file, MyEntityController.parametrization, entities={1: MockedEntity(name="MyEntity")}, file_resources={1: MockedFileResource(vkt.File.from_data("content"), "file")} ) mocked_entity_revision = MockedEntityRevision(params)
- Parameters:
params (
Union
[dict
,Munch
]) – Return value of EntityRevision.params. Must be the deserialized params (seemock_params()
). None to set default (empty) params.created_date (
datetime
) – Return value of EntityRevision.created_date. None to set default date (2000, 1, 1).entity_revision_id (
int
) – Return value of EntityRevision.id.
MockedEntityType
- class viktor.testing.MockedEntityType(name='MockedEntityType', entity_type_id=1)
Bases:
EntityType
New in v13.3.0To mock a EntityType.
MockedFileResource
MockedUser
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 import viktor as vkt 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=vkt.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 import viktor as vkt from viktor.testing import mock_API, MockedEntity, mock_params, MockedFileResource from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): json_file = vkt.File.from_path("path to JSON file") params = mock_params( json_file, MyEntityController.parametrization, entities={1: MockedEntity(name="MyEntity")}, file_resources={1: MockedFileResource(vkt.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
]) – Return value of API.get_entity.create_child_entity (
Union
[Sequence
[MockedEntity
],MockedEntity
]) – Return value of API.create_child_entity.generate_upload_url (
Union
[Sequence
[dict
],dict
]) – Return value of API.generate_upload_url.get_current_user (
Union
[Sequence
[MockedUser
],MockedUser
]) – Return value of API.get_current_user.get_entities_by_type (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
]]) – Return value of API.get_entities_by_type.get_entity_children (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
]]) – Return value of API.get_entity_children.get_entity_siblings (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
]]) – Return value of API.get_entity_siblings.get_root_entities (
Union
[Sequence
[Sequence
[MockedEntity
]],Sequence
[MockedEntity
]]) – Return value of API.get_root_entities.get_entity_parent (
Union
[Sequence
[MockedEntity
],MockedEntity
]) – Return value of API.get_entity_parent.get_entity_revisions (
Union
[Sequence
[Sequence
[MockedEntityRevision
]],Sequence
[MockedEntityRevision
]]) – Return value of API.get_entity_revisions.get_entity_file (
Union
[Sequence
[File
],File
]) – Return value of API.get_entity_file.rename_entity (
Union
[Sequence
[MockedEntity
],MockedEntity
]) – Return value of API.rename_entity.set_entity_params (
Union
[Sequence
[MockedEntity
],MockedEntity
]) – Return value of API.set_entity_params.
- Return type:
Callable
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 import viktor as vkt from viktor.testing import mock_AxisVMAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_AxisVMAnalysis( get_model_file=vkt.File.from_path(Path(__file__).parent / 'test_model.axs'), get_result_file=vkt.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
]) – Return value of AxisVMAnalysis.get_model_file.get_result_file (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
]) – Return value of AxisVMAnalysis.get_result_file.get_results (
Union
[Sequence
[dict
],dict
]) – Return value of AxisVMAnalysis.get_results.
- Return type:
Callable
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 import viktor as vkt from viktor.testing import mock_DFoundationsAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DFoundationsAnalysis(get_output_file={ '.fod': vkt.File.from_path(Path(__file__).parent / 'test_output.fod'), '.fos': vkt.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_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 import viktor as vkt from viktor.testing import mock_DGeoStabilityAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DGeoStabilityAnalysis(get_output_file={ '.sto': vkt.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_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 import viktor as vkt from viktor.testing import mock_DSettlementAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DSettlementAnalysis(get_output_file={ '.sld': vkt.File.from_path(Path(__file__).parent / 'test_output.sld'), '.slo': vkt.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).
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 import viktor as vkt from viktor.testing import mock_DSheetPilingAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DSheetPilingAnalysis(get_output_file={ '.shd': vkt.File.from_path(Path(__file__).parent / 'test_output.shd'), '.shl': vkt.File.from_path(Path(__file__).parent / 'test_output.shl'), '.shs': vkt.File.from_path(Path(__file__).parent / 'test_output.shs'), '.sho': vkt.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 import viktor as vkt from viktor.testing import mock_DStabilityAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DStabilityAnalysis(get_output_file={ '.stix': vkt.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_DynamoAnalysis
- viktor.testing.mock_DynamoAnalysis(get_output_file=None)
- New in 14.17.0Decorator that can be used to mock
viktor.external.dynamo.DynamoAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_DynamoAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_DynamoAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_dynamo_analysis(self): MyEntityTypeController().dynamo_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_ETABSAnalysis
- viktor.testing.mock_ETABSAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.etabs.ETABSAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_ETABSAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_ETABSAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_etabs_analysis(self): MyEntityTypeController().etabs_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_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 import viktor as vkt from viktor.testing import mock_Excel from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_Excel( get_filled_template=vkt.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 (
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 (
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
]) – Return value of Excel.get_filled_template.
- Return type:
Callable
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 import viktor as vkt from viktor.testing import mock_GRLWeapAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_GRLWeapAnalysis( get_output_file=vkt.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_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 import viktor as vkt 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': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.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_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 import viktor as vkt from viktor.testing import mock_IdeaRcsAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_IdeaRcsAnalysis( get_output_file=vkt.File.from_path(Path(__file__).parent / 'test_output.xml'), get_idea_rcs_file=vkt.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_MatlabAnalysis
- viktor.testing.mock_MatlabAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.matlab.MatlabAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_MatlabAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_MatlabAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_matlab_analysis(self): MyEntityTypeController().matlab_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_ParamsFromFile
- viktor.testing.mock_ParamsFromFile(controller)
Decorator that can be used for testing methods decorated with
viktor.core.ParamsFromFile
.Example:
import unittest import viktor as vkt 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 = vkt.File.from_data("abc") returned_dict = MyEntityController().process_file(file) self.assertDictEqual(returned_dict, {...})
- Parameters:
controller (
Type
[Controller
]) – Controller class on which the ParamsFromFile should be mocked- Return type:
Callable
mock_PlaxisAnalysis
- viktor.testing.mock_PlaxisAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.plaxis.PlaxisAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_PlaxisAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_PlaxisAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_plaxis_analysis(self): MyEntityTypeController().plaxis_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_PythonAnalysis
- viktor.testing.mock_PythonAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.python.PythonAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_PythonAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_PythonAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_python_analysis(self): MyEntityTypeController().python_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_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 import viktor as vkt from viktor.testing import mock_RFEMAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_RFEMAnalysis( get_model=vkt.File.from_path(Path(__file__).parent / 'test_model.rfx') get_result={ 3: vkt.File.from_path(Path(__file__).parent / 'load_case_3.json'), 5: vkt.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).
mock_RevitAnalysis
- viktor.testing.mock_RevitAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.revit.RevitAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_RevitAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_RevitAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_revit_analysis(self): MyEntityTypeController().revit_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_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 import viktor as vkt from viktor.testing import mock_RobotAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_RobotAnalysis( get_model_file=vkt.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_SAP2000Analysis
- viktor.testing.mock_SAP2000Analysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.sap2000.SAP2000Analysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_SAP2000Analysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_SAP2000Analysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_sap2000_analysis(self): MyEntityTypeController().sap2000_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_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 import viktor as vkt from viktor.testing import mock_SciaAnalysis from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_SciaAnalysis( get_engineering_report=vkt.File.from_path(Path(__file__).parent / 'test_file.pdf'), get_updated_esa_model=vkt.File.from_path(Path(__file__).parent / 'test_file.esa'), get_xml_output_file=vkt.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
]) – Return value of SciaAnalysis.get_engineering_report.get_updated_esa_model (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
]) – Return value of SciaAnalysis.get_updated_esa_model.get_xml_output_file (
Union
[Sequence
[Union
[BytesIO
,File
]],BytesIO
,File
]) – Return value of SciaAnalysis.get_xml_output_file.
- 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 import viktor as vkt from viktor.testing import mock_Storage from app.my_entity.controller import MyEntityController class TestMyEntityController(unittest.TestCase): @mock_Storage( get=[vkt.File.from_data("abc"), vkt.File.from_data("def")], list=[{'data_key_3': vkt.File.from_data("ghi")}] ) def test_process_analysis_result(self): # Storage().get(...) invoked twice, Storage().list(...) invoked once result = MyEntityController().process_analysis_result() ...
mock_TeklaAnalysis
- viktor.testing.mock_TeklaAnalysis(get_output_file=None)
- New in 14.17.0
Decorator that can be used to mock
viktor.external.tekla.TeklaAnalysis
, to facilitate easier testing.Example:
import unittest import viktor as vkt from viktor.testing import mock_TeklaAnalysis from app.my_entity_type.controller import MyEntityTypeController class TestMyEntityTypeController(unittest.TestCase): @mock_TeklaAnalysis(get_output_file={ 'data.out': vkt.File.from_path(Path(__file__).parent / 'data.out'), 'info.log': vkt.File.from_path(Path(__file__).parent / 'info.log') }) def test_tekla_analysis(self): MyEntityTypeController().tekla_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_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 import viktor as vkt 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
[Controller
]) – Controller class on which the @View decorator should be mocked- 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 import viktor as vkt 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 = vkt.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(vkt.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 (
Union
[Parametrization
,Type
[Parametrization
]]) – Parametrization corresponding to the params.file_resources (
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 (
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