/usr/lib/python2.7/dist-packages/schooltool/gradebook/stesting.py is in python-schooltool.gradebook 2.6.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2012 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Selenium functional tests setup for schooltool.gradebook
"""
from schooltool.app.testing import format_table
css_to_code = {
'valid': 'v',
'error': 'i',
'extracredit': 'e',
}
def tertiary_navigation(browser):
result = []
sel = 'ul.third-nav li'
for tab in browser.query_all.css(sel):
text = tab.query.tag('a').get_attribute('title').strip()
css_class = tab.get_attribute('class')
if css_class is not None and 'active' in css_class:
text = '*%s*' % text
result.append(text)
return result
def table_header(browser):
result = []
row1 = []
sel = '.students thead a.popup_link'
for header in browser.query_all.css(sel):
row1.append(header.text.strip())
sel = '.grades thead a.popup_link'
headers = browser.driver.execute_script(
'return $(arguments[0])', sel)
row1.extend([header.text.strip() for header in headers])
sel = '.totals thead a.popup_link'
headers = browser.driver.execute_script(
'return $(arguments[0])', sel)
row1.extend([header.text.strip() for header in headers])
result.append(row1)
row2 = ['', '']
sel = '#grades-part thead tr:nth-child(2) th'
headers = browser.driver.execute_script(
'return $(arguments[0])', sel)
row2.extend([header.text.strip() for header in headers])
sel = '#totals-part thead th'
headers = browser.driver.execute_script(
'return $(arguments[0])', sel)
row2.extend(['' for header in headers])
result.append(row2)
return result
def table_rows(browser, show_validation):
rows = []
sel = '.students tbody tr'
student_rows = browser.driver.execute_script(
'return $(arguments[0])', sel)
for row in student_rows:
student = []
links = browser.driver.execute_script(
'return $(arguments[0]).find("a.popup_link")', row)
for link in links:
student.append(link.text.strip())
rows.append(student)
sel = '.grades tbody tr'
grade_rows = browser.driver.execute_script(
'return $(arguments[0])', sel)
for index, row in enumerate(grade_rows):
student = rows[index]
tds = browser.driver.execute_script(
'return $(arguments[0]).find("td").not(".placeholder")', row)
for td in tds:
fields = browser.driver.execute_script(
'return $(arguments[0]).find("input")', td)
if fields:
field = fields[0]
value = browser.driver.execute_script(
'return arguments[0].value', field)
value = '[%s]' % value.ljust(5, '_')
if show_validation:
css_class = field.get_attribute('class')
value += css_to_code.get(css_class, '')
else:
value = td.text.strip()
student.append(value)
sel = '.totals tbody tr'
total_rows = browser.driver.execute_script(
'return $(arguments[0])', sel)
for index, row in enumerate(total_rows):
student = rows[index]
tds = browser.driver.execute_script(
'return $(arguments[0]).find("td")', row)
for td in tds:
student.append(td.text.strip())
return rows
def print_gradebook(browser, show_validation):
print format_table([tertiary_navigation(browser)])
rows = []
rows.extend(table_header(browser))
for row in table_rows(browser, show_validation):
rows.append(row)
print format_table(rows, header_rows=2)
def registerSeleniumSetup():
try:
import selenium
except ImportError:
return
from schooltool.testing import registry
import schooltool.testing.selenium
def printGradebook(browser, show_validation=False):
print_gradebook(browser, show_validation)
registry.register('SeleniumHelpers',
lambda: schooltool.testing.selenium.registerBrowserUI(
'gradebook.worksheet.pprint', printGradebook))
def score(browser, student, activity, grade):
row_index = None
column_index = None
sel = '.students tbody td:first-child a.popup_link'
# XXX: reverse in tests
if ', ' in student:
student = ' '.join(reversed(student.split(', ')))
for index, link in enumerate(browser.query_all.css(sel)):
if student == link.get_attribute('title'):
row_index = index
break
sel = '.grades thead a.popup_link'
for index, link in enumerate(browser.query_all.css(sel)):
if activity == link.text:
column_index = index
break
sel = ('//div[contains(@class, "grades")]'
'//tbody/tr[%s]/td[%s]' % (row_index+1, column_index+1))
cell = browser.query.xpath(sel)
cell.click()
cell.query.tag('input').type(browser.keys.DELETE, grade)
sel = 'ul.ui-autocomplete'
browser.driver.execute_script(
'$(arguments[0]).find(arguments[1]).hide()', cell, sel)
registry.register('SeleniumHelpers',
lambda: schooltool.testing.selenium.registerBrowserUI(
'gradebook.worksheet.score', score))
registerSeleniumSetup()
del registerSeleniumSetup
|