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

Use actual, real-life data #9

Merged
merged 5 commits into from
Aug 10, 2017
Merged

Use actual, real-life data #9

merged 5 commits into from
Aug 10, 2017

Conversation

leesharma
Copy link
Collaborator

@leesharma leesharma commented Aug 7, 2017

Resolves #7

This PR contains three major updates:

  • Reorganizes app as a package (for easier testing and future development)
  • Add object model (DistrictVoterData and StateVoterData)
  • Connect API to database

After this point, we should be able to delete the /api/hackathon endpoint and use real data to develop the front-end.

The app will be much easier to test (and grow) if it's set up as an
importable package. The prompt for this reorganization was writing the
tests, but I think it'll be all-around easier to work with this way.

For more information on python packages, check here:
  https://docs.python.org/3/tutorial/modules.html#packages
Works towards #7

This commit adds test-driven objects that represent state and district
voter data, both able to calculate the required values on themselves. It
contains all methods and attributes needed for our current vision of the
API.

In order to complete #7, I need to actually query the database.
Resolves #7

The `/api/states/ohio` endpoint now uses real data from the database!

Other notable changes:

  - Remove Flask-SQLAlchemy. Our database is single table and very
    denormalized, and we're only using a single query. Because of this,
    we don't need the specialized Flask-SQLAlchemy interface; a simple
    SQLAlchemy query will suffice.

  - Resource endpoints (ex. /api/ and /states/) now have a trailing
    slash. Omitting this slash will cause a 301 redirect.

  - Reorganize API to use `data`, `meta`, and `links` keys. I'm not sure
    if we'll keep them, but it makes the API more consistent.

Next up:

  - Tests should not run against the production database
  - Fix the Travis build
Fix the build.

I installed progress_report in editable mode (`pip install -e .`) in
order to allow `pytest` to find the project root. This breaks both
Travis and the Heroku build, and it's not a good idea for production.

This commit removes that dependency and changes Travis's test script to
`python3 -m pytest`; that should allow pytest to load the module without
including an editable dependency.
The goal of this commit is to get Travis to pass.

This commit introduces a fair amount of technical debt. The reasoning is
that until we add database migrations (and possibly figure out our
long-term table structure), it'll be difficult to test with postgresql.
Because of this, this commit introduces an in-memory sqlite database for
testing.
@leesharma leesharma changed the title [wip] Use actual, real-life data Use actual, real-life data Aug 8, 2017
@leesharma
Copy link
Collaborator Author

It's now functional, but the code's messier than I'd like. Some of that will stay until we figure out what we're doing with the database, but a lot of it can be improved. I'm adding docstrings and cleaning some stuff up now.

@leesharma leesharma merged commit 6c4d557 into master Aug 10, 2017
@leesharma
Copy link
Collaborator Author

Just kidding. Things may move around a lot before the mvp, so I don't want to lock them in with comments. I'll document and clean things up a bit when the code's more stable.

@leesharma leesharma deleted the lee/voter-data branch August 10, 2017 03:23
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.

1 participant