Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate seed data for dev/staging using factories #129

Merged
merged 7 commits into from
Apr 16, 2020

Conversation

chris48s
Copy link
Contributor

@chris48s chris48s commented Apr 8, 2020

Closes #115

This PR adds a django management command init_data which can be used to populate the DB with some test data and removes the existing JSON fixtures.
The test data generated is random and meaningless, so you'll end up with a resource called "Road stage could least" tagged with "blue" and "head", but as the models and tests evolve the test data we can generate should evolve with it. It also gives us flexibility about how much data we generate, for example.
It might be that there are particular conditions we want to ensure are always created in the test data. For example, one I've already ensured happens is that at least one resource has zero tags attached to it, but if we think of more we can always extend this, and it should be much easier than manipulating ~1000 line JSON files.

$ docker-compose run --rm app ./manage.py init_data --help

usage: manage.py init_data [-h] [--clear-db] [--num-users NUM-USERS]
                           [--num-tags NUM-TAGS]
                           [--num-resources NUM-RESOURCES] [--version]
                           [-v {0,1,2,3}] [--settings SETTINGS]
                           [--pythonpath PYTHONPATH] [--traceback]
                           [--no-color] [--force-color]

Initialize the DB with some random fake data for testing and development

optional arguments:
  --clear-db            Clear existing data from the DB before creating test
                        data
  --num-users NUM-USERS
                        Number of `User` objects to create (default 10)
  --num-tags NUM-TAGS   Number of `Tag` objects to create (default 10)
  --num-resources NUM-RESOURCES
                        Number of `Resource` objects to create (default 10)
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output

This constraint prevents us from tagging a resource
with the same tag more than once when we're creating
TaggedItems objects via factories.

This is already applied as a soft-constraint at the manager
level when creating via `resource.tags.add()`,
but the factories bypass it. This applies it at the DB level
@codecov
Copy link

codecov bot commented Apr 8, 2020

Codecov Report

Merging #129 into master will increase coverage by 5.11%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage   76.33%   81.44%   +5.11%     
==========================================
  Files          28       29       +1     
  Lines         393      469      +76     
==========================================
+ Hits          300      382      +82     
+ Misses         93       87       -6     
Impacted Files Coverage Δ
project/core/management/commands/init_data.py 83.56% <83.56%> (ø)
project/tagging/factories.py 100.00% <100.00%> (+100.00%) ⬆️
project/tagging/models.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5eb5b6...c47e7ef. Read the comment docs.

Copy link
Member

@lpatmo lpatmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this! Learned a lot from your FactoryBoy setup too. Feel free to merge! :)

@chris48s chris48s merged commit 56c7c90 into codebuddies:master Apr 16, 2020
@lpatmo lpatmo mentioned this pull request Apr 29, 2020
@lpatmo lpatmo mentioned this pull request Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Testing] [WIP] Use Factory-Boy to Create Seed Data for Dev and Staging DBs
2 participants