Skip to content

Commit e4bb839

Browse files
committed
linting applied
1 parent e25ccde commit e4bb839

32 files changed

+758
-321
lines changed

api/osf_api.py

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import settings
21
import json
3-
import os
42
import logging
5-
import requests
3+
import os
64

5+
import requests
76
from pythosf import client
7+
8+
import settings
9+
810
logger = logging.getLogger(__name__)
911

1012

1113
def get_default_session():
12-
return client.Session(api_base_url=settings.API_DOMAIN, auth=(settings.USER_ONE, settings.USER_ONE_PASSWORD))
14+
return client.Session(
15+
api_base_url=settings.API_DOMAIN,
16+
auth=(settings.USER_ONE, settings.USER_ONE_PASSWORD),
17+
)
1318

1419

1520
def create_project(session, title='osf selenium test', tags=None, **kwargs):
@@ -125,7 +130,9 @@ def delete_all_user_projects(session, user=None):
125130
for error_tuple in nodes_failed:
126131
# Position [0] of error_tuple contains node_id
127132
# Position [1] of error_tuple contains the exception
128-
error_message = "node '{}' errored with exception: '{}'".format(error_tuple[0], error_tuple[1])
133+
error_message = "node '{}' errored with exception: '{}'".format(
134+
error_tuple[0], error_tuple[1]
135+
)
129136
error_message_list.append(error_message)
130137
logger.error('\n'.join(error_message_list))
131138

@@ -206,7 +213,14 @@ def get_existing_file(session, node_id=settings.PREFERRED_NODE):
206213
return upload_fake_file(session, node)
207214

208215

