edx_django_utils.data_generation.management.commands package#
Submodules#
edx_django_utils.data_generation.management.commands.manufacture_data module#
Management command for making instances of models with test factories.
- param model:
complete path to a model that has a corresponding test factory
- param {model_attribute}:
(Optional) Value of a model’s attribute that will override test factory’s default value
- param {model_foreignkey__foreignkey_attribute}:
(Optional) Value of a model’s attribute that will override test factory’s default attribute value
- class edx_django_utils.data_generation.management.commands.manufacture_data.Command(stdout=None, stderr=None, no_color=False, force_color=False)#
Bases:
BaseCommandManagement command for generating Django records from factories with custom attributes
- Example usage:
$ ./manage.py manufacture_data –model enterprise.models.enterprise_customer –name “Test Enterprise” –slug “test-enterprise”
- add_arguments(parser)#
Entry point for subclassed commands to add custom arguments.
- handle(*args, **options)#
Entry point for management command execution.
- Parameters:
args – list of command line arguments passed to management command
options – dict of command line argument key/values
- run_from_argv(argv)#
Re-implemented from django/django in order to support individual field customization. We will need to keep this method up to date with our current version of Django BaseCommand.
Uses
parse_known_argsinstead ofparse_argsto not throw an error when encountering unknown argumentshttps://docs.python.org/3.8/library/argparse.html#argparse.ArgumentParser.parse_known_args :param argv: list of command line arguments passed to management command
- class edx_django_utils.data_generation.management.commands.manufacture_data.Node(model_name, field_name=None, field_path=None)#
Bases:
objectNon-binary tree node class for building out a dependency tree of objects to create with customizations.
- add_child(child_node)#
Add a child to the current node
- Parameters:
child_node – Child node object to add
- build_records()#
Recursively build out the tree of objects by first dealing with children nodes before getting to the parent.
- find_node(field_path)#
Find a node in the tree by path
- Parameters:
field_path – Full path hierarchy of the node to find (Example: TestPersonContactPhoneNumber.test_contact_info.test_person)
- set_single_customization(field, value)#
Set a single customization value to the current node, overrides existing values under the same key.
- Parameters:
field – Field for node’s model
value – Value to set field to
- edx_django_utils.data_generation.management.commands.manufacture_data.all_non_abstract_subfactories()#
Get all non-abstract subclasses of DjangoModelFactory Based on our operating definition of ‘Abstract’ (Given there isn’t native support for abstract classes in python). If a DjangoModelFactory has a meta model defined, we assume it is non-abstract.
- edx_django_utils.data_generation.management.commands.manufacture_data.all_subclasses(cls)#
Recursively get all subclasses of a class
https://stackoverflow.com/a/3862957 :param cls: class to get subclasses for
- edx_django_utils.data_generation.management.commands.manufacture_data.build_tree_from_field_list(list_of_fields, provided_factory, base_node, customization_value)#
Builds a non-binary tree of nodes based on a list of children nodes, using a base node and its associated data factory as the parent node the user provided value as a reference to a potential, existing record.
- Parameters:
list_of_fields (list of strings) – the linked list of associated objects to create. Example- [‘enterprise_customer_user’, ‘enterprise_customer’, ‘site’]
provided_factory (factory.django.DjangoModelFactory) – The data factory of the base_node.
base_node (Node) – The parent node of the desired tree to build.
customization_value (string) – The value to be assigned to the object associated with the last value in the
list_of_fieldsparam. Can either be a FK if the last value is a subfactory, or alternatively a custom value to be assigned to the field. Example- list_of_fields = [‘enterprise_customer_user’, ‘enterprise_customer’, ‘site’], customization_value = 9 or list_of_fields = [‘enterprise_customer_user’, ‘enterprise_customer’, ‘name’], customization_value = “FRED”
- edx_django_utils.data_generation.management.commands.manufacture_data.convert_to_pascal_if_needed(name)#
Helper method to convert snake_cased names to Pascal(CapWords) case.
- Parameters:
name – word to convert to PascalCase, if it is snake_case
- edx_django_utils.data_generation.management.commands.manufacture_data.is_snake_name(name)#
Helper method to detect if name is snake_case (lowercase separated by underscores).
- Parameters:
name – word to test if it follows snake_case convention
- edx_django_utils.data_generation.management.commands.manufacture_data.pairwise(iterable)#
Convert a list into a list of tuples of adjacent elements.
s -> [ (s0, s1), (s2, s3), (s4, s5), … ] :param iterable: List to convert