-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add manufacture_data django command
test: Fix test configuration test: improve test coverage test: case for nonstandard model casing test: more coverage docs: Add documentation for manufacture_data
- Loading branch information
1 parent
185f884
commit 0c6b27f
Showing
21 changed files
with
957 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Django Data Generation | ||
###################### | ||
|
||
|
||
Setup | ||
===== | ||
Add 'edx_django_utils.data_generation' to `INSTALLED_APPS` | ||
|
||
Usage | ||
===== | ||
|
||
(Using https://github.com/openedx/edx-enterprise/blob/master/enterprise/models.py through Devstack as an example) | ||
|
||
Generating Basic Model | ||
---------------------- | ||
Upon invoking the command, supply a model param (--model) that is a complete path to a model that has a corresponding test factory: | ||
|
||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomer` | ||
|
||
This will generate an enterprise customer record with place holder values according to the test factory | ||
|
||
Customizing Model Values | ||
------------------------ | ||
We can also provide customizations to the record being generated: | ||
|
||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomer --name "FRED"` | ||
|
||
'EnterpriseCustomer' fields: {'name': 'FRED'} | ||
|
||
We can supply parent model/subfactory customizations as well: | ||
|
||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerCatalog --enterprise_customer__site__name "Fred" --enterprise_catalog_query__title "JOE SHMO" --title "who?"` | ||
|
||
'EnterpriseCustomerCatalog' fields: {'title': 'who?'} | ||
'EnterpriseCustomer' fields: {} | ||
'Site' fields: {'name': 'Fred'} | ||
|
||
'EnterpriseCatalogQuery' fields: {'title': 'JOE SHMO'} | ||
|
||
Note the non subclass customization --title "who?" is applied to the specified model EnterpriseCustomerCatalog | ||
|
||
Customizing Foreign Keys | ||
------------------------ | ||
Say we want to supply an existing record as a FK to our object: | ||
|
||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer 994599e6-3787-48ba-a2d1-42d1bdf6c46e` | ||
|
||
'EnterpriseCustomerUser' fields: {} | ||
'EnterpriseCustomer' PK: 994599e6-3787-48ba-a2d1-42d1bdf6c46e | ||
|
||
or we can do something like: | ||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer__site 9 --enterprise_customer__name "joe"` | ||
|
||
'EnterpriseCustomerUser' fields: {} | ||
'EnterpriseCustomer' fields: {'name': 'joe'} | ||
'Site' PK: 9 | ||
|
||
Unsupported Cases | ||
----------------- | ||
One limitation of this script is that it can only fetch or customize, you cannot customize a specified, existing FK: | ||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer__site__name "fred" --enterprise_customer 994599e6-3787-48ba-a2d1-42d1bdf6c46e` | ||
|
||
which would yield a | ||
`CommandError: This script does not support customizing provided existing objects` | ||
|
||
Error Cases | ||
----------- | ||
|
||
If you try and get something that doesn't exist: | ||
|
||
`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer <invalid uuid>` | ||
|
||
we'd get: | ||
`CommandError: Provided FK value: <SOMETHING BAD> does not exist on EnterpriseCustomer` |
Empty file.
Empty file.
Empty file.
Oops, something went wrong.