-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_flavors.py
More file actions
78 lines (65 loc) · 2.46 KB
/
test_flavors.py
File metadata and controls
78 lines (65 loc) · 2.46 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
"""
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 setup
from .utils import teardown
class FlavorsTest(TestCase):
@classmethod
def setUpClass(cls):
cls.username, cls.password, _ = setup()
@classmethod
def tearDownClass(cls):
teardown(cls.username, cls.password)
def test_create(self):
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)
child = pexpect.spawn("{} flavors:delete {}".format(DEIS, id_))
child.expect(pexpect.EOF)
self.assertNotIn('Error', child.before)
# def test_update(self):
# pass
# def test_delete(self):
# pass
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?
print child.before
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)