Skip to content

Commit 97781ee

Browse files
committed
Added test_examples to hit each example-* project, WIP refs #214.
1 parent 43b0086 commit 97781ee

9 files changed

Lines changed: 163 additions & 129 deletions

File tree

client/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from .test_builds import * # noqa
88
from .test_config import * # noqa
99
from .test_containers import * # noqa
10+
from .test_examples import * # noqa
1011
from .test_flavors import * # noqa
1112
from .test_formations import * # noqa
12-
from .test_git import * # noqa
1313
from .test_keys import * # noqa
1414
from .test_layers import * # noqa
1515
from .test_misc import * # noqa

client/tests/test_apps.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
from .utils import DEIS
1717
from .utils import DEIS_TEST_FLAVOR
18+
from .utils import clone
19+
from .utils import purge
1820
from .utils import random_repo
19-
from .utils import setup
20-
from .utils import teardown
21+
from .utils import register
2122

2223

2324
class AppsTest(TestCase):
2425

2526
@classmethod
2627
def setUpClass(cls):
27-
repo_name, repo_url = random_repo()
28-
cls.username, cls.password, cls.repo_dir = setup(repo_url)
28+
cls.username, cls.password = register()
2929
# create a new formation
3030
cls.formation = "{}-test-formation-{}".format(
3131
cls.username, uuid4().hex[:4])
@@ -34,6 +34,9 @@ def setUpClass(cls):
3434
child.expect("created {}.*to scale a basic formation".format(
3535
cls.formation))
3636
child.expect(pexpect.EOF)
37+
repo_name, (repo_type, repo_url) = random_repo()
38+
# print repo_name, repo_type, repo_url
39+
clone(repo_url, repo_name)
3740

3841
@classmethod
3942
def tearDownClass(cls):
@@ -42,7 +45,7 @@ def tearDownClass(cls):
4245
DEIS, cls.formation, cls.formation))
4346
child.expect('done in ', timeout=5 * 60)
4447
child.expect(pexpect.EOF)
45-
teardown(cls.username, cls.password, cls.repo_dir)
48+
purge(cls.username, cls.password)
4649

4750
def test_create(self):
4851
# create the app

client/tests/test_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212

1313
from .utils import DEIS
1414
from .utils import DEIS_SERVER
15-
from .utils import setup
16-
from .utils import teardown
15+
from .utils import purge
16+
from .utils import register
1717

1818

1919
class AuthTest(TestCase):
2020

2121
@classmethod
2222
def setUpClass(cls):
23-
cls.username, cls.password, _ = setup()
23+
cls.username, cls.password = register()
2424

2525
@classmethod
2626
def tearDownClass(cls):
27-
teardown(cls.username, cls.password, None)
27+
purge(cls.username, cls.password)
2828

2929
def test_login(self):
3030
# log in the interactive way

