-
Notifications
You must be signed in to change notification settings - Fork 6
/
tests.py
44 lines (36 loc) · 1.34 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import docker
import requests
client = docker.from_env()
time.sleep(10) # we expect all containers are up and running in 10 secs
for c in client.containers.list():
print("{}: {}".format(c.name, c.status))
if 'running' not in c.status:
print(c.logs())
# NGINX
nginx = client.containers.get('nginx')
nginx_cfg = nginx.exec_run("/usr/sbin/nginx -T")
assert nginx.status == 'running'
assert 'the configuration file /etc/nginx/nginx.conf syntax is ok' in nginx_cfg.output.decode()
assert 'HTTP/1.1" 500' not in nginx.logs()
# test restart
nginx.restart()
time.sleep(3)
assert nginx.status == 'running'
web = client.containers.get('oscar')
assert 'uWSGI http bound on :8080' in web.logs()
assert 'spawned uWSGI master process' in web.logs()
assert 'spawned uWSGI worker 1' in web.logs()
assert 'spawned uWSGI worker 2' in web.logs()
assert 'INFO success: oscar-00 entered RUNNING state' in web.logs()
assert web.status == 'running'
db = client.containers.get('oscardb')
assert db.status == 'running'
cnf = db.exec_run('psql -U oscar -h 127.0.0.1 -p 5432 -c "select 1"')
log = db.logs()
assert "database system is ready to accept connections" in log.decode()
response = requests.get("http://localhost")
assert response.status_code == 200
assert "<title>Oscar - Sandbox</title>" in response.text