Updated setup to allow adding collections.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / upload.py
1 '''
2    Copyright 2013 Emily O'Leary
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 '''
16 import util
17 from selenium import webdriver
18 from selenium.webdriver.common.by import By
19 from selenium.webdriver.support.ui import Select
20 from selenium.common.exceptions import NoSuchElementException
21 import unittest, time, re
22
23 class UploadFile():  
24     def upload(self, data):
25         '''Uploads a given file.
26
27             The data dictionary contains the following keys:
28             username, password, uri, title, description, tags, license
29
30         '''
31         self.driver = webdriver.Firefox()
32         self.driver.implicitly_wait(30)
33         self.base_url = "http://127.0.0.1:6543"
34         self.verificationErrors = []
35         self.accept_next_alert = True
36
37         driver = self.driver
38         tLogin = login.Login()
39         testharness = unittest.FunctionTestCase(self)
40
41         tLogin.log_in(self, data)
42         driver.get(self.base_url + "/")
43         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
44         testharness.assertTrue(util.is_element_present(self,By.LINK_TEXT, "Add media"))
45         driver.find_element_by_link_text("Add media").click()
46         # Warning: verifyTextPresent may require manual changes
47         try: testharness.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
48         except AssertionError as e: self.verificationErrors.append(str(e))
49         testharness.assertTrue(util.is_element_present(self,By.ID, "file"))
50         driver.find_element_by_id("file").clear()
51         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/" + data["uri"])
52         testharness.assertTrue(util.is_element_present(self,By.ID, "title"))
53         driver.find_element_by_id("title").clear()
54         driver.find_element_by_id("title").send_keys(data["title"])
55         driver.find_element_by_id("description").clear()
56         driver.find_element_by_id("description").send_keys(data["description"])
57         driver.find_element_by_id("tags").clear()
58         driver.find_element_by_id("tags").send_keys(data["tags"])
59         select = Select(driver.find_element_by_id("license"))
60         select.select_by_visible_text(data["license"])
61         testharness.assertTrue(util.is_element_present(self,By.ID, "license"))
62         testharness.assertTrue(util.is_element_present(self,By.ID, "tags"))
63         testharness.assertTrue(util.is_element_present(self,By.CSS_SELECTOR, "input.button_form"))
64         driver.find_element_by_css_selector("input.button_form").click()
65         testharness.assertTrue(util.is_element_present(self,By.LINK_TEXT, data["title"]))