This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds e2e_tests djangoapp with `e2e_test` command. Adds the utiliites for e2e tests Adds make command and e2e_tests app in INSTALLED_APPS requirements: Update selenium to 3.141.0 Add e2e tests in circle CI
- Loading branch information
1 parent
7644ebe
commit c66807b
Showing
17 changed files
with
1,133 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
E2E_TESTS=true | ||
FIREFOX_BINARY_PATH='/usr/local/bin/firefox' | ||
DEBUG=true | ||
SECRET_KEY='tests' | ||
DATABASE_URL='postgres://localhost/opencraft' | ||
DEFAULT_INSTANCE_MYSQL_URL='mysql://root@127.0.0.1' | ||
DEFAULT_INSTANCE_MONGO_URL='mongodb://127.0.0.1' | ||
HUEY_ALWAYS_EAGER=true | ||
OPENSTACK_USER='test' | ||
OPENSTACK_PASSWORD='pass' | ||
OPENSTACK_TENANT='test-tenant' | ||
OPENSTACK_AUTH_URL='http://example.com/auth/url' | ||
OPENSTACK_REGION='test-region' | ||
DEFAULT_INSTANCE_BASE_DOMAIN='example.com' | ||
GANDI_API_KEY='TEST_GANDI_API_KEY' | ||
GITHUB_ACCESS_TOKEN='test-token' | ||
BASE_HANDLERS='["file"]' | ||
BACKUP_SWIFT_ENABLED=true | ||
PRELIMINARY_PAGE_SERVER_IP='47.11.08.15' | ||
DEFAULT_LOAD_BALANCING_SERVER='ubuntu@haproxy-test.fake.domain' | ||
LOAD_BALANCER_FRAGMENT_NAME_PREFIX='opencraft-' | ||
DEFAULT_RABBITMQ_API_URL='https://admin:password@rabbitmq.example.com:15671' | ||
DEFAULT_INSTANCE_RABBITMQ_URL='amqps://rabbitmq.example.com:5671' | ||
CONSUL_ENABLED=false | ||
CONSUL_SERVERS=haproxy-integration.net.opencraft.hosting | ||
DISABLE_LOAD_BALANCER_CONFIGURATION=false | ||
MAILCHIMP_ENABLED=false | ||
MAILCHIMP_API_KEY='deadc0dedeadc0dedeadc0dedeadc0de-us7' | ||
MAILCHIMP_LIST_ID_FOR_TRIAL_USERS='badc0de' | ||
INSTANCE_STORAGE_TYPE='s3' | ||
AWS_ACCESS_KEY_ID='1234' | ||
AWS_SECRET_ACCESS_KEY='5678' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# OpenCraft -- tools to aid developing and hosting free software projects | ||
# Copyright (C) 2015-2020 OpenCraft <xavier@opencraft.com> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
""" | ||
Utility functions related to frontend server for e2e testing. | ||
""" | ||
import http.server | ||
import os | ||
|
||
from urllib.parse import urlparse | ||
from threading import Thread | ||
|
||
|
||
# Functions ################################################################# | ||
|
||
def start_react_server( | ||
build_path="./frontend/build", | ||
hostname="localhost", | ||
port=3000 | ||
): | ||
""" | ||
Start a react server in different thread. | ||
""" | ||
build_path = os.path.abspath(build_path) | ||
handler = RequestHandler | ||
httpd = http.server.HTTPServer((hostname, port), handler, False) | ||
|
||
httpd.server_bind() | ||
address = "http://%s:%d" % (httpd.server_name, httpd.server_port) | ||
|
||
print("Server starting at:", address) | ||
httpd.server_activate() | ||
|
||
def serve_forever(httpd): | ||
# Switch to the frontend build directory | ||
os.chdir(build_path) | ||
with httpd: # to make sure httpd.server_close is called | ||
print("Frontend server started (infinite request loop):", build_path) | ||
httpd.serve_forever() | ||
print("Shutting down frontend server") | ||
|
||
thread = Thread(target=serve_forever, args=(httpd, )) | ||
thread.setDaemon(True) | ||
thread.start() | ||
|
||
return httpd, address | ||
|
||
|
||
# Classes ################################################################ | ||
|
||
class RequestHandler(http.server.SimpleHTTPRequestHandler): | ||
""" | ||
RequestHandler for react frontend server. We send the index file | ||
instead of 404. | ||
""" | ||
|
||
INDEXFILE = "index.html" | ||
|
||
def log_message(self, format, *args): # pylint: disable=redefined-builtin | ||
""" | ||
Override to supress logs of accessed paths. | ||
""" | ||
|
||
def do_GET(self): # noqa | ||
""" | ||
Override get method to send the INDEXFILE when the requested file is not found. | ||
""" | ||
parsed_params = urlparse(self.path) | ||
|
||
try: | ||
# See if the file requested exists and accessible | ||
if os.access('.' + os.sep + parsed_params.path, os.R_OK): | ||
http.server.SimpleHTTPRequestHandler.do_GET(self) | ||
else: | ||
# send index.html, but don't redirect | ||
index_file = os.path.join(os.getcwd(), self.INDEXFILE) | ||
self.send_response(200) | ||
self.send_header('Content-Type', 'text/html') | ||
self.end_headers() | ||
with open(index_file, 'rb') as fin: | ||
self.copyfile(fin, self.wfile) | ||
except BrokenPipeError: | ||
# The client closed connection. We can ignore the exception here. | ||
pass |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# OpenCraft -- tools to aid developing and hosting free software projects | ||
# Copyright (C) 2015-2019 OpenCraft <contact@opencraft.com> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
""" | ||
Django Command e2e_test for running e2e_tests | ||
""" | ||
|
||
from django.core.management.commands import test | ||
|
||
from e2e_tests.frontend_server import start_react_server | ||
|
||
|
||
class Command(test.Command): | ||
""" | ||
Management command to run the e2e test. | ||
Start the frontend server and run the tests in e2e application. | ||
""" | ||
def handle(self, *args, **options): | ||
httpd, _ = start_react_server() | ||
args = (*args, 'e2e_tests') | ||
try: | ||
super(Command, self).handle(*args, **options) | ||
finally: | ||
httpd.shutdown() |
Empty file.
Oops, something went wrong.