cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
farm_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.farm_test
23 #
24 # @author Piotr W√≥jcik
25 # @author Krzysztof Danielowski
26 # @date 24.05.2013
27 #
28 
29 from wi.tests import WiTestCase
30 import random
31 import resources_test
32 import unittest
33 
34 
35 class FarmTests(WiTestCase, unittest.TestCase):
36  def _test_create_farm(self):
37  driver = self.driver
38  self.base_url = self.TEST_SERVER
39 
40  self.login_testuser(self.TEST_USER)
41 
42  driver.get(self.base_url + "/farm/create_farm/")
43 
44  self.wait_for_text("//div[@id='item-list']/div[2]/table/tbody", ["witest_complete_ctx"])
45 
46  self.cell_click("Name", "witest_complete_ctx", None, element="a",
47  path_head_tds="//div[@id='item-list']/div[1]/table/tbody/tr/td",
48  path_body_trs="//div[@id='item-list']/div[2]/table/tbody/tr")
49 
50  self.wait_for_text("//form[@id='wizard-form']/div[2]/fieldset/div/span/label", ["Head template"])
51 
52  driver.find_element_by_xpath("//form[@id='wizard-form']/div[2]/fieldset/div/span[2]/a/span").click()
53  driver.find_element_by_xpath("//a[contains(text(),'" + "small" + "')]").click()
54  driver.find_element_by_xpath("//form[@id='wizard-form']/div[2]/fieldset/div[2]/span[2]/a/span").click()
55  driver.find_elements_by_xpath("//a[contains(text(),'" + "small" + "')]")[1].click()
56 
57  driver.find_element_by_xpath("//div[@id='submit-div']/input").click()
58 
59  self.wait_for_text("//form[@id='wizard-form']/div[2]/fieldset/div/span/label", ["Assign IP address"])
60 
61  driver.find_element_by_xpath("//div[@id='submit-div']/input").click()
62 
63  self.wait_for_text("//form[@id='wizard-form']/div[2]/fieldset/div/span/label", ["Name"])
64 
65  name = "witest_farm" + str(random.randint(1, 100000))
66  driver.find_element_by_id("id_3-name").clear()
67  driver.find_element_by_id("id_3-name").send_keys(name)
68 
69  driver.find_element_by_css_selector("input.big_button").click()
70 
71  self.wait_for_message(["Farm is being created."])
72 
73  driver.find_element_by_link_text("Logout").click()
74 
75  return name
76 
77  def _test_destroy_farm(self, name):
78  driver = self.driver
79  self.base_url = self.TEST_SERVER
80 
81  self.login_testuser(self.TEST_USER)
82 
83  driver.get(self.base_url + "/farm/show_farm/")
84 
85  self.wait_for_text("//div[@id='item-list']", [name])
86 
87  number = 0
88 
89  els = driver.find_elements_by_xpath("//div[@id='item-list']/div/h3")
90  for i in range(len(els)):
91  if name in els[i].text:
92  number = i + 1
93  break
94  if number == 0:
95  self.fail("time out while searching for \"" + name + "\"")
96 
97  self.wait_for_text("//div[@id='item-list']/div[" + str(number) + "]", ["Running"], max_time=100, sleep_time=5)
98 
99  driver.find_element_by_xpath("//div[@id='item-list']/div[" + str(number) + "]/table/tbody/tr/td/div/ul/li/a").click()
100 
101  self.wait_for_text("//div[@id='dialog-div']/p", ["Do you really want to destroy farm"])
102 
103  driver.find_element_by_css_selector("button.ok-button.mid_button").click()
104 
105  self.wait_for_message(["You have successfully destroyed farm"])
106 
107  driver.find_element_by_link_text("Logout").click()
108 
109  def test_1_simple(self):
110  name = self._test_create_farm()
111  self._test_destroy_farm(name)
112