Added comments to upload function in the UploadFile class.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / upload.py
1 #!/usr/bin/env python
2
3 # GNU MediaGoblin Selenium Automation
4 # Copyright (C) 2013 Emily O'Leary
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # This file is a modified version of the Log In test case for re-use throughout
20 # test cases. See ContributingTests.txt
21 import util
22 from selenium import webdriver
23 from selenium.webdriver.common.by import By
24 from selenium.webdriver.support.ui import Select
25 from selenium.common.exceptions import NoSuchElementException
26 import unittest, time, re
27
28 class UploadFile():  
29     def upload(self,external,data):
30         '''Uploads a given file.
31
32             The data dictionary contains the following keys:
33             username, password, file, title, description, tags, license
34
35         '''
36         driver = self.driver
37         tLogin = login.Login()
38
39         tLogin.log_in(self, data)
40         driver.get(self.base_url + "/")
41         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
42         external.assertTrue(util.is_element_present(self,By.LINK_TEXT, "Add media"))
43         driver.find_element_by_link_text("Add media").click()
44         # Warning: verifyTextPresent may require manual changes
45         try: external.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
46         except AssertionError as e: self.verificationErrors.append(str(e))
47         external.assertTrue(util.is_element_present(self,By.ID, "file"))
48         driver.find_element_by_id("file").clear()
49         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/" + data["file"])
50         external.assertTrue(util.is_element_present(self,By.ID, "title"))
51         driver.find_element_by_id("title").clear()
52         driver.find_element_by_id("title").send_keys(data["title"])
53         driver.find_element_by_id("description").clear()
54         driver.find_element_by_id("description").send_keys(data["description"])
55         driver.find_element_by_id("tags").clear()
56         driver.find_element_by_id("tags").send_keys(data["tags"])
57         select = Select(driver.find_element_by_id("license"))
58         select.select_by_visible_text(data["license"])
59         external.assertTrue(util.is_element_present(self,By.ID, "license"))
60         external.assertTrue(util.is_element_present(self,By.ID, "tags"))
61         external.assertTrue(util.is_element_present(self,By.CSS_SELECTOR, "input.button_form"))
62         driver.find_element_by_css_selector("input.button_form").click()
63         external.assertTrue(util.is_element_present(self,By.LINK_TEXT, "Gavroche Test"))