terraformtestinglib.testing package

Submodules

terraformtestinglib.testing.testing module

Main code for testing.

class terraformtestinglib.testing.testing.Attribute(resource, name, value)[source]

Bases: object

Models the attribute.

resource_name

Exposes the name of the parent resource object.

Returns:The name of the parent resource
Return type:name (basestring)
resource_type

Exposes the type of the parent resource object.

Returns:The type of the parent resource
Return type:type (basestring)
class terraformtestinglib.testing.testing.AttributeList(validator, attributes)[source]

Bases: object

Object containing attribute objects and providing validation methods for them.

attribute(name)[source]

Filters attributes on matching the provided name.

Parameters:name (basestring) – The name to match the attribute with
Returns:A container of attribute objects
Return type:AttributeList
if_has_attribute_with_value(attribute, value)[source]

Filters the AttributeList based on the provided attribute and value.

Parameters:
  • attribute – The attribute to filter on
  • value – the value of the attribute to filter on
Returns:

A container of attribute objects

Return type:

AttributeList

if_not_has_attribute_with_value(attribute, value)[source]

Filters the AttributeList based on the provided attribute and value.

Parameters:
  • attribute – The attribute to filter on
  • value – the value of the attribute to filter on
Returns:

A container of attribute objects

Return type:

AttributeList

should_be_valid_json()[source]

Checks whether the value for the attribute is valid json.

Raises:AssertionError – If any errors are found on the check
Returns:None
should_equal(value)[source]

Checks for equality for the provided value from all contained attributes.

Parameters:value – The value to match with
Raises:AssertionError – If any errors are found on the check
Returns:None
should_have_attributes(attributes)[source]

Checks for existence for the provided attribute from all contained attributes.

Parameters:attributes – An attribute or list of attributes to check for
Raises:AssertionError – If any errors are found on the check
Returns:None
should_match_regex(regex)[source]

Checks for regular expression match from all contained attributes.

Parameters:regex (basestring) – A regular expression to match with
Raises:AssertionError – If any errors are found on the check
Returns:None
should_not_equal(value)[source]

Checks for inequality for the provided value from all contained attributes.

Parameters:value – The value to not match with
Raises:AssertionError – If any errors are found on the check
Returns:None
should_not_have_attributes(attributes)[source]

Checks for lack for the provided attribute from all contained attributes.

Parameters:attributes – An attribute or list of attributes to check for
Raises:AssertionError – If any errors are found on the check
Returns:None
should_not_match_regex(regex)[source]

Checks for regular expression not matching from all contained attributes.

Parameters:regex (basestring) – A regular expression to not match with
Raises:AssertionError – If any errors are found on the check
Returns:None
class terraformtestinglib.testing.testing.Container(validator_instance, entities)[source]

Bases: object

An object handling the exposing of attributes of different resources of terraform.

attribute(name)[source]

Filters attributes based on the provided name.

Parameters:name (basestring) – The name to match against
Raises:AssertionError – If any errors are calculated
Returns:An object containing any attributes matching the check
Return type:AttributeList (list)
attribute_matching_regex(regex)[source]

Filters attributes based on the provided regex.

Parameters:regex (basestring) – A basestring of a valid regular expression to match against
Raises:AssertionError – If any errors are calculated
Returns:An object containing any attributes matching the check
Return type:AttributeList (list)
if_has_attribute(attribute)[source]

Filters the entities based on the provided attribute.

Parameters:attribute (basestring) – The attribute to filter the resources on
Returns:An entities list object with all resources following the pattern
Return type:(list)
if_has_attribute_with_regex_value(attribute, regex)[source]

Filters the entities based on the provided attribute and value.

Parameters:
  • attribute (basestring) – The attribute to filter the entities on if the value matches the regex provided
  • regex – The regex to match with
Returns:

An entities list object with all entities following the pattern

Return type:

(list))

if_has_attribute_with_value(attribute, value)[source]

Filters the entities based on the provided attribute and value.

Parameters:
  • attribute (basestring) – The attribute to filter the entities on
  • value – The value to match with
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_has_subattribute(parent_attribute, attribute)[source]

Filters the entities based on the provided parent and child attribute.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the resources on
  • attribute (basestring) – The child attribute to filter the entities on if it exists
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_has_subattribute_with_regex_value(parent_attribute, attribute, regex)[source]

Filters the entities based on the provided parent and child attribute and regex for value matching.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the entities on
  • attribute (basestring) – The child attribute to filter the entities on
  • regex – The regex to match with for the child attribute’s value
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_has_subattribute_with_value(parent_attribute, attribute, value)[source]

Filters the entities based on the provided parent and child attribute and value.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the entities on
  • attribute (basestring) – The child attribute to filter the entities on
  • value – The value to match with for the child attribute
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_not_has_attribute(attribute)[source]

Filters the entities based on the non existence of the provided attribute.

Parameters:attribute (basestring) – The attribute to filter the resources on
Returns:An entities list object with all entities following the pattern
Return type:(list))
if_not_has_attribute_with_regex_value(attribute, regex)[source]

Filters the entities based on the provided attribute and value.

Parameters:
  • attribute (basestring) – The attribute to filter the entities on if the value does not match the regex
  • regex – The regex not to match with
Returns:

An entities list object with all entities following the pattern

Return type:

(list))

if_not_has_attribute_with_value(attribute, value)[source]

Filters the entities based on the provided attribute and value.

Parameters:
  • attribute (basestring) – The attribute to filter the resources on
  • value – The value to not match
Returns:

An entities list object with all entities following the pattern

Return type:

(list))

if_not_has_subattribute(parent_attribute, attribute)[source]

