cots.mock – Mocking Product Handlers

This module is a mocking product handler to test the lapptrack module or any python module using the cots package.

This module differs from the dummy module, because the latter exists as an example (more precisely as a skeleton) to implement a product handler.

Public Classes

This module includes a number of handlers listed below in alphabetical order. A mocking handler is a derived class from the BaseMockHandler class.

BaseMockHandler

FailureMockHandler

ErrorMockHandler

MockHandler

Objects reference

This section details the objects defined in this module.

class cots.mock.BaseMockHandler

Bases: cots.core.BaseProduct

Common base class for mocking handler.

This class is a base class for mocking handler used to test the lapptrack module or any python module using the cots package. Most of information about handler mechanism are in the cots.core module and more particularly in the BaseProduct class documentation.

Overridden Methods

This class is a concrete class, so the overridden methods are listed below in alphabetical order.

dump

is_update

fetch

load

get_origin

dump()

Dump the handler class attributes.

The method use a variable named attributes to store a copy of public attributes. The attributes content may be altered by the script.

Returns

Contain a copy of the instance variables values.

Return type

dict

fetch(dirpath)

Download the mocking installer.

Parameters

dirpath (str) – The directory path name where to store the installer package.

Returns

True if the fake installer creation went well. In case of failure, the members are not modified and an error log is written.

Return type

bool

Raises

TypeError – Parameters type mismatch.

get_origin()

Get the mocking information.

Returns

always True.

Return type

bool

is_update(product)

Return if this instance is an update.

This method compare the version of the two product, and return the comparison result. The version numbers used by the editor are compliant with the semantic versioning specification 2.0.0 (see support.semver module)

Parameters

product (BaseProduct) – The reference product (i.e. the deployed one)

Returns

True if this instance is an update of the product specified by the product parameter.

Return type

bool

load(attributes=None)

Load the saved handler class attributes.

Parameters

attributes (dict) – The instance variables values to set. Previous value of the instance variables kept if this argument value is None. The key value pairs which don’t exist in the instance variables dictionary are ignored.

Raises

TypeError – Parameters type mismatch.

class cots.mock.MockHandler

Bases: cots.mock.BaseMockHandler

Mocking handler.

This concrete class implements a mocking handler used to test the lapptrack module or any python module using the cots package. Most of information about handler mechanism are in the cots.core and more particularly in the BaseProduct class documentation.

class cots.mock.BrotherMockHandler

Bases: cots.mock.BaseMockHandler

Mocking handler.

This concrete class implements a mocking handler (similar to MockHandler) used to test the lapptrack module or any python module using the cots package.

get_origin()

Get the mocking information.

Returns

always True.

Return type

bool

class cots.mock.FailureMockHandler

Bases: cots.mock.BaseMockHandler

Failure mocking handler.

This concrete class implements a mocking handler used to test the lapptrack module or any python module using the cots package. This handler always return an error on the fetch or get_origin method call. In this context, is_update method should not be called so his call raise an RuntimeError exception.

Overridden Methods

This class is a concrete class, so the overridden methods are listed below in alphabetical order.

fetch

is_update

get_origin

fetch(dirpath)

Download the mocking installer.

This method always return False to indicate that an error has occurred while the product installer fetching.

Parameters

dirpath (str) – The directory path name where to store the installer package.

Returns

True if the download of the file went well. In case of failure, the members are not modified and an error log is written.

Return type

bool

Returns

always False.

Return type

bool

get_origin()

Get the mocking information.

This method always return False to indicate that an error has occurred while the fetching of the product information.

Returns

always False.

Return type

bool

is_update(product)

Return if this instance is an update.

In this context, this method should not be called.

Parameters

product (BaseProduct) – The reference product (i.e. the deployed one)

Raises

RuntimeError – see above.

class cots.mock.ErrorMockHandler

Bases: cots.mock.BaseMockHandler

Error mocking handler.

This concrete class implements a mocking handler used to test the lapptrack module or any python module using the cots package. This handler raises an TypeError exception on the fetch or get_origin method call. In this context, is_update method should not be called so his call raise an RuntimeError exception.

Overridden Methods

This class is a concrete class, so the overridden methods are listed below in alphabetical order.

fetch

is_update

get_origin

fetch(dirpath)

Download the mocking installer.

This method always raises an TypeError exception.

Parameters

dirpath (str) – The path name where to store the installer package.

Raises

TypeError – see above.

get_origin()

Get the mocking information.

This method always raises an TypeError exception.

Raises

TypeError – see above.

is_update(product)

Return if this instance is an update.

In this context, this method should not be called.

Parameters

product (BaseProduct) – The reference product (i.e. the deployed one)

Raises

RuntimeError – see above.