edx_django_utils.data_generation.tests package

Contents

edx_django_utils.data_generation.tests package#

Submodules#

edx_django_utils.data_generation.tests.apps module#

Tests for Data Generation

class edx_django_utils.data_generation.tests.apps.DataGenerationTestsConfig(app_name, app_module)#

Bases: AppConfig

label = 'data_generation_tests'#
name = 'edx_django_utils.data_generation.tests'#

edx_django_utils.data_generation.tests.factories module#

Factories for models used in testing manufacture_data command

class edx_django_utils.data_generation.tests.factories.AbstractFactory(**kwargs)#

Bases: DjangoModelFactory

Test factory for making sure our factory discovery doesn’t choke on abstract factory classes

class edx_django_utils.data_generation.tests.factories.TestCompanyFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for TestCompany

ceo = <factory.declarations.SubFactory object>#
company_name = 'Acme, Inc'#
national_id = <factory.declarations.SubFactory object>#
class edx_django_utils.data_generation.tests.factories.TestContactInfoFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for TestContactInfo

address = '123 4th st, Fiveville, AZ, 67890'#
test_company = <factory.declarations.SubFactory object>#
test_person = <factory.declarations.SubFactory object>#
class edx_django_utils.data_generation.tests.factories.TestModelNonstandardCasingFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for test_model_nonstandard_casing

test_field = 'TEST'#
class edx_django_utils.data_generation.tests.factories.TestNationalIdFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for TestNationalId

id_number = '123456789'#
class edx_django_utils.data_generation.tests.factories.TestPersonContactPhoneNumberFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for TestPersonContactPhoneNumber

phone_number = '(123) 456-7890'#
test_contact_info = <factory.declarations.SubFactory object>#
class edx_django_utils.data_generation.tests.factories.TestPersonFactory(**kwargs)#

Bases: DjangoModelFactory

Test Factory for TestPerson

first_name = 'John'#
last_name = 'Doe'#
national_id = <factory.declarations.SubFactory object>#

edx_django_utils.data_generation.tests.models module#

Models used in testing manufacture_data command

class edx_django_utils.data_generation.tests.models.TestCompany(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

ceo#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

ceo_id#
company_name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

national_id#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

national_id_id#
objects = <django.db.models.manager.Manager object>#
testcontactinfo_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class edx_django_utils.data_generation.tests.models.TestContactInfo(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

address#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
test_company#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

test_company_id#
test_person#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

test_person_id#
testpersoncontactphonenumber_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class edx_django_utils.data_generation.tests.models.TestNationalId(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id_number#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
testcompany_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

testperson_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class edx_django_utils.data_generation.tests.models.TestPerson(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

first_name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

national_id#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

national_id_id#
objects = <django.db.models.manager.Manager object>#
testcompany_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

testcontactinfo_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class edx_django_utils.data_generation.tests.models.TestPersonContactPhoneNumber(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
phone_number#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

test_contact_info#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

test_contact_info_id#
class edx_django_utils.data_generation.tests.models.test_model_nonstandard_casing(*args, **kwargs)#

Bases: Model

For use in testing manufacture_data command

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
test_field#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

edx_django_utils.data_generation.tests.test_management module#

Test management commands and related functions.

class edx_django_utils.data_generation.tests.test_management.ManufactureDataCommandTests(methodName='runTest')#

Bases: TestCase

Test command manufacture_data.

command = 'manufacture_data'#
pytestmark = [Mark(name='django_db', args=(), kwargs={})]#
test_argv_command_can_customize_nested_objects()#

argv: Test that the manufacture_data command supports customizing nested objects.

test_argv_command_error()#

argv error: Nested model does not exist

test_argv_system_check_error(handleMock)#

argv error: SystemCheckError

test_command_builds_chains_of_pk()#

Test that the manufacture_data command supports customizing nested objects.

test_command_can_customize_doubly_nested_objects()#

Test that the manufacture_data command supports customizing nested objects.

test_command_can_customize_fields()#

Test that the manufacture_data command will create a single object with customizations.

test_command_can_customize_multiple_nested_objects()#

Test that the manufacture_data command supports customizing nested objects.

test_command_can_customize_nested_objects()#

Test that the manufacture_data command supports customizing nested objects.

test_command_can_customize_nested_objects_with_fk()#

Test that the manufacture_data command supports customizing nested objects.

test_command_cannot_customize_foreign_keys()#

Error case: customizing provided objects.

test_command_cannot_customize_nested_foreign_keys()#

Error case: customizing nested provided objects.

test_command_cannot_edit_created_fk()#

Error case: trying to edit foreign key after foreign key object has already been created

test_command_nested_nonexistent_attribute()#

Error case: Nested model does not exist

test_command_nested_nonexistent_model()#

Error case: Nested model does not exist

test_command_object_foreign_key()#

Test that the manufacture_data command supports creating objects with foreign keys

test_command_requires_model()#

Test that the manufacture_data command will raise an error if no model is provided.

test_command_requires_valid_field()#

Test that the manufacture_data command will raise an error if the provided field is invalid.

test_command_requires_valid_model()#

Test that the manufacture_data command will raise an error if the provided model is invalid.

test_node_no_factory()#

Node error case: no factory provided

test_node_str()#

Node __str__ test

test_nonstandard_casing()#

Test that the manufacture_data command will work with models that use non-standard casing

test_single_object_create_no_customizations()#

Test that the manufacture_data command will create a single object with no customizations.

class edx_django_utils.data_generation.tests.test_management.TestCommand(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: Command

Class for use in testing manufacture_data command via run_from_argv

check(*args)#

Use the system check framework to validate entire Django project. Raise CommandError for any serious message (error or critical errors). If there are only light messages (like warnings), print them to stderr and don’t raise an exception.

edx_django_utils.data_generation.tests.test_management.call_command(command_name, *args, **options)#

Call the given command, with the given options and args/kwargs.

This is the primary API you should use for calling specific commands.

command_name may be a string or a command object. Using a string is preferred unless the command object is required for further processing or testing.

Some examples:

call_command(‘migrate’) call_command(‘shell’, plain=True) call_command(‘sqlmigrate’, ‘myapp’)

from django.core.management.commands import flush cmd = flush.Command() call_command(cmd, verbosity=0, interactive=False) # Do something with cmd …

Module contents#

Tests for Data Generation