Filters the entities based on the provided parent and child attribute.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the entities on
  • attribute (basestring) – The child attribute to filter the entities on if it does not exists
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_not_has_subattribute_with_regex_value(parent_attribute, attribute, regex)[source]

Filters the entities based on the provided parent and child attribute and regex for value matching.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the entities on
  • attribute (basestring) – The child attribute to filter the entities on
  • regex – The regex to not match with for the child attribute’s value
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

if_not_has_subattribute_with_value(parent_attribute, attribute, value)[source]

Filters the entities based on the provided parent and child attribute and value.

Parameters:
  • parent_attribute (basestring) – The parent attribute to filter the entities on
  • attribute (basestring) – The child attribute to filter the entities on
  • value – The value to not match with for the child attribute
Returns:

An entities list object with all entities following the pattern

Return type:

(list)

should_have_attributes(attributes_list)[source]

Validates that the resource has the provided arguments which are always cast to a list.

Parameters:attributes_list (list) – A list of strings for attributes to check against
Raises:AssertionError – If any errors are calculated
Returns:None
should_not_have_attributes(attributes_list)[source]

Validates that the resource does not have the provided arguments which are always cast to a list.

Parameters:attributes_list (list) – A list of strings for attributes to check against
Raises:AssertionError – If any errors are calculated
Returns:None
class terraformtestinglib.testing.testing.Data(type: str, name: str, data: Any)[source]

Bases: terraformtestinglib.testing.testing.Entity

Basic model of a data object exposing required attributes.

class terraformtestinglib.testing.testing.DataList(validator_instance, entities)[source]

Bases: terraformtestinglib.testing.testing.Container

A list of data objects being capable to filter on specific requirements.

class terraformtestinglib.testing.testing.Entity(type: str, name: str, data: Any)[source]

Bases: object

Basic model of an entity exposing required attributes.

class terraformtestinglib.testing.testing.Provider(type: str, name: str, data: Any)[source]

Bases: terraformtestinglib.testing.testing.Entity

Basic model of a provider object exposing required attributes.

class terraformtestinglib.testing.testing.ProviderList(validator_instance, entities)[source]

Bases: terraformtestinglib.testing.testing.Container

A list of provider objects being capable to filter on specific requirements.

class terraformtestinglib.testing.testing.Resource(type: str, name: str, data: Any)[source]

Bases: terraformtestinglib.testing.testing.Entity

Basic model of a resource exposing required attributes.

class terraformtestinglib.testing.testing.ResourceList(validator_instance, entities)[source]

Bases: terraformtestinglib.testing.testing.Container

A list of resource objects being capable to filter on specific requirements.

resources(type_)[source]

Filters resources based on resource type which is always cast to list.

Parameters:type (list|basestring) – The type of resources to filter on. Always gets cast to list.
Raises:AssertionError – If any errors are calculated
Returns:An object containing any resources matching the type
Return type:ResourceList (list)
class terraformtestinglib.testing.testing.Terraform(type: str, name: str, data: Any)[source]

Bases: terraformtestinglib.testing.testing.Entity

Basic model of a provider object exposing required attributes.

class terraformtestinglib.testing.testing.TerraformList(validator_instance, entities)[source]

Bases: terraformtestinglib.testing.testing.Container

A list of terraform objects being capable to filter on specific requirements.

class terraformtestinglib.testing.testing.Validator(configuration_path, global_variables_file_path=None, raise_on_missing_variable=True, environment_variables=None)[source]

Bases: terraformtestinglib.terraformtestinglib.Parser

Object exposing resources and variables of terraform plans.

data(type_)[source]

Filters data based on data type which is always cast to list.

Parameters:type (basestring|list) – The type of data attributes to filter on. Always gets cast to a list.
Returns:An object containing the data matching the type provided
Return type:DataList
get_variable_value(variable)[source]

Retrieves the variable value from the global view state.

Parameters:variable (basestring) – The variable to retrieve the value for
Returns:The value of the retrieved variable
Return type:value
provider(type_)[source]

Filters providers based on provider type which is always cast to list.

Parameters:type (basestring|list) – The type of provider to filter on. Always gets cast to a list.
Returns:An object containing the providers matching the type provided
Return type:ProviderList
resources(type_)[source]

Filters resources based on resource type which is always cast to list.

Parameters:type (basestring|list) – The type of resources to filter on. Always gets cast to a list.
Returns:An object containing the resources matching the type provided
Return type:ResourceList
terraform(type_)[source]

Filters terraform entries based on provided type which is always cast to list.

Parameters:type (basestring|list) – The type of terraform attributes to filter on. Always gets cast to a list.
Returns:An object containing the terraform objects matching the type provided
Return type:TerraformList
static to_list(value)[source]

Casts to list the provided argument if not a list already.

Parameters:value (basestring|list) – Casts the provided value to list if not already
Returns:A list of the value or values
Return type:value (list)
variable(name)[source]

Returns a variable object of the provided name.

Parameters:name (basestring) – The name of the variable to retrieve
Returns:An object modeling a variable
Return type:Variable
class terraformtestinglib.testing.testing.Variable(name, value)[source]

Bases: object

Models a variable and exposes basic test for it.

value_equals(value)[source]

Checks that the value equals the provided value.

Raises:AssertionError – If any errors are found on the check
Returns:None
value_exists()[source]

Checks that the value exists.

Raises:AssertionError – If any errors are found on the check
Returns:None
value_matches_regex(regex)[source]

Checks that the value matches the provided regex.

Raises:AssertionError – If any errors are found on the check
Returns:None
terraformtestinglib.testing.testing.assert_on_error(func)[source]

Raises assertion error exceptions if the wrapped method returned any errors.

Module contents

terraformtestinglib.testing package.

Import all parts from terraformtestinglib.testing here