-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_flavors.py
148 lines (135 loc) · 5.76 KB
/
test_flavors.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
Unit tests for the Deis CLI flavors commands.
Run these tests with "python -m unittest client.tests.test_flavors"
or with "./manage.py test client.FlavorsTest".
"""
from __future__ import unicode_literals
from unittest import TestCase
import re
import json
import pexpect
import random
from uuid import uuid4
from .utils import DEIS
from .utils import purge
from .utils import register
class FlavorsTest(TestCase):
@classmethod
def setUpClass(cls):
cls.username, cls.password = register()
@classmethod
def tearDownClass(cls):
purge(cls.username, cls.password)
def test_create(self):
# create a new flavor
id_ = "test-flavor-{}".format(uuid4().hex[:4])
child = pexpect.spawn("{} flavors:create {} --provider={} --params='{}'".format(
DEIS, id_, 'ec2',
'{"region":"ap-southeast-2","image":"ami-d5f66bef","zone":"any","size":"m1.medium"}'
))
child.expect(id_)
child.expect(pexpect.EOF)
# list the flavors and make sure it's in there
child = pexpect.spawn("{} flavors".format(DEIS))
child.expect(pexpect.EOF)
flavors = re.findall('([\w|-]+): .*', child.before)
self.assertIn(id_, flavors)
# delete the new flavor
child = pexpect.spawn("{} flavors:delete {}".format(DEIS, id_))
child.expect(pexpect.EOF)
self.assertNotIn('Error', child.before)
def test_update(self):
# create a new flavor
id_ = "test-flavor-{}".format(uuid4().hex[:4])
child = pexpect.spawn("{} flavors:create {} --provider={} --params={}".format(
DEIS, id_, 'mock', '{}'))
child.expect(id_)
child.expect(pexpect.EOF)
# update the provider
child = pexpect.spawn("{} flavors:update {} --provider={}".format(DEIS, id_, 'ec2'))
child.expect(pexpect.EOF)
# update the params
child = pexpect.spawn("{} flavors:update {} {}".format(
DEIS, id_, "'{\"key1\": \"val1\"}'"))
child.expect(pexpect.EOF)
# test the flavor contents
child = pexpect.spawn("{} flavors:info {}".format(DEIS, id_))
child.expect(pexpect.EOF)
results = json.loads(child.before)
self.assertEqual('ec2', results['provider'])
self.assertIn('key1', results['params'])
self.assertIn('val1', results['params'])
# update the params and provider
child = pexpect.spawn("{} flavors:update {} {} --provider={}".format(
DEIS, id_, "'{\"key2\": \"val2\"}'", 'mock'))
child.expect(pexpect.EOF)
# test the flavor contents
child = pexpect.spawn("{} flavors:info {}".format(DEIS, id_))
child.expect(pexpect.EOF)
results = json.loads(child.before)
self.assertIn('key1', results['params'])
self.assertIn('val1', results['params'])
self.assertIn('key2', results['params'])
self.assertIn('val2', results['params'])
self.assertEqual('mock', results['provider'])
# update the params to remove a value
child = pexpect.spawn("{} flavors:update {} {}".format(
DEIS, id_, "'{\"key1\": null}'"))
child.expect(pexpect.EOF)
# test the flavor contents
child = pexpect.spawn("{} flavors:info {}".format(DEIS, id_))
child.expect(pexpect.EOF)
results = json.loads(child.before)
self.assertNotIn('key1', results['params'])
self.assertNotIn('val1', results['params'])
self.assertIn('key2', results['params'])
self.assertIn('val2', results['params'])
# delete the new flavor
child = pexpect.spawn("{} flavors:delete {}".format(DEIS, id_))
child.expect(pexpect.EOF)
self.assertNotIn('Error', child.before)
def test_delete(self):
# create a new flavor
id_ = "test-flavor-{}".format(uuid4().hex[:4])
child = pexpect.spawn("{} flavors:create {} --provider={} --params='{}'".format(
DEIS, id_, 'ec2',
'{"region":"ap-southeast-2","image":"ami-d5f66bef","zone":"any","size":"m1.medium"}'
))
child.expect(id_)
child.expect(pexpect.EOF)
# delete the new flavor
child = pexpect.spawn("{} flavors:delete {}".format(DEIS, id_))
child.expect(pexpect.EOF)
self.assertNotIn('Error', child.before)
# list the flavors and make sure it's not in there
child = pexpect.spawn("{} flavors".format(DEIS))
child.expect(pexpect.EOF)
flavors = re.findall('([\w|-]+): .*', child.before)
self.assertNotIn(id_, flavors)
def test_list(self):
child = pexpect.spawn("{} flavors".format(DEIS))
child.expect(pexpect.EOF)
before = child.before
flavors = re.findall('([\w|-]+): .*', before)
# test that there were at least 3 flavors seeded
self.assertGreaterEqual(len(flavors), 3)
# test that "flavors" and "flavors:list" are equivalent
child = pexpect.spawn("{} flavors:list".format(DEIS))
child.expect(pexpect.EOF)
self.assertEqual(before, child.before)
def test_info(self):
child = pexpect.spawn("{} flavors".format(DEIS))
child.expect(pexpect.EOF)
flavor = random.choice(re.findall('([\w|-]+): .*', child.before))
child = pexpect.spawn("{} flavors:info {}".format(DEIS, flavor))
child.expect(pexpect.EOF)
# test that we received JSON results
# TODO: There's some error here, but only when run as part of the
# entire test suite?
results = json.loads(child.before)
self.assertIn('created', results)
self.assertIn('updated', results)
self.assertIn('provider', results)
self.assertIn('id', results)
self.assertIn('params', results)
self.assertEqual(results['owner'], self.username)