Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Ran pyupgrade on half of the python files
Browse files Browse the repository at this point in the history
  • Loading branch information
UsamaSadiq committed Oct 14, 2020
1 parent ccc9851 commit 11480c8
Show file tree
Hide file tree
Showing 41 changed files with 262 additions and 334 deletions.
4 changes: 1 addition & 3 deletions a11y_tests/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from acceptance_tests.mixins import AnalyticsApiClientMixin, LoginMixin


Expand All @@ -10,6 +8,6 @@ class CoursePageTestsMixin(LoginMixin, AnalyticsApiClientMixin):
page = None

def setUp(self):
super(CoursePageTestsMixin, self).setUp()
super().setUp()
self.api_date_format = self.analytics_api_client.DATE_FORMAT
self.api_datetime_format = self.analytics_api_client.DATETIME_FORMAT
15 changes: 7 additions & 8 deletions a11y_tests/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests for course analytics pages
"""

from __future__ import absolute_import

from bok_choy.page_object import PageObject

Expand All @@ -16,13 +15,13 @@ class CoursePage(PageObject):
def __init__(self, browser, course_id=None):
# Create the path
self.course_id = course_id or TEST_COURSE_ID
path = 'courses/{}'.format(self.course_id)
path = f'courses/{self.course_id}'

self.server_url = DASHBOARD_SERVER_URL
self.page_url = '{0}/{1}'.format(self.server_url, path)
self.page_url = f'{self.server_url}/{path}'

# Call the constructor and setup the URL
super(CoursePage, self).__init__(browser)
super().__init__(browser)

def is_browser_on_page(self):
return self.browser.current_url == self.page_url
Expand All @@ -36,13 +35,13 @@ class CourseEnrollmentDemographicsPage(CoursePage):
demographic = None

def __init__(self, browser, course_id=None):
super(CourseEnrollmentDemographicsPage, self).__init__(browser, course_id)
self.page_url += '/enrollment/demographics/{0}/'.format(self.demographic)
super().__init__(browser, course_id)
self.page_url += f'/enrollment/demographics/{self.demographic}/'

def is_browser_on_page(self):
return (
super(CourseEnrollmentDemographicsPage, self).is_browser_on_page()
and 'Enrollment Demographics by {0}'.format(self.demographic.title())
super().is_browser_on_page()
and f'Enrollment Demographics by {self.demographic.title()}'
in self.browser.title
)

Expand Down
4 changes: 1 addition & 3 deletions a11y_tests/test_course_enrollment_demographics_axs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from bok_choy.promise import EmptyPromise
from bok_choy.web_app_test import WebAppTest

Expand All @@ -15,7 +13,7 @@ class CourseEnrollmentDemographicsAgeTests(CoursePageTestsMixin, WebAppTest):
"""

def setUp(self):
super(CourseEnrollmentDemographicsAgeTests, self).setUp()
super().setUp()
self.page = CourseEnrollmentDemographicsAgePage(self.browser)

def test_a11y(self):
Expand Down
26 changes: 12 additions & 14 deletions acceptance_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@


import locale
import os

locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')


def str2bool(s):
return str(s).lower() in (u"yes", u"true", u"t", u"1")
return str(s).lower() in ("yes", "true", "t", "1")


# Dashboard settings
Expand Down Expand Up @@ -40,27 +38,27 @@ def str2bool(s):
if ENABLE_OAUTH_TESTS and not (LMS_HOSTNAME and LMS_USERNAME and LMS_PASSWORD):
raise Exception('LMS settings must be set in order to test OAuth.')

