Skip to content

Commit 88bd938

Browse files
committed
Updated tests
1 parent ef59b7c commit 88bd938

3 files changed

Lines changed: 156 additions & 34 deletions

File tree

client/tests/test_apps.py

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from __future__ import unicode_literals
99
from unittest import TestCase
1010
from uuid import uuid4
11+
import json
12+
import re
1113

1214
import pexpect
1315

@@ -42,5 +44,115 @@ def tearDownClass(cls):
4244
child.expect(pexpect.EOF)
4345
teardown(cls.username, cls.password, cls.repo_dir)
4446

45-
def test_app_create(self):
47+
def test_create(self):
48+
# create the app
4649
self.assertIsNotNone(self.formation)
50+
child = pexpect.spawn("{} create --formation={}".format(
51+
DEIS, self.formation))
52+
child.expect('done, created (?P<name>[-_\w]+)')
53+
app = child.match.group('name')
54+
child.expect('Git remote deis added')
55+
child.expect(pexpect.EOF)
56+
# check that it's in the list of apps
57+
child = pexpect.spawn("{} apps".format(DEIS))
58+
child.expect('=== Apps')
59+
child.expect(pexpect.EOF)
60+
apps = re.findall(r'([-_\w]+) {\w?}', child.before)
61+
self.assertIn(app, apps)
62+
# destroy the app
63+
child = pexpect.spawn("{} apps:destroy --confirm={}".format(DEIS, app))
64+
child.expect('Git remote deis removed')
65+
child.expect(pexpect.EOF)
66+
67+
def test_destroy(self):
68+
# create the app
69+
self.assertIsNotNone(self.formation)
70+
child = pexpect.spawn("{} apps:create --formation={}".format(
71+
DEIS, self.formation))
72+
child.expect('done, created ([-_\w]+)')
73+
app = child.match.group(1)
74+
child.expect(pexpect.EOF)
75+
# check that it's in the list of apps
76+
child = pexpect.spawn("{} apps".format(DEIS))
77+
child.expect('=== Apps')
78+
child.expect(pexpect.EOF)
79+
apps = re.findall(r'([-_\w]+) {\w?}', child.before)
80+
self.assertIn(app, apps)
81+
# destroy the app
82+
child = pexpect.spawn("{} destroy --confirm={}".format(DEIS, app))
83+
child.expect("Destroying {}".format(app))
84+
child.expect('done in \d+s')
85+
child.expect('Git remote deis removed')
86+
child.expect(pexpect.EOF)
87+
88+
def test_list(self):
89+
# list apps and get their names
90+
child = pexpect.spawn("{} apps".format(DEIS))
91+
child.expect('=== Apps')
92+
child.expect(pexpect.EOF)
93+
apps_before = re.findall(r'([-_\w]+) {\w?}', child.before)
94+
# create a new app
95+
self.assertIsNotNone(self.formation)
96+
child = pexpect.spawn("{} apps:create --formation={}".format(
97+
DEIS, self.formation))
98+
child.expect('done, created ([-_\w]+)')
99+
app = child.match.group(1)
100+
child.expect(pexpect.EOF)
101+
# list apps and get their names
102+
child = pexpect.spawn("{} apps".format(DEIS))
103+
child.expect('=== Apps')
104+
child.expect(pexpect.EOF)
105+
apps = re.findall(r'([-_\w]+) {\w?}', child.before)
106+
# test that the set of names contains the previous set
107+
self.assertLess(set(apps_before), set(apps))
108+
# delete the app
109+
child = pexpect.spawn("{} apps:destroy --app={} --confirm={}".format(
110+
DEIS, app, app))
111+
child.expect('done in ', timeout=5*60)
112+
child.expect(pexpect.EOF)
113+
# list apps and get their names
114+
child = pexpect.spawn("{} apps:list".format(DEIS))
115+
child.expect('=== Apps')
116+
child.expect(pexpect.EOF)
117+
apps = re.findall(r'([-_\w]+) {\w?}', child.before)
118+
# test that the set of names is equal to the original set
119+
self.assertEqual(set(apps_before), set(apps))
120+
121+
def test_info(self):
122+
# create a new app
123+
self.assertIsNotNone(self.formation)
124+
child = pexpect.spawn("{} create --formation={}".format(
125+
DEIS, self.formation))
126+
child.expect('done, created (?P<name>[-_\w]+)')
127+
app = child.match.group('name')
128+
child.expect('Git remote deis added')
129+
child.expect(pexpect.EOF)
130+
# get app info
131+
child = pexpect.spawn("{} info".format(DEIS))
132+
child.expect("=== {} Application".format(app))
133+
child.expect("=== {} Containers".format(app))
134+
response = json.loads(child.before)
135+
child.expect(pexpect.EOF)
136+
self.assertEqual(response['id'], app)
137+
self.assertEqual(response['formation'], self.formation)
138+
self.assertEqual(response['owner'], self.username)
139+
self.assertIn('uuid', response)
140+
self.assertIn('created', response)
141+
self.assertIn('containers', response)
142+
# delete the app
143+
child = pexpect.spawn("{} apps:destroy --app={} --confirm={}".format(
144+
DEIS, app, app))
145+
child.expect('done in ', timeout=5*60)
146+
child.expect(pexpect.EOF)
147+
148+
# def test_calculate(self):
149+
# pass
150+
151+
# def test_open(self):
152+
# pass
153+
154+
# def test_logs(self):
155+
# pass
156+
157+
# def test_run(self):
158+
# pass