client/tests/test_examples.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
Unit tests for the Deis example-[language] projects.
3+
4+
Run these tests with "python -m unittest client.tests.test_examples"
5+
or with "./manage.py test client.ExamplesTest".
6+
"""
7+
8+
from __future__ import unicode_literals
9+
from unittest import TestCase
10+
from uuid import uuid4
11+
12+
import pexpect
13+
from .utils import DEIS
14+
from .utils import DEIS_TEST_FLAVOR
15+
from .utils import EXAMPLES
16+
from .utils import clone
17+
from .utils import purge
18+
from .utils import register
19+
20+
21+
class ExamplesTest(TestCase):
22+
23+
@classmethod
24+
def setUpClass(cls):
25+
cls.username, cls.password = register()
26+
# create a new formation
27+
cls.formation = "{}-test-formation-{}".format(
28+
cls.username, uuid4().hex[:4])
29+
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
30+
DEIS, cls.formation, DEIS_TEST_FLAVOR))
31+
child.expect("created {}.*to scale a basic formation".format(
32+
cls.formation))
33+
child.expect(pexpect.EOF)
34+
# TODO: scale the formation runtime=1
35+
36+
@classmethod
37+
def tearDownClass(cls):
38+
# TODO: scale formation runtime=0
39+
# destroy the formation
40+
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
41+
DEIS, cls.formation, cls.formation))
42+
child.expect('done in ', timeout=5*60)
43+
child.expect(pexpect.EOF)
44+
purge(cls.username, cls.password)
45+
46+
def _test_example(self, repo_name):
47+
# `git clone` the example app repository
48+
repo_type, repo_url = EXAMPLES[repo_name]
49+
# print repo_name, repo_type, repo_url
50+
clone(repo_url, repo_name)
51+
# create an App
52+
child = pexpect.spawn("{} create --formation={}".format(
53+
DEIS, self.formation))
54+
child.expect('done, created (?P<name>[-_\w]+)')
55+
app = child.match.group('name')
56+
try:
57+
child.expect('Git remote deis added')
58+
child.expect(pexpect.EOF)
59+
child = pexpect.spawn('git push deis master')
60+
# check git output for repo_type, e.g. "Clojure app detected"
61+
child.expect("{} app detected".format(repo_type), timeout=2*60)
62+
child.expect(' -> master', timeout=10*60)
63+
child.expect(pexpect.EOF, timeout=2*60)
64+
# TODO: scale up runtime nodes in setUpClass, then
65+
# actually fetch the URL with curl and check the output
66+
# TODO: `deis config:set POWERED_BY="Automated Testing"`
67+
# then re-fetch the URL with curl and recheck the output
68+
finally:
69+
# destroy the app
70+
child = pexpect.spawn(
71+
"{} apps:destroy --app={} --confirm={}".format(DEIS, app, app),
72+
timeout=5*60)
73+
child.expect('Git remote deis removed')
74+
child.expect(pexpect.EOF)
75+
76+
def test_clojure_ring(self):
77+
self._test_example('example-clojure-ring')
78+
79+
def test_dart(self):
80+
self._test_example('example-dart')
81+
82+
def test_go(self):
83+
self._test_example('example-go')
84+
85+
def test_java_jetty(self):
86+
self._test_example('example-java-jetty')
87+
88+
def test_nodejs_express(self):
89+
self._test_example('example-nodejs-express')
90+
91+
def test_perl(self):
92+
self._test_example('example-perl')
93+
94+
def test_php(self):
95+
self._test_example('example-php')
96+
97+
def test_play(self):
98+
self._test_example('example-play')
99+
100+
def test_python_flask(self):
101+
self._test_example('example-python-flask')
102+
103+
def test_ruby_sinatra(self):
104+
self._test_example('example-ruby-sinatra')
105+
106+
def test_scala(self):
107+
self._test_example('example-scala')

client/tests/test_flavors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
from uuid import uuid4
1616

1717
from .utils import DEIS
18-
from .utils import setup
19-
from .utils import teardown
18+
from .utils import purge
19+
from .utils import register
2020

2121

2222
class FlavorsTest(TestCase):
2323

2424
@classmethod
2525
def setUpClass(cls):
26-
cls.username, cls.password, _ = setup()
26+
cls.username, cls.password = register()
2727

2828
@classmethod
2929
def tearDownClass(cls):
30-
teardown(cls.username, cls.password)
30+
purge(cls.username, cls.password)
3131

3232
def test_create(self):
3333
# create a new flavor

client/tests/test_formations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414

1515
from .utils import DEIS
1616
from .utils import DEIS_TEST_FLAVOR
17-
from .utils import setup
18-
from .utils import teardown
17+
from .utils import purge
18+
from .utils import register
1919

2020

2121
class FormationsTest(TestCase):
2222

2323
@classmethod
2424
def setUpClass(cls):
25-
cls.username, cls.password, cls.repo_dir = setup()
25+
cls.username, cls.password = register()
2626

2727
@classmethod
2828
def tearDownClass(cls):
29-
teardown(cls.username, cls.password)
29+
purge(cls.username, cls.password)
3030

3131
def test_list(self):
3232
# list formations and get their names

client/tests/test_git.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

client/tests/test_providers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
import pexpect
1212

1313
from .utils import DEIS
14-
from .utils import setup
15-
from .utils import teardown
14+
from .utils import purge
15+
from .utils import register
1616

1717

1818
class ProvidersTest(TestCase):
1919

2020
@classmethod
2121
def setUpClass(cls):
22-
cls.username, cls.password, _ = setup()
22+
cls.username, cls.password = register()
2323

2424
@classmethod
2525
def tearDownClass(cls):
26-
teardown(cls.username, cls.password, None)
26+
purge(cls.username, cls.password)
2727

2828
def test_seeded(self):
2929
"""Test that our autotest user has some providers auto-seeded."""

0 commit comments

Comments
 (0)