TEST_COURSE_ID = os.environ.get('TEST_COURSE_ID', u'edX/DemoX/Demo_Course')
TEST_COURSE_ID = os.environ.get('TEST_COURSE_ID', 'edX/DemoX/Demo_Course')
TEST_ASSIGNMENT_TYPE = os.environ.get('TEST_ASSIGNMENT_TYPE', 'Homework')
TEST_ASSIGNMENT_ID = os.environ.get('TEST_ASSIGNMENT_ID', u'i4x://edX/DemoX/sequential/basic_questions')
TEST_ASSIGNMENT_ID = os.environ.get('TEST_ASSIGNMENT_ID', 'i4x://edX/DemoX/sequential/basic_questions')
TEST_GRADED_PROBLEM_ID = os.environ.get('TEST_GRADED_PROBLEM_ID',
u'i4x://edX/DemoX/problem/a0effb954cca4759994f1ac9e9434bf4')
'i4x://edX/DemoX/problem/a0effb954cca4759994f1ac9e9434bf4')
TEST_GRADED_PROBLEM_PART_ID = os.environ.get('TEST_GRADED_PROBLEM_PART_ID',
u'i4x-edX-DemoX-problem-a0effb954cca4759994f1ac9e9434bf4_2_1')
'i4x-edX-DemoX-problem-a0effb954cca4759994f1ac9e9434bf4_2_1')
TEST_UNGRADED_SECTION_ID = os.environ.get('TEST_UNGRADED_SECTION_ID',
u'i4x://edX/DemoX/chapter/interactive_demonstrations')
'i4x://edX/DemoX/chapter/interactive_demonstrations')
TEST_UNGRADED_SUBSECTION_ID = os.environ.get('TEST_UNGRADED_SUBSECTION_ID',
u'i4x://edX/DemoX/sequential/19a30717eff543078a5d94ae9d6c18a5')
'i4x://edX/DemoX/sequential/19a30717eff543078a5d94ae9d6c18a5')
TEST_UNGRADED_PROBLEM_ID = os.environ.get('TEST_UNGRADED_PROBLEM_ID',
u'i4x://edX/DemoX/problem/303034da25524878a2e66fb57c91cf85')
'i4x://edX/DemoX/problem/303034da25524878a2e66fb57c91cf85')
TEST_UNGRADED_PROBLEM_PART_ID = os.environ.get('TEST_UNGRADED_PROBLEM_PART_ID',
u'i4x-edX-DemoX-problem-303034da25524878a2e66fb57c91cf85_2_1')
'i4x-edX-DemoX-problem-303034da25524878a2e66fb57c91cf85_2_1')
TEST_VIDEO_SECTION_ID = os.environ.get('TEST_VIDEO_SECTION_ID',
u'i4x://edX/DemoX/chapter/interactive_demonstrations')
'i4x://edX/DemoX/chapter/interactive_demonstrations')
TEST_VIDEO_SUBSECTION_ID = os.environ.get('TEST_VIDEO_SUBSECTION_ID',
u'i4x://edX/DemoX/sequential/19a30717eff543078a5d94ae9d6c18a5')
'i4x://edX/DemoX/sequential/19a30717eff543078a5d94ae9d6c18a5')
TEST_VIDEO_ID = os.environ.get('TEST_VIDEO_ID',
u'i4x://edX/DemoX/video/7e9b434e6de3435ab99bd3fb25bde807')
'i4x://edX/DemoX/video/7e9b434e6de3435ab99bd3fb25bde807')

DOC_BASE_URL = os.environ.get('DOC_BASE_URL', 'http://edx-insights.readthedocs.org/en/latest')

Expand Down
2 changes: 0 additions & 2 deletions acceptance_tests/course_validation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import os

from acceptance_tests import str2bool
Expand Down
12 changes: 5 additions & 7 deletions acceptance_tests/course_validation/report_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import datetime
import logging
import traceback
Expand Down Expand Up @@ -50,11 +48,11 @@ def get_http_status_and_load_time(self, url):

def build_course_path(self, path):
path = path.strip('/')
return '/courses/{}/{}/'.format(self.course_id, path)
return f'/courses/{self.course_id}/{path}/'

def get_dashboard_url(self, path):
path = path.strip('/')
return '{}/{}/'.format(DASHBOARD_SERVER_URL, path)
return f'{DASHBOARD_SERVER_URL}/{path}/'

