Skip to content

Commit

Permalink
Use pytest-dotenv for test environment (hasgeek#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Apr 27, 2022
1 parent 04969c8 commit 327a691
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 78 deletions.
54 changes: 54 additions & 0 deletions .env.testing-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Run Flask in testing environment
FLASK_ENV='testing'

# Mail settings
MAIL_SERVER='localhost'
MAIL_PORT=25
MAIL_DEFAULT_SENDER='[email protected]'
SITE_SUPPORT_EMAIL=''
ADMINS=''

#: Keys for tests specifically
FACEBOOK_OAUTH_TOKEN=''

#: Twitter integration
OAUTH_TWITTER_KEY=''
OAUTH_TWITTER_SECRET=''

#: GitHub integration
OAUTH_GITHUB_KEY=''
OAUTH_GITHUB_SECRET=''

#: Google integration
OAUTH_GOOGLE_KEY=''
OAUTH_GOOGLE_SECRET=''

#: Recaptcha for the registration form
RECAPTCHA_PUBLIC_KEY=''
RECAPTCHA_PRIVATE_KEY=''

#: Boxoffice settings for sync tests in Cypress
CYPRESS_BOXOFFICE_SECRET_KEY=''
CYPRESS_BOXOFFICE_ACCESS_KEY''
CYPRESS_BOXOFFICE_IC_ID=
CYPRESS_BOXOFFICE_CLIENT_ID=''

#: Google Maps API key
GOOGLE_MAPS_API_KEY=''

#: YouTube API key
YOUTUBE_API_KEY=''

#: Twilio SID
SMS_TWILIO_SID=''
#: Twilio Token
SMS_TWILIO_TOKEN=''
#: Twilio test number
SMS_TWILIO_FROM='+15005550006'

#: Vimeo client id
VIMEO_CLIENT_ID=''
#: Vimeo client secret
VIMEO_CLIENT_SECRET=''
#: Vimeo access token
VIMEO_ACCESS_TOKEN=''
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ instance/container_env
secrets.dev
secrets.test
newrelic.ini
.env
.env.testing
.env.staging
.env.production

# Local venvs (Idea creates them)
venv/
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ repos:
- toml
- lxml-stubs==0.4.0
- sqlalchemy-stubs==0.4
- types-certifi==2021.10.8.1
- types-certifi==2021.10.8.2
- types-click==7.1.8
- types-cryptography==3.3.20
- types-flask==1.1.6
Expand All @@ -84,13 +84,13 @@ repos:
- types-jinja2==2.11.9
- types-markupsafe==1.1.10
- types-maxminddb==1.5.0
- types-python-dateutil==2.8.12
- types-pytz==2021.3.6
- types-requests==2.27.20
- types-python-dateutil==2.8.14
- types-pytz==2021.3.7
- types-requests==2.27.22
- types-setuptools==57.4.14
- types-simplejson==3.17.5
- types-simplejson==3.17.6
- types-six==1.16.15
- types-toml==0.10.5
- types-toml==0.10.6
- types-urllib3==1.26.13
- types-werkzeug==1.0.9
- repo: https://github.com/PyCQA/flake8
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,22 @@ default_section = 'THIRDPARTY'
sections = ['FUTURE', 'STDLIB', 'SQLALCHEMY', 'FLASK', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER']

[tool.pytest.ini_options]
addopts = '--cov-report=term-missing'
addopts = ['--cov-report=term-missing']
filterwarnings = ['ignore::DeprecationWarning', 'ignore::UserWarning']
mocked-sessions = 'coaster.db.db.session'
env_files = ['.env', '.env.testing']

[tool.pyright]
venv = "hasgeek"
venv = 'hasgeek'

reportMissingImports = true
reportMissingTypeStubs = false

pythonVersion = "3.7"
pythonVersion = '3.7'

[tool.mypy]
files = "**/*.py"
exclude = "node_modules"
files = '**/*.py'
exclude = 'node_modules'
ignore_missing_imports = true
show_error_codes = true
warn_unreachable = true
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pycountry
pyIsEmail
pymdown-extensions
python-dateutil
python-dotenv
pytz
PyVimeo
qrcode
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ python-dateutil==2.8.2
# croniter
# icalendar
# rq-scheduler
python-dotenv==0.20.0
# via -r requirements.in
python-utils==3.1.0
# via progressbar2
pytz==2022.1
Expand Down
5 changes: 3 additions & 2 deletions requirements_dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
awscli # Dupe from requirements.in due to conflicting requirements for PyYAML versions
bandit
black
flake8
flake8-assertive
flake8-bandit
Expand All @@ -23,7 +24,7 @@ sqlalchemy-stubs
toml
types-certifi
types-cryptography
types-Flask
types-flask
types-geoip2
types-itsdangerous
types-maxminddb
Expand All @@ -34,5 +35,5 @@ types-setuptools
types-simplejson
types-six
types-toml
types-Werkzeug
types-werkzeug
watchdog
32 changes: 22 additions & 10 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ bandit==1.7.4
# via
# -r requirements_dev.in
# flake8-bandit
black==22.3.0
# via -r requirements_dev.in
botocore==1.25.1
# via
# awscli
# s3transfer
cfgv==3.3.1
# via pre-commit
click==8.1.2
# via pip-tools
# via
# black
# pip-tools
colorama==0.4.4
# via awscli
distlib==0.3.4
Expand Down Expand Up @@ -84,14 +88,18 @@ lxml-stubs==0.4.0
# via -r requirements_dev.in
mccabe==0.6.1
# via flake8
mypy==0.942
mypy==0.950
# via
# -r requirements_dev.in
# sqlalchemy-stubs
mypy-extensions==0.4.3
# via mypy
# via
# black
# mypy
nodeenv==1.6.0
# via pre-commit
pathspec==0.9.0
# via black
pbr==5.8.1
# via stevedore
pep517==0.12.0
Expand All @@ -101,7 +109,9 @@ pep8-naming==0.12.1
pip-tools==6.6.0
# via -r requirements_dev.in
platformdirs==2.5.2
# via virtualenv
# via
# black
# virtualenv
pre-commit==2.18.1
# via -r requirements_dev.in
pyasn1==0.4.8
Expand Down Expand Up @@ -151,9 +161,10 @@ toml==0.10.2
# pre-commit
tomli==2.0.1
# via
# black
# mypy
# pep517
types-certifi==2021.10.8.1
types-certifi==2021.10.8.2
# via -r requirements_dev.in
types-click==7.1.8
# via types-flask
Expand All @@ -175,19 +186,19 @@ types-maxminddb==1.5.0
# via
# -r requirements_dev.in
# types-geoip2
types-python-dateutil==2.8.12
types-python-dateutil==2.8.14
# via -r requirements_dev.in
types-pytz==2021.3.6
types-pytz==2021.3.7
# via -r requirements_dev.in
types-requests==2.27.20
types-requests==2.27.22
# via -r requirements_dev.in
types-setuptools==57.4.14
# via -r requirements_dev.in
types-simplejson==3.17.5
types-simplejson==3.17.6
# via -r requirements_dev.in
types-six==1.16.15
# via -r requirements_dev.in
types-toml==0.10.5
types-toml==0.10.6
# via -r requirements_dev.in
types-urllib3==1.26.13
# via types-requests
Expand All @@ -197,6 +208,7 @@ types-werkzeug==1.0.9
# types-flask
typing-extensions==4.2.0
# via
# black
# mypy
# sqlalchemy-stubs
urllib3==1.26.9
Expand Down
1 change: 1 addition & 0 deletions requirements_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lxml
pytest
pytest-bdd
pytest-cov
pytest-dotenv
requests-mock
5 changes: 5 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ pytest==7.1.2
# -r requirements_test.in
# pytest-bdd
# pytest-cov
# pytest-dotenv
pytest-bdd==5.0.0
# via -r requirements_test.in
pytest-cov==3.0.0
# via -r requirements_test.in
pytest-dotenv==0.5.2
# via -r requirements_test.in
python-dotenv==0.20.0
# via pytest-dotenv
requests==2.27.1
# via
# coveralls
Expand Down
3 changes: 0 additions & 3 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/bin/bash
set -e
export FLASK_ENV="TESTING"
if [ -f secrets.test ]; then
source ./secrets.test
fi
if [ $# -eq 0 ]; then
pytest --cov=funnel
else
Expand Down
51 changes: 0 additions & 51 deletions secrets.test.sample

This file was deleted.

3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def db_connection(database):


# This fixture borrowed from
# https://github.com/jeancochrane/pytest-flask-sqlalchemy/issues/46#issuecomment-829694672
# https://github.com/jeancochrane/pytest-flask-sqlalchemy/issues/46
# #issuecomment-829694672
@pytest.fixture(scope='function')
def db_session(database, db_connection):
"""Create a nested transaction for the test and roll it back after."""
Expand Down

0 comments on commit 327a691

Please sign in to comment.