-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_formations.py
More file actions
86 lines (75 loc) · 3.38 KB
/
test_formations.py
File metadata and controls
86 lines (75 loc) · 3.38 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Unit tests for the Deis CLI formations commands.
Run these tests with "python -m unittest client.tests.test_formations"
or with "./manage.py test client.FormationsTest".
"""
from __future__ import unicode_literals
from unittest import TestCase
from uuid import uuid4
import re
import pexpect
from .utils import DEIS
from .utils import DEIS_TEST_FLAVOR
from .utils import purge
from .utils import register
class FormationsTest(TestCase):
@classmethod
def setUpClass(cls):
cls.username, cls.password = register()
@classmethod
def tearDownClass(cls):
purge(cls.username, cls.password)
def test_list(self):
# list formations and get their names
child = pexpect.spawn("{} formations".format(DEIS))
child.expect('=== Formations')
child.expect(pexpect.EOF)
formations_before = re.findall(r'([-_\w]+) {\w?}', child.before)
# create a new formation
formation = "{}-test-formation-{}".format(self.username, uuid4().hex[:4])
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
DEIS, formation, DEIS_TEST_FLAVOR))
child.expect("created {}.*to scale a basic formation".format(formation))
child.expect(pexpect.EOF)
# list formations and get their names
child = pexpect.spawn("{} formations".format(DEIS))
child.expect('=== Formations')
child.expect(pexpect.EOF)
formations = re.findall(r'([-_\w]+) {\w?}', child.before)
# test that the set of names contains the previous set
self.assertLess(set(formations_before), set(formations))
# delete the formation
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
DEIS, formation, formation))
child.expect('done in ', timeout=5*60)
child.expect(pexpect.EOF)
# list formations and get their names
child = pexpect.spawn("{} formations:list".format(DEIS))
child.expect('=== Formations')
child.expect(pexpect.EOF)
formations = re.findall(r'([-_\w]+) {\w?}', child.before)
# test that the set of names is equal to the original set
self.assertEqual(set(formations_before), set(formations))
def test_create(self):
formation = "{}-test-formation-{}".format(self.username, uuid4().hex[:4])
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
DEIS, formation, DEIS_TEST_FLAVOR))
child.expect("created {}.*to scale a basic formation".format(formation))
child.expect(pexpect.EOF)
# destroy formation the one-liner way
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
DEIS, formation, formation))
child.expect('done in ', timeout=5*60)
child.expect(pexpect.EOF)
def test_destroy(self):
formation = "{}-test-formation-{}".format(self.username, uuid4().hex[:4])
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
DEIS, formation, DEIS_TEST_FLAVOR))
child.expect("created {}.*to scale a basic formation".format(formation))
child.expect(pexpect.EOF)
# destroy formation the interactive way
child = pexpect.spawn("{} formations:destroy {}".format(DEIS, formation))
child.expect('> ')
child.sendline(formation)
child.expect('done in ', timeout=5*60)
child.expect(pexpect.EOF)