def generate_report(self):
"""
Expand Down Expand Up @@ -283,7 +281,7 @@ class CoursePerformanceScreenshotReporter(CoursePerformanceReportGenerator):
REPORT_NAME = 'course_performance_screenshot'

def __init__(self, course_id, http_cookies=None):
super(CoursePerformanceScreenshotReporter, self).__init__(course_id, http_cookies)
super().__init__(course_id, http_cookies)
self.driver = webdriver.Firefox()

def _take_screenshot(self, url_path):
Expand All @@ -310,9 +308,9 @@ def _login(self):
if BASIC_AUTH_CREDENTIALS:
username = BASIC_AUTH_CREDENTIALS[0]
password = BASIC_AUTH_CREDENTIALS[1]
url = url.replace('://', '://{}:{}@'.format(username, password))
url = url.replace('://', f'://{username}:{password}@')

self.driver.get('{}/login'.format(url))
self.driver.get(f'{url}/login')
self.driver.find_element_by_id('login-email').send_keys(LMS_USERNAME)
self.driver.find_element_by_id('login-password').send_keys(LMS_PASSWORD)
self.driver.find_element_by_css_selector('button.login-button').click()
Expand Down
15 changes: 7 additions & 8 deletions acceptance_tests/course_validation/report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import datetime
import io
import json
import logging
import time
Expand Down Expand Up @@ -64,7 +63,7 @@ def _setup_logging():
msg_format = '%(asctime)s - %(levelname)s - %(message)s'

logging.basicConfig(
filename='{}-course_report.log'.format(TIMESTAMP),
filename=f'{TIMESTAMP}-course_report.log',
format=msg_format,
level=level)

Expand Down Expand Up @@ -126,7 +125,7 @@ def login(http_client):

if ENABLE_AUTO_AUTH:
logger.info('Logging into dashboard with auto auth...')
response = http_client.get('{}/test/auto_auth/'.format(DASHBOARD_SERVER_URL))
response = http_client.get(f'{DASHBOARD_SERVER_URL}/test/auto_auth/')

if response.status_code == 200:
logger.info('Login succeeded.')
Expand All @@ -140,8 +139,8 @@ def login(http_client):
if BASIC_AUTH_CREDENTIALS:
http_client.auth = BASIC_AUTH_CREDENTIALS

lms_login = '{}/login'.format(LMS_URL)
lms_login_ajax = '{}/login_ajax'.format(LMS_URL)
lms_login = f'{LMS_URL}/login'
lms_login_ajax = f'{LMS_URL}/login_ajax'

# Make a call to the login page to get cookies (esp. CSRF token)
http_client.get(lms_login)
Expand Down Expand Up @@ -175,7 +174,7 @@ def get_courses():
filename = 'courses.json'

try:
with io.open(filename, 'r', encoding='utf-8') as f:
with open(filename, 'r', encoding='utf-8') as f:
courses = json.load(f)
except Exception as e: # pylint: disable=broad-except
logger.warning('Failed to read courses from file: %s', e)
Expand All @@ -188,7 +187,7 @@ def get_courses():
courses = [course['id'] for course in courses]
courses.sort(key=lambda course: course.lower())

with io.open(filename, 'w', encoding='utf-8') as f:
with open(filename, 'w', encoding='utf-8') as f:
f.write(str(json.dumps(courses, ensure_ascii=False)))

logger.info('Retrieved %s courses.', len(courses))
Expand All @@ -212,7 +211,7 @@ def main():

# Create the mappings
mappings_file = join(dirname(abspath(__file__)), 'mappings.json')
with io.open(mappings_file, 'r', encoding='utf-8') as f:
with open(mappings_file, 'r', encoding='utf-8') as f:
mappings = json.load(f)

for doc_type, body in mappings.items():
Expand Down
Loading

0 comments on commit 11480c8

Please sign in to comment.