2 # -*- coding: utf-8 -*-
4 Copyright 2013 Emily O'Leary
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
18 from util import login
19 from selenium import webdriver
20 from selenium.webdriver.common.by import By
21 from selenium.webdriver.support.ui import Select
22 from selenium.common.exceptions import NoSuchElementException
23 import unittest, time, re
25 class ChangeAccountSettings(unittest.TestCase):
27 self.driver = webdriver.Firefox()
28 self.driver.implicitly_wait(30)
29 self.base_url = "http://127.0.0.1:6543"
30 self.verificationErrors = []
31 self.accept_next_alert = True
33 def test_change_account_settings(self):
35 driver.get(self.base_url + "/")
36 tLogin = login.Login()
37 data = {"username" : "editorgoblin", "password" : "Fixyourgrammarplease"}
38 tLogin.log_in(self, data)
39 driver.find_element_by_link_text(u"▼").click()
40 self.assertTrue(self.is_element_present(By.LINK_TEXT, "Change account settings"))
41 driver.find_element_by_link_text("Change account settings").click()
42 try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.boolean > label"))
43 except AssertionError as e: self.verificationErrors.append(str(e))
44 self.assertTrue(self.is_element_present(By.ID, "license_preference"))
45 select = Select(driver.find_element_by_id("license"))
46 select.select_by_visible_text("Public Domain")
47 driver.find_element_by_id("wants_comment_notification").click()
48 driver.find_element_by_css_selector("input.button_form").click()
49 try: self.assertEqual("Account settings saved", driver.find_element_by_css_selector("li.message_success").text)
50 except AssertionError as e: self.verificationErrors.append(str(e))
51 driver.find_element_by_link_text(u"▼").click()
52 self.assertTrue(self.is_element_present(By.LINK_TEXT, "Change account settings"))
53 driver.find_element_by_link_text("Change account settings").click()
54 try: self.assertEqual("off", driver.find_element_by_id("wants_comment_notification").get_attribute("value"))
55 except AssertionError as e: self.verificationErrors.append(str(e))
57 def is_element_present(self, how, what):
58 try: self.driver.find_element(by=how, value=what)
59 except NoSuchElementException, e: return False
62 def is_alert_present(self):
63 try: self.driver.switch_to_alert()
64 except NoAlertPresentException, e: return False
67 def close_alert_and_get_its_text(self):
69 alert = self.driver.switch_to_alert()
70 alert_text = alert.text
71 if self.accept_next_alert:
76 finally: self.accept_next_alert = True
80 self.assertEqual([], self.verificationErrors)
82 if __name__ == "__main__":