benchling_sdk.apps.config.mock_dependencies module¶

class MockBenchlingAppConfig¶

Bases: object

Mock App Config.

A helper class for easily mocking app config in various permutations.

Easily mock all config items from a manifest model (which can be loaded from benchling_sdk.apps.helpers.manifest_helpers.manifest_from_file().

__init__(config_items: List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]], decryption_provider: Optional[MockDecryptionProvider])¶

Init Mock Benchling App Config.

The class can be initialized by providing a list of AppConfigItem, but the recommended usage is to mock directly from a manifest, like MockBenchlingAppConfig.from_manifest()

property config_items: List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, TextAppConfigItem]]¶

List the config items in the mock app config, excluding any unknown types.

property config_items_with_unknown: List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]]¶

List the config items in the mock app config, including any unknown types.

classmethod from_manifest(manifest: benchling_api_client.v2.beta.models.benchling_app_manifest.BenchlingAppManifest, decryption_provider: Optional[MockDecryptionProvider] = None) → MockBenchlingAppConfig¶

From Manifest.

Reads a manifest amd mocks out all dependencies.

to_dependencies(target_dependencies: Type[benchling_sdk.apps.config.mock_dependencies.D]) → benchling_sdk.apps.config.mock_dependencies.D¶

To Dependencies.

Convenience method for providing mocked app config to a target class extending BaseDependencies.

with_replacement(replacement: Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, TextAppConfigItem]) → MockBenchlingAppConfig¶

With Replacement.

Returns a new MockBenchlingAppConfig with the app config item at the specified path replaced.

with_replacements(replacements: List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, TextAppConfigItem]]) → MockBenchlingAppConfig¶

With Replacement.

Returns a new MockBenchlingAppConfig with the app config item at the specified path replaced.

class MockDecryptionFunction¶

Bases: typing_extensions.Protocol

Mock out a decryption function for use with secure text.

__init__(*args, **kwargs)¶
class MockDecryptionProvider¶

Bases: benchling_sdk.apps.config.decryption_provider.BaseDecryptionProvider

Mock Decryption Provider.

A generic class mocking a BaseDecryptionProvider. Can be passed a function to mock arbitrary decryption.

It’s recommended to extend this class or use a specific implementation instead of initializing an instance.

__init__(mock_decryption_function: MockDecryptionFunction)¶

Init Mock Decryption Provider.

Pass a function that returns desired mocked plaintext given ciphertext.

decrypt(ciphertext: str) → str¶

Decrypt.

Invokes the mocked decryption function provided when instantiating the class to return a “decrypted” value.

class MockDecryptionProviderMapped¶

Bases: benchling_sdk.apps.config.mock_dependencies.MockDecryptionProvider

Mock Decryption Provider Mapped.

Returns a “decrypted” value based on the input ciphertext. Useful if you have multiple secrets to mock simultaneously.

__init__(decrypt_mapping: Dict[str, str])¶

Init Mock Decryption Provider Mapped.

Supply the dictionary mapping with ciphertext as keys and plaintext as values. Any ciphertext decrypted without a corresponding value will result in a KeyError.

class MockDecryptionProviderStatic¶

Bases: benchling_sdk.apps.config.mock_dependencies.MockDecryptionProvider

Mock Decryption Provider Static.

Always return the same “decrypted” value regardless of what ciphertext is passed. Useful if you only have a single secret value.

__init__(decrypt_value: str)¶

Init Mock Decryption Provider Static.

Supply the string to always be returned.

mock_app_config_items_from_manifest(manifest: benchling_api_client.v2.beta.models.benchling_app_manifest.BenchlingAppManifest) → List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]]¶

Mock Benchling App Config Items.

This method accepts an app manifest model and creates mocked values for app the app config.

The concrete mocked out values, such as API Ids and schema names are nonsensical and random, but are valid.

Code should avoid relying on specific values or conventions (such as API prefixes). If specific dependency values need to be tested in isolation, the caller can selectively override the randomized values with replace_mocked_config_item_by_path().

mock_bool_app_config_item(path: List[str], value: Optional[bool]) → BooleanAppConfigItem¶

Mock a bool app config item with a path and specified value.

mock_date_app_config_item(path: List[str], value: Optional[date]) → DateAppConfigItem¶

Mock a date app config item with a path and specified value.

mock_datetime_app_config_item(path: List[str], value: Optional[datetime]) → DatetimeAppConfigItem¶

Mock a datetime app config item with a path and specified value.

mock_float_app_config_item(path: List[str], value: Optional[float]) → FloatAppConfigItem¶

Mock a float app config item with a path and specified value.

mock_int_app_config_item(path: List[str], value: Optional[int]) → IntegerAppConfigItem¶

Mock an int app config item with a path and specified value.

mock_json_app_config_item(path: List[str], value: Optional[Union[Dict[str, Any], List[Any], str, int, float, bool]]) → JsonAppConfigItem¶

Mock an int app config item with a path and specified value.

mock_secure_text_app_config_item(path: List[str], value: Optional[str]) → SecureTextAppConfigItem¶

Mock a secure text app config item with a path and specified value.

mock_text_app_config_item(path: List[str], value: Optional[str]) → TextAppConfigItem¶

Mock a text app config item with a path and specified value.

replace_mocked_config_item_by_path(original_config: List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]], replacement_path: List[str], replacement_item: Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]) → List[Union[DateAppConfigItem, DatetimeAppConfigItem, JsonAppConfigItem, EntitySchemaAppConfigItem, FieldAppConfigItem, BooleanAppConfigItem, IntegerAppConfigItem, FloatAppConfigItem, TextAppConfigItem, GenericApiIdentifiedAppConfigItem, SecureTextAppConfigItem, benchling_api_client.v2.extensions.UnknownType]]¶

Return an updated list of app config items with a specific config item replaced with the provided mock.