satellite_populate package¶
Submodules¶
satellite_populate.api module¶
Implements API populator using Nailgun
-
class
satellite_populate.api.
APIPopulator
(data, verbose=None, mode=None, config=None)[source]¶ Bases:
satellite_populate.base.BasePopulator
Populates system using API/Nailgun
-
action_create
(rendered_action_data, action_data, search, model, silent_errors)[source]¶ Creates new entity if does not exists or get existing entity and return Entity object
-
action_delete
(rendered_action_data, action_data, search, model, silent_errors)[source]¶ Deletes an existing entity
-
action_update
(rendered_action_data, action_data, search, model, silent_errors)[source]¶ Updates an existing entity
-
add_and_log_error
(action_data, rendered_action_data, search, e=None)[source]¶ Add to validation errors and outputs error
-
satellite_populate.assertion_operators module¶
Implement basic assertions to be used in assertion action
satellite_populate.base module¶
Base module for satellite_populate reads the YAML definition and perform all the rendering and basic actions.
-
class
satellite_populate.base.
BasePopulator
(data, verbose=None, mode=None, config=None)[source]¶ Bases:
object
Base class for API and CLI populators
-
action_echo
(rendered_action_data, action_data)[source]¶ After message is echoed to log, check if needs print
-
action_register
(rendered_action_data, action_data)[source]¶ Register arbitrary items to the registry
-
add_rendered_action
(action_data, rendered_action_data)[source]¶ Add rendered action to be written in validation file
-
build_search
(rendered_action_data, action_data, context=None)[source]¶ Build search data and returns a dict containing elements
- data Dictionary of parsed rendered_action_data to be used to i nstantiate an object to searched without raw_query.
- options if search_options are specified it is passed to .search(**options)
- searchable Returns boolean True if model inherits from EntitySearchMixin, else alternative search must be implemented.
if search_query is available in action_data it will be used instead of rendered_action_data.
-
build_search_options
(data, action_data)[source]¶ Builds nailgun options for search raw_query: Some API endpoints demands a raw_query, so build it as in example: {‘query’: {‘search’:’name=name,label=label,id=28’}}
force_raw: Returns a boolean if action_data.force_raw is explicitly specified
-
config
¶ Return config dynamically because it can be overwritten by user in datafile or by custom populator
-
crud_actions
¶ Return a list of crud_actions, actions that gets data and perform nailgun crud operations so custom populators can overwrite this list to add new crud actions.
-
execute
(mode=None)[source]¶ Iterates the entities property described in YAML file and parses its values, variables and substitutions depending on mode execute populate or validate
-
from_read
(action_data, context)[source]¶ Gets fields and perform a read to return Entity object used when ‘from_read’ directive is used in YAML file
-
from_search
(action_data, context)[source]¶ Gets fields and perform a search to return Entity object used when ‘from_search’ directive is used in YAML file
-
load_raw_search_rules
()[source]¶ Reads default search rules then update first with custom populator defined rules and then user defined in datafile.
-
populate
(rendered_action_data, raw_entity, search_query, action)[source]¶ Should be implemented in sub classes
-
populate_modelname
(rendered_action_data, action_data, search_query, action)[source]¶ Example on how to implement custom populate methods e.g: def populate_organization This method should take care of all validations and errors.
-
raw_search_rules
¶ Subclasses of custom populators can extend this rules
-
render
(action_data, action)[source]¶ Takes an entity description and strips ‘data’ out to perform single rendering and also handle repetitions defined in with_items
-
render_action_data
(data, context)[source]¶ Gets a single action_data and perform inplace template rendering or reference evaluation depending on directive being used.
-
resolve_result
(data, from_where, k, v, result)[source]¶ Used in from_search and from_object to get specific attribute from object e.g: name. Or to invoke a method when attr is a dictionary of parameters.
-
satellite_populate.cli module¶
To be implemented: a populator using CLI
satellite_populate.commands module¶
This module contains commands to interact with satellite populator and validator.
Commands included:
satellite-populate¶
A command to populate the system based in an YAML file describing the entities:
$ satellite-populate file.yaml -h myhost.com -o /tmp/validation.yaml
validate¶
A command to validate the system based in an validation file generated by the populate or a YAML file with mode: validation:
$ satellite-populate /tmp/validation.yaml
Use $ satellite-populate --help
for more info
satellite_populate.constants module¶
Default base config values
satellite_populate.decorators module¶
decorators for populate feature
-
satellite_populate.decorators.
populate_with
(data, context_name=None, context_wrapper=<function default_context_wrapper>, **extra_options)[source]¶ To be used in test cases as a decorator
Having a data_file like:
actions: - model: Organization register: organization_1 data: name: My Org
Then you can use in decorators:
@populate_with('file.yaml') def test_case_(self): 'My Org exists in system test anything here'
And getting the populated entities inside the test_case:
@populate_with('file.yaml', context_name='my_context') def test_case_(self, my_context=None): assert my_context.organization_1.name == 'My Org'
You can also set a customized context wrapper to the context_wrapper argument:
def my_custom_context_wrapper(result): # create an object using result my_context = MyResultContext(result) return my_context @populate_with('file.yaml', context_name='my_context', content_wrapper=my_custom_context_wrapper) def test_case_(self, my_context=None): # assert with some expression using my_context object returned # my_custom_context_wrapper assert some_expression
NOTE:
That is important that ``context_name`` argument always be declared using either a default value ``my_context=None`` or handle in ``**kwargs`` Otherwise ``py.test`` may try to use this as a fixture placeholder. if context_wrapper is set to None, my_context will be the pure unmodified result of populate function.
satellite_populate.main module¶
Point of entry for populate and validate used in scripts
-
satellite_populate.main.
default_context_wrapper
(result)[source]¶ Takes the result of populator and keeps only useful data e.g. in decorators context.registered_name, context.config.verbose and context.vars.admin_username will all be available.
-
satellite_populate.main.
get_populator
(data, **kwargs)[source]¶ Gets an instance of populator dynamically
-
satellite_populate.main.
populate
(data, **kwargs)[source]¶ Loads and execute populator in populate mode
-
satellite_populate.main.
save_rendered_data
(result, filepath)[source]¶ Save the result of rendering in a new file to be used for validation
-
satellite_populate.main.
setup_yaml
()[source]¶ Set YAML to use OrderedDict http://stackoverflow.com/a/8661021
satellite_populate.utils module¶
-
class
satellite_populate.utils.
SmartDict
(*args, **kwargs)[source]¶ Bases:
dict
A Dict which is accessible via attribute dot notation
-
satellite_populate.utils.
import_from_string
(import_name, *args, **kwars)[source]¶ Try import string and then try builtins
Module contents¶
This package contains tools to populate and validate the system