209-
def upload_fake_file(session, node=None, name='osf selenium test file for testing because its fake.txt', upload_url=None, provider='osfstorage', quickfile=False):
216+
def upload_fake_file(
217+
session,
218+
node=None,
219+
name='osf selenium test file for testing because its fake.txt',
220+
upload_url=None,
221+
provider='osfstorage',
222+
quickfile=False,
223+
):
210224
"""Upload an almost empty file to the given node. Return the file's name.
211225
212226
Note: The default file has a very long name because it makes it easier to click a link to it.
@@ -215,9 +229,13 @@ def upload_fake_file(session, node=None, name='osf selenium test file for testin
215229
if not upload_url:
216230
if not node:
217231
raise TypeError('Node must not be none when upload URL is not set.')
218-
upload_url = '{}/v1/resources/{}/providers/{}/'.format(settings.FILE_DOMAIN, node.id, provider)
232+
upload_url = '{}/v1/resources/{}/providers/{}/'.format(
233+
settings.FILE_DOMAIN, node.id, provider
234+
)
219235

220-
metadata = session.put(url=upload_url, query_parameters={'kind': 'file', 'name': name}, raw_body={})
236+
metadata = session.put(
237+
url=upload_url, query_parameters={'kind': 'file', 'name': name}, raw_body={}
238+
)
221239

222240
if quickfile:
223241
# create_guid param is tied to the GET request so we can't use query_parameters={'create_guid': 1} here
@@ -270,13 +288,14 @@ def get_providers_total(provider_name, session):
270288
""" Return the total number of preprints for a given service provider.
271289
Note: Reformat provider names to all lowercase and remove white spaces.
272290
"""
273-
provider_url = '/v2/providers/preprints/{}/preprints/'.format(provider_name.lower().replace(' ', ''))
291+
provider_url = '/v2/providers/preprints/{}/preprints/'.format(
292+
provider_name.lower().replace(' ', '')
293+
)
274294
return session.get(provider_url)['links']['meta']['total']
275295

276296

277297
def connect_provider_root_to_node(
278-
session, provider, external_account_id,
279-
node_id=settings.PREFERRED_NODE,
298+
session, provider, external_account_id, node_id=settings.PREFERRED_NODE,
280299
):
281300
"""Initialize the node<=>addon connection, add the given external_account_id, and configure it
282301
to connect to the root folder of the provider."""
@@ -306,7 +325,9 @@ def connect_provider_root_to_node(
306325
},
307326
}
308327
addon = session.patch(
309-
url=url, item_type='node_addons', item_id=provider,
328+
url=url,
329+
item_type='node_addons',
330+
item_id=provider,
310331
raw_body=json.dumps(raw_payload),
311332
)
312333
# payload = {
@@ -321,7 +342,9 @@ def connect_provider_root_to_node(
321342
root_folder = session.get(url + 'folders/')['data'][0]['attributes']['folder_id']
322343
raw_payload['data']['attributes']['folder_id'] = root_folder
323344
addon = session.patch(
324-
url=url, item_type='node_addons', item_id=provider,
345+
url=url,
346+
item_type='node_addons',
347+
item_id=provider,
325348
raw_body=json.dumps(raw_payload),
326349
)
327350
return addon

base/exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class HttpError(PageException):
99
class LoginError(PageException):
1010
"""Error used when driver is in an unexpected login state.
1111
"""
12+
1213
pass

base/expected_conditions.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class link_has_href(object):
55
""" An Expectation for checking link is visible and has an href so
66
you can click it."""
7+
78
def __init__(self, locator):
89
self.locator = locator
910

@@ -18,6 +19,7 @@ def __call__(self, driver):
1819
class window_at_index(object):
1920
""" An Expectation for checking if a tab is open for certain index
2021
so you can switch to it."""
22+
2123
def __init__(self, page_index):
2224
self.page_index = page_index
2325

base/locators.py

+49-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import settings
1+
from selenium.common.exceptions import (
2+
NoSuchElementException,
3+
StaleElementReferenceException,
4+
TimeoutException,
5+
)
6+
from selenium.webdriver.support import expected_conditions as EC
7+
from selenium.webdriver.support.ui import WebDriverWait
28

9+
import settings
310
from base import expected_conditions as ec
4-
from selenium.webdriver.support.ui import WebDriverWait
5-
from selenium.webdriver.support import expected_conditions as EC
6-
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException, NoSuchElementException
11+
712

813
class WebElementWrapper:
914
"""A wrapper for selenium's WebElement. Supports all WebElement attributes
@@ -13,6 +18,7 @@ class WebElementWrapper:
1318
:param str attribute_name: The attribute name of the locator in its containing class.
1419
:param locator: An object of the type Locator.
1520
"""
21+
1622
def __init__(self, driver, attribute_name, locator):
1723
self.driver = driver
1824
self.locator = locator
@@ -90,8 +96,7 @@ def click_expecting_popup(self, timeout=settings.TIMEOUT):
9096
self.click()
9197

9298
try:
93-
WebDriverWait(self.driver, timeout).until(
94-
EC.number_of_windows_to_be(2))
99+
WebDriverWait(self.driver, timeout).until(EC.number_of_windows_to_be(2))
95100
except TimeoutException:
96101
raise ValueError('No new window was opened.')
97102
self.driver.close()
@@ -106,13 +111,15 @@ def send_keys_deliberately(self, keys):
106111
for k in keys:
107112
self.element.send_keys(k)
108113

114+
109115
class BaseLocator:
110116
"""Abstract base class from which all Locator classes inherit.
111117
112118
Includes the method of how to locate the element (a subclass of selenium By),
113119
a string that actually identifies the element, and a timeout for how long to wait
114120
when searching for the element.
115121
"""
122+
116123
def __init__(self, selector, path, timeout=settings.TIMEOUT):
117124
self.selector = selector
118125
self.path = path
@@ -135,6 +142,7 @@ class Locator(BaseLocator):
135142
most notably `get_web_element`. You may end up waiting longer than your timeout because some
136143
methods use more than one Wait.
137144
"""
145+
138146
def get_web_element(self, driver, attribute_name):
139147
"""
140148
Check if element is on page and visible before returning the selenium
@@ -150,39 +158,54 @@ def get_web_element(self, driver, attribute_name):
150158
WebDriverWait(driver, self.timeout).until(
151159
EC.presence_of_element_located(self.location)
152160
)
153-
except(TimeoutException, StaleElementReferenceException):
154-
raise ValueError('Element {} not present on page. {}'.format(
155-
attribute_name, driver.current_url)) from None
161+
except (TimeoutException, StaleElementReferenceException):
162+
raise ValueError(
163+
'Element {} not present on page. {}'.format(
164+
attribute_name, driver.current_url
165+
)
166+
) from None
156167

157168
try:
158169
WebDriverWait(driver, self.timeout).until(
159170
EC.visibility_of_element_located(self.location)
160171
)
161-
except(TimeoutException, StaleElementReferenceException):
162-
raise ValueError('Element {} not visible before timeout. {}'.format(
163-
attribute_name, driver.current_url)) from None
172+
except (TimeoutException, StaleElementReferenceException):
173+
raise ValueError(
174+
'Element {} not visible before timeout. {}'.format(
175+
attribute_name, driver.current_url
176+
)
177+
) from None
164178

165179
try:
166180
WebDriverWait(driver, self.timeout).until(
167181
EC.element_to_be_clickable(self.location)
168182
)
169-
except(TimeoutException, StaleElementReferenceException):
170-
raise ValueError('Element {} not clickable before timeout. {}'.format(
171-
attribute_name, driver.current_url)) from None
183+
except (TimeoutException, StaleElementReferenceException):
184+
raise ValueError(
185+
'Element {} not clickable before timeout. {}'.format(
186+
attribute_name, driver.current_url
187+
)
188+
) from None
172189

173190
if 'href' in attribute_name:
174191
try:
175192
WebDriverWait(driver, self.timeout).until(
176193
ec.link_has_href(self.location)
177194
)
178-
except(TimeoutException, StaleElementReferenceException):
179-
raise ValueError('Element {} on page but does not have a href. {}'.format(
180-
attribute_name, driver.current_url)) from None
195+
except (TimeoutException, StaleElementReferenceException):
196+
raise ValueError(
197+
'Element {} on page but does not have a href. {}'.format(
198+
attribute_name, driver.current_url
199+
)
200+
) from None
181201
try:
182202
return driver.find_element(self.selector, self.path)
183203
except NoSuchElementException:
184-
raise ValueError('Element {} was present, but now is gone. {}'.format(
185-
attribute_name, driver.current_url)) from None
204+
raise ValueError(
205+
'Element {} was present, but now is gone. {}'.format(
206+
attribute_name, driver.current_url
207+
)
208+
) from None
186209

187210
def get_element(self, driver, attribute_name):
188211
return WebElementWrapper(driver, attribute_name, self)
@@ -195,6 +218,7 @@ class GroupLocator(BaseLocator):
195218
:param str path: Identifying string that is shared between the elements
196219
you are attempting to locate.
197220
"""
221+
198222
def get_web_elements(self, driver):
199223
return driver.find_elements(self.selector, self.path)
200224

