Skip to content

Commit

Permalink
Add live server for browser tests (hasgeek#1439)
Browse files Browse the repository at this point in the history
Also includes multiplexing app for dev and test runtime and direct invocation of pytest.
  • Loading branch information
jace authored Aug 3, 2022
1 parent c1e2a0f commit 7909d16
Show file tree
Hide file tree
Showing 46 changed files with 984 additions and 392 deletions.
31 changes: 17 additions & 14 deletions .env.testing-sample
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
# Run Flask in testing environment
FLASK_ENV='testing'

# Specify HOSTALIASES file for platforms that support it
HOSTALIASES=${PWD}/HOSTALIASES

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

#: Keys for tests specifically
# Keys for tests specifically
FACEBOOK_OAUTH_TOKEN=''

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

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

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

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

#: Boxoffice settings for sync tests in Cypress
# 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
GOOGLE_MAPS_API_KEY=''

#: YouTube API key
# YouTube API key
YOUTUBE_API_KEY=''

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

#: Vimeo client id
# Vimeo client id
VIMEO_CLIENT_ID=''
#: Vimeo client secret
# Vimeo client secret
VIMEO_CLIENT_SECRET=''
#: Vimeo access token
# Vimeo access token
VIMEO_ACCESS_TOKEN=''
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ baseframe-packed.*
# Download files
geoname_data

# Log files
# Log and test files
error.log
error.log.*
ghostdriver.log
geckodriver.log
tests/screenshots

# Instance Files that should not be checked-in.
# Instance files that should not be checked-in
instance/development.py
instance/hasgeekapp.py
instance/production.py
Expand Down
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:
args:
['--keep-runtime-typing', '--py3-plus', '--py36-plus', '--py37-plus']
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: &flake8deps
Expand Down Expand Up @@ -89,7 +89,7 @@ repos:
- types-all
- typing-extensions
- repo: https://github.com/PyCQA/flake8
rev: 5.0.2
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: *flake8deps
Expand All @@ -104,9 +104,9 @@ repos:
'--ignore-paths=tests,migrations',
]
additional_dependencies:
- toml
- pylint-pytest
- pylint-flask-sqlalchemy
- pylint-pytest
- toml
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
Expand Down Expand Up @@ -156,3 +156,10 @@ repos:
hooks:
- id: djlint-jinja
files: \.html\.(jinja2|j2)$
- id: djlint-handlebars
files: \.html\.(mustache|hb)$
- repo: https://github.com/ducminh-phan/reformat-gherkin
rev: v3.0.0
hooks:
- id: reformat-gherkin
files: \.feature$
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_script:
- psql -c 'create database geoname_testing;' -U postgres
- 'flask dbconfig | sudo -u postgres psql geoname_testing'
script:
- './runtests.sh'
- 'pytest'
# - './runfrontendtests.sh'
after_success:
- coveralls
Expand Down
4 changes: 4 additions & 0 deletions HOSTALIASES
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy these entries into your /etc/hosts

127.0.0.1 funnel.test
127.0.0.1 f.test
33 changes: 33 additions & 0 deletions devserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
"""Development server with multi-app switching."""

import os
import sys

from werkzeug import run_simple

if __name__ == '__main__':
sys.path.insert(0, os.path.dirname(__file__))
os.environ['FLASK_ENV'] = 'development'

from funnel import rq
from funnel.devtest import BackgroundWorker, devtest_app

background_rq = None
if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
# Only start RQ worker within the reloader environment
background_rq = BackgroundWorker(rq.get_worker().work)
background_rq.start()

run_simple(
os.environ.get('FLASK_RUN_HOST', '127.0.0.1'),
int(os.environ.get('FLASK_RUN_PORT', 3000)),
devtest_app,
use_reloader=True,
use_debugger=True,
use_evalex=True,
threaded=True,
)

if background_rq:
background_rq.stop()
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- 3000:3000
depends_on:
- redis
command: sh ./runserver.sh
command: sh ./devserver.py
volumes:
#- .:/app
- $HOME/.aws/credentials:/app/.aws/credentials:ro
Expand Down
3 changes: 3 additions & 0 deletions funnel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

redis_store = FlaskRedis(decode_responses=True)
rq = RQ()
rq.job_class = 'rq.job.Job'
rq.queues = ['funnel'] # Queues used in this app
executor = Executor()

# --- Assets ---------------------------------------------------------------------------
Expand Down Expand Up @@ -84,6 +86,7 @@
from .models import db # isort:skip # pylint: disable=wrong-import-position

# --- Configuration---------------------------------------------------------------------

app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=365)
coaster.app.init_app(app, ['py', 'toml'])
coaster.app.init_app(shortlinkapp, ['py', 'toml'], init_logging=False)
Expand Down
Loading

0 comments on commit 7909d16

Please sign in to comment.