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

Refactor: organize application as a package #140

Merged
merged 19 commits into from
Sep 7, 2022
Merged

Conversation

angela-tran
Copy link
Member

@angela-tran angela-tran commented Aug 31, 2022

Part of #131

Closes #139

This PR makes changes to the organization of our code so that

  • database-related code is grouped together
  • our application can be imported as a package.

This should allow us to move towards using the app factory pattern, which in turn should move us towards using a separate database when testing.

Note that the setup.py and teardown.py scripts for modifying the database were converted into click commands to facilitate moving them into a db sub-package and since that's the approach shown in Flask documentation.

@angela-tran angela-tran added this to the Courtesy Cards milestone Aug 31, 2022
@angela-tran angela-tran self-assigned this Aug 31, 2022
@angela-tran angela-tran requested a review from a team as a code owner August 31, 2022 00:44
Copy link
Member

@machikoyasuda machikoyasuda left a comment

Choose a reason for hiding this comment

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

Small documentation change.

I ran and tested:

  • Ran cp .env.sample .env
  • Ran docker compose build --no-cache server
  • Ran and passed all tests
  • Opened http://localhost:5000/healthcheck, http://localhost:5000/publickey
  • Tested flask drop-db

docs/getting-started.md Show resolved Hide resolved
@machikoyasuda
Copy link
Member

I believe this PR also closes #139

@thekaveman
Copy link
Member

👀 Started reading through this tonight, will finish a little later or tomorrow!

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

This looks like a good direction overall.

I'm not totally thrilled with the Database class (nothing you did in this PR) - it feels weird, we called it that in the past because it literally was the hardcoded database. Now it's just that check_user function... which is really doing the eligibility check? Oh well. Not too worried about this for now.

Left a few comments inline, a few areas we need some changes and a few potential cleanups/reorgs.

setup.py Outdated Show resolved Hide resolved
eligibility_server/db/setup.py Show resolved Hide resolved
eligibility_server/db/teardown.py Outdated Show resolved Hide resolved
eligibility_server/verify.py Show resolved Hide resolved
eligibility_server/db/models.py Outdated Show resolved Hide resolved
eligibility_server/db/setup.py Outdated Show resolved Hide resolved
eligibility_server/verify.py Show resolved Hide resolved
@angela-tran
Copy link
Member Author

Thanks @machikoyasuda and @thekaveman for your thorough reviews! I agree with the things you pointed out and will work through these items.

@angela-tran
Copy link
Member Author

@thekaveman I made some changes based on your feedback. Also, I agree with this:

I'm not totally thrilled with the Database class (nothing you did in this PR) - it feels weird, we called it that in the past because it literally was the hardcoded database. Now it's just that check_user function... which is really doing the eligibility check? Oh well. Not too worried about this for now.

Should I try to move the check_user logic into the verify module as a part of this PR?

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

All of my comments below are mostly stylistic and don't require any changes.

But one thing that should be addressed: We want the Docker app container to install this package!

Need a line in the Dockerfile like:

RUN pip install -e .

Obviously the source and setup.py need to the in the image layer for this to work, so may need to adjust how/where pip install happens, or just do it a second time if that's preferable.

eligibility_server/app.py Outdated Show resolved Hide resolved
eligibility_server/db/database.py Outdated Show resolved Hide resolved
eligibility_server/db/models.py Outdated Show resolved Hide resolved
eligibility_server/verify.py Show resolved Hide resolved
eligibility_server/db/__init__.py Outdated Show resolved Hide resolved
eligibility_server/app.py Show resolved Hide resolved
eligibility_server/verify.py Outdated Show resolved Hide resolved
tests/test_database.py Outdated Show resolved Hide resolved
@thekaveman
Copy link
Member

thekaveman commented Sep 2, 2022

@angela-tran

@thekaveman I made some changes based on your feedback. Also, I agree with this:

I'm not totally thrilled with the Database class (nothing you did in this PR) - it feels weird, we called it that in the past because it literally was the hardcoded database. Now it's just that check_user function... which is really doing the eligibility check? Oh well. Not too worried about this for now.

Should I try to move the check_user logic into the verify module as a part of this PR?

Didn't see this comment before leaving my review - but yeah that could be a better place for it! Maybe turn verify into a sub-package with api.py and somethingelse.py?

setup.py Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

Looks great!

  • All tests passed locally
  • The package is installed (in a python REPL session I could import eligibility_server)
  • /healthcheck, /publickey, /verify return expected results

@angela-tran angela-tran merged commit 06037dd into main Sep 7, 2022
@angela-tran angela-tran deleted the refactor/package branch September 7, 2022 21:56
@angela-tran angela-tran mentioned this pull request Nov 14, 2022
10 tasks
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.

Fix setup/teardown logging
3 participants