@@ -30,22 +30,93 @@ def tearDownClass(cls):
3030 teardown (cls .username , cls .password )
3131
3232 def test_create (self ):
33+ # create a new flavor
3334 id_ = "test-flavor-{}" .format (uuid4 ().hex [:4 ])
3435 child = pexpect .spawn ("{} flavors:create {} --provider={} --params='{}'" .format (
3536 DEIS , id_ , 'ec2' ,
3637 '{"region":"ap-southeast-2","image":"ami-d5f66bef","zone":"any","size":"m1.medium"}'
3738 ))
3839 child .expect (id_ )
3940 child .expect (pexpect .EOF )
41+ # list the flavors and make sure it's in there
42+ child = pexpect .spawn ("{} flavors" .format (DEIS ))
43+ child .expect (pexpect .EOF )
44+ flavors = re .findall ('([\w|-]+): .*' , child .before )
45+ self .assertIn (id_ , flavors )
46+ # delete the new flavor
4047 child = pexpect .spawn ("{} flavors:delete {}" .format (DEIS , id_ ))
4148 child .expect (pexpect .EOF )
4249 self .assertNotIn ('Error' , child .before )
4350
44- # def test_update(self):
45- # pass
51+ def test_update (self ):
52+ # create a new flavor
53+ id_ = "test-flavor-{}" .format (uuid4 ().hex [:4 ])
54+ child = pexpect .spawn ("{} flavors:create {} --provider={} --params={}" .format (
55+ DEIS , id_ , 'mock' , '{}' ))
56+ child .expect (id_ )
57+ child .expect (pexpect .EOF )
58+ # update the provider
59+ child = pexpect .spawn ("{} flavors:update {} --provider={}" .format (DEIS , id_ , 'ec2' ))
60+ child .expect (pexpect .EOF )
61+ # update the params
62+ child = pexpect .spawn ("{} flavors:update {} {}" .format (
63+ DEIS , id_ , "'{\" key1\" : \" val1\" }'" ))
64+ child .expect (pexpect .EOF )
65+ # test the flavor contents
66+ child = pexpect .spawn ("{} flavors:info {}" .format (DEIS , id_ ))
67+ child .expect (pexpect .EOF )
68+ results = json .loads (child .before )
69+ self .assertEqual ('ec2' , results ['provider' ])
70+ self .assertIn ('key1' , results ['params' ])
71+ self .assertIn ('val1' , results ['params' ])
72+ # update the params and provider
73+ child = pexpect .spawn ("{} flavors:update {} {} --provider={}" .format (
74+ DEIS , id_ , "'{\" key2\" : \" val2\" }'" , 'mock' ))
75+ child .expect (pexpect .EOF )
76+ # test the flavor contents
77+ child = pexpect .spawn ("{} flavors:info {}" .format (DEIS , id_ ))
78+ child .expect (pexpect .EOF )
79+ results = json .loads (child .before )
80+ self .assertIn ('key1' , results ['params' ])
81+ self .assertIn ('val1' , results ['params' ])
82+ self .assertIn ('key2' , results ['params' ])
83+ self .assertIn ('val2' , results ['params' ])
84+ self .assertEqual ('mock' , results ['provider' ])
85+ # update the params to remove a value
86+ child = pexpect .spawn ("{} flavors:update {} {}" .format (
87+ DEIS , id_ , "'{\" key1\" : null}'" ))
88+ child .expect (pexpect .EOF )
89+ # test the flavor contents
90+ child = pexpect .spawn ("{} flavors:info {}" .format (DEIS , id_ ))
91+ child .expect (pexpect .EOF )
92+ results = json .loads (child .before )
93+ self .assertNotIn ('key1' , results ['params' ])
94+ self .assertNotIn ('val1' , results ['params' ])
95+ self .assertIn ('key2' , results ['params' ])
96+ self .assertIn ('val2' , results ['params' ])
97+ # delete the new flavor
98+ child = pexpect .spawn ("{} flavors:delete {}" .format (DEIS , id_ ))
99+ child .expect (pexpect .EOF )
100+ self .assertNotIn ('Error' , child .before )
46101
47- # def test_delete(self):
48- # pass
102+ def test_delete (self ):
103+ # create a new flavor
104+ id_ = "test-flavor-{}" .format (uuid4 ().hex [:4 ])
105+ child = pexpect .spawn ("{} flavors:create {} --provider={} --params='{}'" .format (
106+ DEIS , id_ , 'ec2' ,
107+ '{"region":"ap-southeast-2","image":"ami-d5f66bef","zone":"any","size":"m1.medium"}'
108+ ))
109+ child .expect (id_ )
110+ child .expect (pexpect .EOF )
111+ # delete the new flavor
112+ child = pexpect .spawn ("{} flavors:delete {}" .format (DEIS , id_ ))
113+ child .expect (pexpect .EOF )
114+ self .assertNotIn ('Error' , child .before )
115+ # list the flavors and make sure it's not in there
116+ child = pexpect .spawn ("{} flavors" .format (DEIS ))
117+ child .expect (pexpect .EOF )
118+ flavors = re .findall ('([\w|-]+): .*' , child .before )
119+ self .assertNotIn (id_ , flavors )
49120
50121 def test_list (self ):
51122 child = pexpect .spawn ("{} flavors" .format (DEIS ))
@@ -68,7 +139,6 @@ def test_info(self):
68139 # test that we received JSON results
69140 # TODO: There's some error here, but only when run as part of the
70141 # entire test suite?
71- print child .before
72142 results = json .loads (child .before )
73143 self .assertIn ('created' , results )
74144 self .assertIn ('updated' , results )
0 commit comments