client/tests/test_git.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
from __future__ import unicode_literals
99
from unittest import TestCase
10+
from uuid import uuid4
1011

11-
# import pexpect
12+
import pexpect
1213

13-
# from .utils import DEIS
14+
from .utils import DEIS
15+
from .utils import DEIS_TEST_FLAVOR
1416
from .utils import random_repo
1517
from .utils import setup
1618
from .utils import teardown
@@ -22,30 +24,38 @@ class GitTest(TestCase):
2224
def setUpClass(cls):
2325
cls.repo_name, repo_url = random_repo()
2426
cls.username, cls.password, cls.repo_dir = setup(repo_url)
27+
# create a new formation
28+
cls.formation = "{}-test-formation-{}".format(
29+
cls.username, uuid4().hex[:4])
30+
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
31+
DEIS, cls.formation, DEIS_TEST_FLAVOR))
32+
child.expect("created {}.*to scale a basic formation".format(
33+
cls.formation))
34+
child.expect(pexpect.EOF)
35+
# create an app
36+
child = pexpect.spawn("{} create --formation={}".format(
37+
DEIS, cls.formation))
38+
child.expect('done, created (?P<name>[-_\w]+)')
39+
cls.app = child.match.group('name')
40+
child.expect(pexpect.EOF)
2541

2642
@classmethod
2743
def tearDownClass(cls):
44+
# destroy the formation
45+
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
46+
DEIS, cls.formation, cls.formation))
47+
child.expect('done in ', timeout=5*60)
48+
child.expect(pexpect.EOF)
2849
teardown(cls.username, cls.password, cls.repo_dir)
2950

30-
# def test_push(self):
31-
# pushes = {
32-
# 'clojure': 'Clojure app detected.*\[new branch\] master -> master',
33-
# 'django': 'Python app detected.*\[new branch\] master -> master',
34-
# 'flask': 'Python app detected.*\[new branch\] master -> master',
35-
# 'go': 'Go app detected.*\[new branch\] master -> master',
36-
# 'java': 'Java app detected.*\[new branch\] master -> master',
37-
# 'nodejs': 'Node.js app detected.*\[new branch\] master -> master',
38-
# 'rails': 'Ruby/Rails app detected.*\[new branch\] master -> master',
39-
# 'rails-todo': 'Ruby/Rails app detected.*\[new branch\] master -> master',
40-
# 'sinatra': 'Ruby/Rack app detected.*\[new branch\] master -> master',
41-
# }
42-
# child = pexpect.spawn("python {} create --flavor=ec2-us-west-2".format(DEIS))
43-
# child.expect('created (?P<name>[a-z]{6}-[a-z]{8}).*to scale a basic formation')
44-
# formation = child.match.group('name')
45-
# child = pexpect.spawn('git push deis master')
46-
# child.expect(pushes[self.repo_name], timeout=180)
47-
# child.expect(pexpect.EOF)
48-
# # destroy formation the one-liner way
49-
# child = pexpect.spawn("{} destroy --confirm={}".format(DEIS, formation))
50-
# child.expect('Git remote deis removed')
51-
# child.expect(pexpect.EOF)
51+
def test_push(self):
52+
child = pexpect.spawn('git push deis master')
53+
# check git output for "Clojure app detected", for example
54+
print self.repo_name
55+
child.expect('----->')
56+
print child.before
57+
# child.expect("{} app detected".format(self.repo_name))
58+
# print child.before
59+
child.expect(' -> master', timeout=10*60)
60+
child.expect(pexpect.EOF, timeout=2*60)
61+
print child.before

client/tests/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
'Environment variable DEIS_SERVER must point to a Deis controller URL.')
2323
DEIS_TEST_FLAVOR = os.environ.get('DEIS_TEST_FLAVOR', 'ec2-us-west-2')
2424
REPOSITORIES = {
25-
'clojure': 'https://github.com/opdemand/example-clojure-ring.git',
26-
'django': 'https://github.com/opdemand/example-python-django.git',
27-
'flask': 'https://github.com/opdemand/example-python-flask.git',
28-
'java': 'https://github.com/opdemand/example-java-jetty.git',
29-
'go': 'https://github.com/opdemand/example-go.git',
30-
'nodejs': 'https://github.com/opdemand/example-nodejs-express.git',
31-
'rails': 'https://github.com/opdemand/example-rails-helloworld.git',
32-
'rails-todo': 'https://github.com/opdemand/example-rails-todo.git',
33-
'sinatra': 'https://github.com/opdemand/example-ruby-sinatra.git',
25+
'Clojure': 'https://github.com/opdemand/example-clojure-ring.git',
26+
# 'Python': 'https://github.com/opdemand/example-python-django.git',
27+
'Python': 'https://github.com/opdemand/example-python-flask.git',
28+
'Java': 'https://github.com/opdemand/example-java-jetty.git',
29+
'Go': 'https://github.com/opdemand/example-go.git',
30+
'Node.js': 'https://github.com/opdemand/example-nodejs-express.git',
31+
# 'Ruby/Rails': 'https://github.com/opdemand/example-rails-helloworld.git',
32+
'Ruby/Rails': 'https://github.com/opdemand/example-rails-todo.git',
33+
'Ruby/Rack': 'https://github.com/opdemand/example-ruby-sinatra.git',
3434
}
3535

3636

0 commit comments

Comments
 (0)