system-config/testinfra/test_etherpad.py

61 lines
2.5 KiB
Python

# Copyright 2018 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import urllib.parse
testinfra_hosts = ['etherpad99.opendev.org']
def test_etherpad_listening(host):
etherpad = host.socket("tcp://127.0.0.1:9001")
assert etherpad.is_listening
def test_etherpad_robots(host):
cmd = host.run('curl --insecure '
'--resolve etherpad.opendev.org:443:127.0.0.1 '
'https://etherpad.opendev.org/robots.txt')
assert 'Disallow: /' in cmd.stdout
def test_etherpad_logs(host):
etherpad_log_file = host.file('/var/log/containers/docker-etherpad.log')
assert etherpad_log_file.exists
assert etherpad_log_file.contains('Etherpad is running')
mariadb_log_file = host.file('/var/log/containers/docker-mariadb.log')
assert mariadb_log_file.exists
assert mariadb_log_file.contains('mysqld: ready for connections')
def test_etherpad_4_byte_utf8(host):
# The 🖖 utf8 character is a four byte character. This test ensures we
# can set that value in a pad and get it back out again. This test both
# general functionality as well as proper database setup for four byte
# utf8 chars
teststr = '🖖 Live long and prosper 🖖'
urlstr = urllib.parse.quote(teststr)
cmd = host.run('sudo docker-compose -f '
'/etc/etherpad-docker/docker-compose.yaml '
'exec -T etherpad cat /opt/etherpad-lite/APIKEY.txt')
token = cmd.stdout.strip()
cmd = host.run('wget -qO- "http://localhost:9001/api/1/createPad?'
'apikey=%s&padID=testing"' % token)
assert '"code":0' in cmd.stdout
assert '"message":"ok"' in cmd.stdout
cmd = host.run('wget -qO- "http://localhost:9001/api/1/setText?'
'apikey=%s&padID=testing&text=%s"' % (token, urlstr))
assert '"code":0' in cmd.stdout
assert '"message":"ok"' in cmd.stdout
cmd = host.run('wget -qO- "http://localhost:9001/api/1/getText?'
'apikey=%s&padID=testing"' % token)
assert teststr in cmd.stdout