Skip to content
Snippets Groups Projects
Commit 59db5cd6 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

tests: Use empty database and register admin user for cypress use

parent 84214873
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,13 @@ run-migrations-prod:
django-admin migrate --settings=swh.web.settings.production -v0 2>/dev/null
django-admin createcachetable --settings=swh.web.settings.production -v0 2>/dev/null
.PHONY: run-migrations-test
run-migrations-test:
rm -f swh/web/settings/testdb.sqlite3
django-admin migrate --settings=swh.web.settings.tests -v0 2>/dev/null
django-admin createcachetable --settings=swh.web.settings.tests -v0 2>/dev/null
cat swh/web/tests/create_test_admin.py | django-admin shell --settings=swh.web.settings.tests
.PHONY: clear-memcached
clear-memcached:
echo "flush_all" | nc -q 2 localhost 11211 2>/dev/null
......@@ -60,9 +67,9 @@ run-django-webpack-memory-storages: build-webpack-dev run-migrations
test-full:
$(TEST) $(TESTFULL_FLAGS) $(TEST_DIRS)
test-frontend: build-webpack-test run-migrations
test-frontend: build-webpack-test run-migrations-test
python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & sleep 10 && $(YARN) run cypress run && pkill -P $$! && $(YARN) run mochawesome
test-frontend-ui: build-webpack-test run-migrations
test-frontend-ui: build-webpack-test run-migrations-test
bash -c "trap 'trap - SIGINT SIGTERM ERR EXIT; jobs -p | head -1 | xargs pkill -P' SIGINT SIGTERM ERR EXIT; python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & sleep 10 && $(YARN) run cypress open"
......@@ -84,6 +84,7 @@ DEFAULT_CONFIG = {
}
}),
'development_db': ('string', os.path.join(SETTINGS_DIR, 'db.sqlite3')),
'test_db': ('string', os.path.join(SETTINGS_DIR, 'testdb.sqlite3')),
'production_db': ('string', '/var/lib/swh/web.sqlite3'),
'deposit': ('dict', {
'private_api_url': 'https://deposit.softwareheritage.org/1/private/',
......
......@@ -79,6 +79,13 @@ swh_web_config.update({
from .common import * # noqa
from .common import ALLOWED_HOSTS, LOGGING # noqa
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': swh_web_config['test_db'],
}
}
# when not running unit tests, make the webapp fetch data from memory storages
if 'pytest' not in sys.argv[0]:
swh_web_config.update({
......
# Copyright (C) 2019 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
from django.contrib.auth import get_user_model
username = 'admin'
password = 'admin'
email = 'admin@swh-web.org'
User = get_user_model()
if not User.objects.filter(username=username).exists():
User.objects.create_superuser(username, email, password)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment