Added utf-8 encoding to files.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / collection.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 '''
4    Copyright 2013 Emily O'Leary
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 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
24
25 class Collection():
26     def create_by_adding(self, data):
27         '''Creates a collection by adding a media item to it.
28
29             The data dictionary contains the following keys:
30             username, password, mediatitle, collectiontitle, description, note
31
32         '''
33         self.driver = webdriver.Firefox()
34         self.driver.implicitly_wait(30)
35         self.base_url = "http://127.0.0.1:6543"
36         self.verificationErrors = []
37         self.accept_next_alert = True
38
39         driver = self.driver
40         tLogin = login.Login()
41         tLogin.log_in(self, data)
42         testharness = unittest.FunctionTestCase(self)
43
44         driver.get(self.base_url + "/")
45
46         testharness.assertTrue(self.is_element_present(By.LINK_TEXT, data["mediatitle"]))
47         driver.find_element_by_link_text("Gavroche Test").click()
48         testharness.assertTrue(self.is_element_present(By.LINK_TEXT, "Add to a collection"))
49         driver.find_element_by_link_text("Add to a collection").click()
50         testharness.assertTrue(self.is_element_present(By.ID, "button_addcollection"))
51         driver.find_element_by_id("button_addcollection").click()
52         try: testharness.assertTrue(self.is_element_present(By.ID, "collection_title"))
53         except AssertionError as e: self.verificationErrors.append(str(e))
54         driver.find_element_by_id("collection_title").send_keys(data["collectiontitle"])
55         try: testharness.assertTrue(self.is_element_present(By.ID, "collection_description"))
56         except AssertionError as e: self.verificationErrors.append(str(e))
57         driver.find_element_by_id("collection_description").clear()
58         driver.find_element_by_id("collection_description").send_keys(data["description"])
59         try: testharness.assertTrue(self.is_element_present(By.ID, "note"))
60         except AssertionError as e: self.verificationErrors.append(str(e))
61         driver.find_element_by_id("note").clear()
62         driver.find_element_by_id("note").send_keys(data["note"])
63         testharness.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
64         driver.find_element_by_css_selector("input.button_form").click()
65         try: testharness.assertEqual("\""+ data["mediatitle"] +"\" added to collection \"" + data["collectiontitle"] + "\"", driver.find_element_by_css_selector("li.message_success").text)
66         except AssertionError as e: self.verificationErrors.append(str(e))