Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Test review apps. #273

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release: python manage.py migrate --noinput
release: utility/heroku-release.sh
web: gunicorn config.wsgi:application
worker: python manage.py rqworker default
15 changes: 13 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
"formation": {
"web": {
"quantity": 1,
"size": "free"
"size": "Private-S"
},
"worker": {
"quantity": 1,
"size": "free"
"size": "Private-S"
}
},
"scripts": {
Expand All @@ -126,6 +126,17 @@
"env": {
"DJANGO_SETTINGS_MODULE": "config.settings.test"
}
},
"review": {
"scripts": {
"test-setup": "pip install --upgrade -r requirements/test.txt",
"test": "pytest"
},
"addons": ["heroku-postgresql:in-dyno", "heroku-redis:in-dyno"],
"env": {
"DJANGO_SETTINGS_MODULE": "config.settings.integration_tests"
},
"space": "sfdoc"
}
}
}
14 changes: 4 additions & 10 deletions config/settings/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,13 @@
}
}

# django-debug-toolbar
# ------------------------------------------------------------------------------
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
INSTALLED_APPS += ["debug_toolbar"]

INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"]

DEBUG_TOOLBAR_CONFIG = {
"DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
"SHOW_TEMPLATE_CONTEXT": True,
}

# django-extensions
# ------------------------------------------------------------------------------
INSTALLED_APPS += ["django_extensions"]

# TESTING
# ------------------------------------------------------------------------------
TEST_RUNNER = "django.test.runner.DiscoverRunner"
Expand Down Expand Up @@ -81,6 +72,8 @@
SALESFORCE_JWT_PRIVATE_KEY = process_key(env("SALESFORCE_JWT_PRIVATE_KEY"))
SALESFORCE_SANDBOX = env.bool("SALESFORCE_SANDBOX")
SALESFORCE_USERNAME = env("SALESFORCE_USERNAME")
SALESFORCE_ARTICLE_LINK_LIMIT = 100


# django-rq
REDIS_URL = env("REDIS_URL", default="redis://localhost:6379")
Expand All @@ -99,5 +92,6 @@

# easyDITA
EASYDITA_INSTANCE_URL = env("EASYDITA_INSTANCE_URL")
EASYDITA_USERNAME = env("EASYDITA_USERNAME")
# One of our test cases changed in EasyDITA and needs to be fixed back.
EASYDITA_USERNAME = "mock" # env("EASYDITA_USERNAME")
EASYDITA_PASSWORD = env("EASYDITA_PASSWORD")
16 changes: 16 additions & 0 deletions sfdoc/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import pytest
import environ
from django.conf import settings

# this recipe convinces pytest-sjango to use the pre-existing
# database instead of creating a new one. Heroku apps seem
# to not have permissions to create databases on the fly.

# https://pytest-django.readthedocs.io/en/latest/database.html#using-an-existing-external-database-for-tests

if os.environ.get("HEROKU_APP_NAME", "").startswith("sfdoc-review-apps-"):
env = environ.Env()
@pytest.fixture(scope='session')
def django_db_setup():
settings.DATABASES['default'] = env.db("DATABASE_URL")
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a clarifying comment in 231b1ff.

6 changes: 6 additions & 0 deletions utility/heroku-release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

if os.environ.get("HEROKU_APP_NAME", "").startswith("sfdoc-review-apps-"):
assert not os.system("pip install --upgrade -r requirements/test.txt")
os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.integration_tests"
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use the --ds option for pytest instead. https://pytest-django.readthedocs.io/en/latest/configuring_django.html#command-line-option-ds-settings

I'll leave this up to you but it seems a bit silly to have heroku-release.sh call into Python just to shell back out to run other commands...

assert not os.system("pytest")
2 changes: 2 additions & 0 deletions utility/heroku-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python manage.py migrate --noinput
python utility/heroku-release.py