@@ -214,7 +238,10 @@ class ComponentLocator(Locator):
214238
:param component_class: A subclass of BaseElment.
215239
Note: Currently the parameters selector, path, and timeout don't do anything.
216240
"""
217-
def __init__(self, component_class, selector=None, path=None, timeout=settings.TIMEOUT):
241+
242+
def __init__(
243+
self, component_class, selector=None, path=None, timeout=settings.TIMEOUT
244+
):
218245
super().__init__(selector, path, timeout)
219246
self.component_class = component_class
220247

@@ -227,6 +254,7 @@ class BaseElement:
227254
Handles waffled pages, storage of the WebDriver, and returning WebElements when Locators are
228255
accessed.
229256
"""
257+
230258
default_timeout = settings.TIMEOUT
231259

232260
def __new__(cls, *args, **kwargs):

components/accessibility.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import settings
21
import os
32

43
import pandas as pd
54
from axe_selenium_python import Axe
65

7-
class ApplyA11yRules:
6+
import settings
87

8+
9+
class ApplyA11yRules:
910
def run_axe(driver, session, page_name, write_files=True, terminal_errors=True):
1011
""" Use the axe testing engine to perform accessibility checks on a web page
1112
Parameters:
@@ -37,6 +38,7 @@ def run_axe(driver, session, page_name, write_files=True, terminal_errors=True):
3738
# - shared Google Drive folder
3839
# - Github repository (either selenium-a11y repo or maybe separate dedicated repo)
3940

41+
4042
def write_results_files(axe, results, page_name):
4143
""" Write results to output .json files (3 separate files for passes, violations,
4244
and incomplete) and also convert each .json file to a .csv file. So there should
@@ -57,20 +59,32 @@ def write_results_files(axe, results, page_name):
5759
if not os.path.isdir(work_dir):
5860
os.mkdir(work_dir)
5961
# Files for Passed Rules
60-
file_name_passes = os.path.join(work_dir, 'a11y_' + page_name + '_passes_' + settings.DOMAIN + '.json')
62+
file_name_passes = os.path.join(
63+
work_dir, 'a11y_' + page_name + '_passes_' + settings.DOMAIN + '.json'
64+
)
6165
axe.write_results(results['passes'], file_name_passes)
6266
pandaObject = pd.read_json(file_name_passes)
63-
file_name_passes_csv = os.path.join(work_dir, 'a11y_' + page_name + '_passes_' + settings.DOMAIN + '.csv')
67+
file_name_passes_csv = os.path.join(
68+
work_dir, 'a11y_' + page_name + '_passes_' + settings.DOMAIN + '.csv'
69+
)
6470
pandaObject.to_csv(file_name_passes_csv)
6571
# Files for Failed Rules (aka Violations)
66-
file_name_violations = os.path.join(work_dir, 'a11y_' + page_name + '_violations_' + settings.DOMAIN + '.json')
72+
file_name_violations = os.path.join(
73+
work_dir, 'a11y_' + page_name + '_violations_' + settings.DOMAIN + '.json'
74+
)
6775
axe.write_results(results['violations'], file_name_violations)
6876
pandaObject = pd.read_json(file_name_violations)
69-
file_name_violations_csv = os.path.join(work_dir, 'a11y_' + page_name + '_violations_' + settings.DOMAIN + '.csv')
77+
file_name_violations_csv = os.path.join(
78+
work_dir, 'a11y_' + page_name + '_violations_' + settings.DOMAIN + '.csv'
79+
)
7080
pandaObject.to_csv(file_name_violations_csv)
7181
# Files for Rules that couldn't be evaluated by the rules engine (aka Incomplete)
72-
file_name_incomplete = os.path.join(work_dir, 'a11y_' + page_name + '_incomplete_' + settings.DOMAIN + '.json')
82+
file_name_incomplete = os.path.join(
83+
work_dir, 'a11y_' + page_name + '_incomplete_' + settings.DOMAIN + '.json'
84+
)
7385
axe.write_results(results['incomplete'], file_name_incomplete)
7486
pandaObject = pd.read_json(file_name_incomplete)
75-
file_name_incomplete_csv = os.path.join(work_dir, 'a11y_' + page_name + '_incomplete_' + settings.DOMAIN + '.csv')
87+
file_name_incomplete_csv = os.path.join(
88+
work_dir, 'a11y_' + page_name + '_incomplete_' + settings.DOMAIN + '.csv'
89+
)
7690
pandaObject.to_csv(file_name_incomplete_csv)

0 commit comments

Comments
 (0)