cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
images_test.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 # -*- coding: utf-8 -*-
21 ##
22 # @package src.wi.tests.images_test
23 #
24 # @author Piotr Wójcik
25 # @author Krzysztof Danielowski
26 # @date 24.11.2012
27 #
28 
29 from wi.tests import WiTestCase
30 import groups_test
31 import vm_test
32 import unittest
33 import random
34 
35 
36 class ImagesTests(WiTestCase, unittest.TestCase):
37 
38  @staticmethod
39  def _test_upload_image_private(self):
40  driver = self.driver
41  self.base_url = self.TEST_SERVER
42 
43  self.login_testuser(self.TEST_USER)
44 
45  driver.get(self.base_url + "/images/images_private/")
46 
47  self.wait_for_text("//table[@id='item-list']/tfoot/tr/td/ul/li/a", ["Upload image"])
48 
49  driver.find_element_by_link_text("Upload image").click()
50 
51  self.wait_for_text("//div[@id='dialog-div']/p", ["Please specify image parameters:"])
52 
53  name = "witest_image" + str(random.randint(1, 100000))
54  driver.find_element_by_id("id_name").clear()
55  driver.find_element_by_id("id_name").send_keys(name)
56  driver.find_element_by_id("id_description").clear()
57  driver.find_element_by_id("id_description").send_keys(self.iso)
58  driver.find_element_by_id("id_path").clear()
59  driver.find_element_by_id("id_path").send_keys(self.iso)
60  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
61 
62  self.wait_for_message(["Image upload started."])
63 
64  driver.find_element_by_link_text("Logout").click()
65 
66  return name
67 
68  def _test_edit_image_private(self, name):
69  driver = self.driver
70  self.base_url = self.TEST_SERVER
71 
72  self.login_testuser(self.TEST_USER)
73 
74  driver.get(self.base_url + "/images/images_private/")
75 
76  self.wait_for_text("//table[@id='item-list']/tbody", [name])
77 
78  self.menu_click("Name", name, "Edit", {"dict": {"Size": "B"}, "path": "//table[@id='item-list']/tbody"})
79 
80  self.wait_for_text("//div[@id='dialog-div']/p", ["Edit image data"])
81 
82  newname = "new_witest_image" + str(random.randint(1, 100000))
83  driver.find_element_by_id("id_name").clear()
84  driver.find_element_by_id("id_name").send_keys(newname)
85  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
86 
87  self.wait_for_message(["You have successfully edited this image."])
88 
89  driver.find_element_by_link_text("Logout").click()
90 
91  return newname
92 
93  @staticmethod
94  def _test_remove_image_private(self, name):
95  driver = self.driver
96  self.base_url = self.TEST_SERVER
97 
98  self.login_testuser(self.TEST_USER)
99 
100  driver.get(self.base_url + "/images/images_private/")
101 
102  self.wait_for_text("//table[@id='item-list']/tbody", [name])
103 
104  self.menu_click("Name", name, "Delete")
105 
106  self.wait_for_text("//div[@id='dialog-div']/p", ["Do you really want to delete image"])
107 
108  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
109 
110  self.wait_for_message(["You have successfully deleted image"])
111 
112  driver.find_element_by_link_text("Logout").click()
113 
114  def _test_create_vm_from_image(self, name):
115  driver = self.driver
116  self.base_url = self.TEST_SERVER
117 
118  self.login_testuser(self.TEST_USER)
119 
120  driver.get(self.base_url + "/images/images_private/")
121 
122  self.wait_for_text("//table[@id='item-list']/tbody", [name])
123 
124  self.menu_click("Name", name, "Create virtual machine", {"dict": {"Size": "B"}, "path": "//table[@id='item-list']/tbody"})
125 
126  self.wait_for_text("//div[@id='item-list']/div[2]/table/tbody", ["small"])
127 
128  self.cell_click("Name", "small", None, element="a",
129  path_head_tds="//div[@id='item-list']/div[1]/table/tbody/tr/td",
130  path_body_trs="//div[@id='item-list']/div[2]/table/tbody/tr")
131 
132  self.wait_for_text("//form[@id='wizard-form']/div[2]/fieldset/div/span/label", ["Assign IP address"])
133 
134  driver.find_element_by_xpath("//div[@id='submit-div']/input").click()
135 
136  self.wait_for_text("//form[@id='wizard-form']/div[2]/fieldset/div/span/label", ["Name"])
137 
138  name = "witest_vm" + str(random.randint(1, 100000))
139  driver.find_element_by_id("id_3-name").clear()
140  driver.find_element_by_id("id_3-name").send_keys(name)
141 
142  driver.find_element_by_css_selector("input.big_button").click()
143 
144  self.wait_for_message(["Virtual machine is being created."])
145 
146  driver.find_element_by_link_text("Logout").click()
147 
148  return name
149 
150  def _test_group_image_private(self, name, group_name):
151  driver = self.driver
152  self.base_url = self.TEST_SERVER
153 
154  self.login_testuser(self.TEST_USER)
155 
156  driver.get(self.base_url + "/images/images_private/")
157 
158  self.wait_for_text("//table[@id='item-list']/tbody", [name])
159 
160  self.menu_click("Name", name, "Assign to group", {"dict": {"Size": "B"}, "path": "//table[@id='item-list']/tbody"})
161 
162  self.wait_for_text("//div[@id='dialog-div']/p", ["Enter a name of group for image"])
163 
164  driver.find_element_by_xpath("//div[@id='dialog-div']/form/div/fieldset/div/span[2]/a/span").click()
165  driver.find_element_by_xpath("//a[contains(text(),'" + group_name + "')]").click()
166 
167  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
168 
169  self.wait_for_message(["You have successfully assigned image "])
170 
171  driver.find_element_by_link_text("Logout").click()
172 
173  def _test_ungroup_image_private(self, name):
174  driver = self.driver
175  self.base_url = self.TEST_SERVER
176 
177  self.login_testuser(self.TEST_USER)
178 
179  driver.get(self.base_url + "/images/images_private/")
180 
181  self.wait_for_text("//table[@id='item-list']/tbody", [name])
182 
183  self.menu_click("Name", name, "Move to my images")
184 
185  self.wait_for_text("//div[@id='dialog-div']/p", ["Do you want to make image"])
186 
187  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
188 
189  self.wait_for_message(["You have successfully revoked group's assigment."])
190 
191  driver.find_element_by_link_text("Logout").click()
192 
193  def test_1_simple(self):
194  name = self._test_upload_image_private(self)
195  newname = self._test_edit_image_private(name)
196  self._test_remove_image_private(self, newname)
197 
198  def test_2_create_vm(self):
199  name = self._test_upload_image_private(self)
200  vmname = self._test_create_vm_from_image(name)
201  vm_test.VMTests._test_destroy_vm(self, vmname)
202  self._test_remove_image_private(self, name)
203 
204  def test_3_group(self):
205  name = self._test_upload_image_private(self)
206  group_name = groups_test.GroupsTests._test_create_group(self)
207  self._test_group_image_private(name, group_name)
208  self._test_ungroup_image_private(name)
209  groups_test.GroupsTests._test_remove_group(self, group_name, who=self.TEST_USER)
210  self._test_remove_image_private(self, name)
211