Skip to content

Commit

Permalink
Create fake data for testing (#932)
Browse files Browse the repository at this point in the history
* Create NewsFactory

* Update Faker and move to one factory per apps

* Implement HighlightFactory

* Update the highlight tests

* 1. Implement factories for Person, InternetHealthIssue, and Affiliation models.
2. WIP implement factories Homepage and HomepageHighlights models. HomepageLeaders and HomepageNews factories are not implemented yet.

* news factory WIP

* 1. fixes for highlights factory and tests
2. fixes for homepage factory and tests
3. fixes for people factory

* 1. Implement HomepageLeaderFactory tests
2. Fix the post_generation check for a tuple in the PersonFactory

* lint fixes

* Implement tests for the PersonFactory class

* Fix news factory and tests. Fix some typos

* Move tests in a tests folder per app + HighlightFactory tests

* Add milestone factory + tests

* Remove UTC and general cleanup

* make the milestone duration a datetime.datetime, and make it configurable

* Refactor Highlight View Tests

1. Refactor the view tests to use rest_framework.test.APIRequestFactory so that the view classes can be directly tested
2. Separate the HighlightView and HighlightListView tests into separate TestCase classes
3. Test only one thing in each test case of HighlightView and HighlightListView

* HightlightFactory test cleanup

* Homepage Factories Tests

1. Move homepage app tests into a tests directory
2. Refactor the HomepageFactory, HomepageLeadersFactory, HomepageNewsFactory and HomepageHighlightsFactory tests so they test only what makes sense - i.e We shouldn't test that functionality provided by FakerBoy can pass arguments to sub-factories

* WIP Homepage view tests

* Fix views tests + typo

* first try at the management command

*  FileField Support

1. Add some placeholder images for generated models
2. Write a custom provider for Faker that can generate paths to the placeholder images
3. Using a post_generate hook, update the 'name' attribute on the FileFields. This must be done in a post_generate hook so that we don't have to constantly be reading and writing and duplicating images as we generate data (images are shared amongst the models).

* Small fix

* Such change, very wow

1. Implemented LandingPage Factory and tests
2. test cleanup in basically all the test files
3. used moar LazyAttributes so that we can join arrays of sentences/paragraphs/words or strip trailing periods from Faker lorem data
4. fixed linting issues
5. removed fixture data
6. changed LOAD_FIXTURE to LOAD_FAKE_DATA
7. wired up the new management command to the heroku release command

* Management command day!
1: Revert paragraphs generation changes back to Faker.paragraph()
2: Change start date in milestones to have events in the recent section
3: Create a management command that can wipe previous database data and generate new fake one

Need to fiw some todos in the management command + write tests for it

* 1. Separate model deletion into a separate management command, and call it when requested in the load_fake_data command
2. Add coverage and remove fake-factory requirements.py
3. Add in stdout logging to the comands
4. Create a base opportunity page, like staging/prod, and make it the parent of the other opportunity pages
5. For each person, generate and associate an affiliation

* Generate actual Internet Health Issue objects, to be associated with the generated People

* remove unused import, report coverage to coveralls

* fix invalid YAML in .travis.yml

* how did that sneak back in there

* try removing trailing slashes

* It helps if you do not hard code the pk

* add coveralls badge

* copy paste fail

* 1. Add a seed option to ensure reproducible output
2. Add landing pages with CTAs

* Modify the command to load fake data on Heroku review apps

* fix a lint error

* Small fixes + readme update

* Always provide our own seed value to Faker, so we can output it, for reproducible results

* update app.json

* update readme

* missed a typo
  • Loading branch information
patjouk authored and Christopher DeCairos committed Jan 17, 2018
1 parent 85f2775 commit 7786116
Show file tree
Hide file tree
Showing 44 changed files with 1,457 additions and 5,015 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ before_script:
script:
- npm test
- flake8 network-api/
- python network-api/manage.py test
- coverage run --source './network-api/networkapi' network-api/manage.py test networkapi
after_success:
- coveralls
env:
global:
- DEBUG=True
Expand Down
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Dependency Status](https://david-dm.org/mozilla/network.svg)](https://david-dm.org/mozilla/network)
[![Dev Dependency Status](https://david-dm.org/mozilla/network/dev-status.svg)](https://david-dm.org/mozilla/network/?type=dev)
[![Uses Mofo Standards](https://MozillaFoundation.github.io/mofo-standards/badge.svg)](https://github.com/MozillaFoundation/mofo-standards)
[![Code Coverage](https://coveralls.io/repos/github/mozilla/foundation.mozilla.org/badge.svg?branch=master)](https://coveralls.io/github/mozilla/foundation.mozilla.org)

## Development

Expand Down Expand Up @@ -47,29 +48,28 @@ Install all dependencies into the virtual environment:

- `pip install -r ../requirements.txt`

#### Run migrate and load fixtures
#### Run migrate and load fake model data


Migrate the database to the latest schema:

- `python manage.py migrate`

By default, Django sets the site domain to `example.com`, but the mock data needs the domain to be `localhost:8000`. Run the following command to update the site domain automatically
By default, Django sets the site domain to `example.com`, but the fake data needs the domain to be `localhost:8000`. Run the following command to update the site domain automatically

- `python manage.py update_site_domain`

Mock data can be loaded into your dev site with the following command
Fake model data can be loaded into your dev site with the following command

- `python manage.py loaddata networkapi/fixtures/test_data.json`
- `python manage.py load_fake_data`

This will set up a default superuser account for you to use:
Create an admin user using the following command

- username: `testuser`
- pass: `networktest`
- `python manage.py createsuperuser`

#### From scratch database

If you'd prefer not to load in the fixture data, you can use the following commands to get started:
If you'd prefer not to load in fake model data, you can use the following commands to get started:

```bash
python manage.py migrate
Expand All @@ -86,10 +86,29 @@ The site should now be accessible at `https://localhost:8000`

To log in to the admin UI, visit: http://localhost:8000/admin

#### Generating a new set of fake model data

You can empty your database and create a full new set of fake model data using the following command

- `python manage.py load_fake_data --delete`

You can generate a specific set of fake model data by entering a seed value

- `python manage.py load_fake_data --delete --seed VALUE`

If a seed is not provided, a pseudorandom one will be generated and logged to the console. You can share this value with others if you need them to generate the same set of data that you have.

#### Running the project for front-end development

- At the root of the project you can run: `npm start`, which will start the server as well as watch tasks for recompiling changes to Pug, JS, and Sass files.

#### Tests

When relevant, we encourage you to write tests.
You can run the tests using the following command

- `python manage.py test`

---

### Stack
Expand Down Expand Up @@ -164,7 +183,7 @@ The `DEBUG` flag does all sorts of magical things, to the point where testing wi

- Django uses its own built-in static content server, in which template tags may behave *differently* from the Mezzanine static server, which can lead to `400 Bad Request` errors in `DEBUG=False` setting.
- Django bypasses the `ALLOWED_HOST` restrictions, which again can lead to `400 Bad Request` errors in `DEBUG=False` setting.
- Rather than HTTP error pages, Django will generate stack traces pages that expose pretty much all enviroment variables except any that match certain substrings such as `KEY`, `PASS`, etc. for obvious security reasons.
- Rather than HTTP error pages, Django will generate stack traces pages that expose pretty much all environment variables except any that match certain substrings such as `KEY`, `PASS`, etc. for obvious security reasons.
- ...there are probably more gotchas just for `DEBUG` so if you find any please add them to this list.

#### Use of `{ static "...." }` in templates
Expand Down Expand Up @@ -197,7 +216,7 @@ Default environment variables are declared in `env.default`. If you wish to over

The domain used to fetch static content from Network Pulse can be customized by specifying `PULSE_API_DOMAIN`. By default it uses `network-pulse-api-production.herokuapp.com`.

The URL for fetching static content from the Network API can be customized by specifying `NETWORK_SITE_URL`. By default it uses `https://foundation.mozilla.org`. NOTE: this variable must include a protocol (such as `https://`)
The URL for fetching static content from the Network API can be customized by specifying `NETWORK_SITE_URL`. By default it uses `https://foundation.mozilla.org`. **NOTE: this variable must include a protocol (such as `https://`)**

---
### Security
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"CSP_MEDIA_SRC": "'self'",
"CSP_CHILD_SRC": "'self'",
"CSP_FORM_ACTION": "'self' https://www.mozilla.org/en-US/newsletter/",
"LOAD_FIXTURE": "True"
"EXECUTE_FAKE_DATA": "True"
},
"buildpacks": [
{
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7786116

Please sign in to comment.