Commit 71699eb4 by Christine Lytwynec

add first a11y test and run it in travis builds

parent 426fe52a
...@@ -14,7 +14,8 @@ script: ...@@ -14,7 +14,8 @@ script:
- make static -e DJANGO_SETTINGS_MODULE="analytics_dashboard.settings.test" - make static -e DJANGO_SETTINGS_MODULE="analytics_dashboard.settings.test"
- make validate - make validate
- make generate_fake_translations - make generate_fake_translations
- bash ./runAcceptance.sh - make accept
- make a11y
branches: branches:
only: only:
- master - master
......
...@@ -39,7 +39,10 @@ test_python: clean ...@@ -39,7 +39,10 @@ test_python: clean
--with-ignore-docstrings --cover-xml --cover-xml-file=$(COVERAGE)/coverage.xml --with-ignore-docstrings --cover-xml --cover-xml-file=$(COVERAGE)/coverage.xml
accept: accept:
nosetests -v acceptance_tests --exclude-dir=acceptance_tests/course_validation ./runTests.sh acceptance_tests
a11y:
SELENIUM_BROWSER=phantomjs ./runTests.sh a11y_tests
course_validation: course_validation:
python -m acceptance_tests.course_validation.generate_report python -m acceptance_tests.course_validation.generate_report
......
from acceptance_tests.mixins import LoginMixin, AnalyticsApiClientMixin
class CoursePageTestsMixin(LoginMixin, AnalyticsApiClientMixin):
""" Mixin for course page tests. """
DASHBOARD_DATE_FORMAT = '%B %d, %Y'
page = None
def setUp(self):
super(CoursePageTestsMixin, self).setUp()
self.api_date_format = self.analytics_api_client.DATE_FORMAT
self.api_datetime_format = self.analytics_api_client.DATETIME_FORMAT
"""
Tests for course analytics pages
"""
from bok_choy.page_object import PageObject
from acceptance_tests import TEST_COURSE_ID, DASHBOARD_SERVER_URL
class DashboardPage(PageObject): # pylint: disable=abstract-method
path = None
basic_auth_username = None
basic_auth_password = None
@property
def url(self):
return self.page_url
def __init__(self, browser, path=None):
super(DashboardPage, self).__init__(browser)
path = path or self.path
self.server_url = DASHBOARD_SERVER_URL
self.page_url = '{0}/{1}'.format(self.server_url, path)
class CoursePage(DashboardPage):
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)
# Call the constructor and setup the URL
super(CoursePage, self).__init__(browser, path)
def is_browser_on_page(self):
return self.browser.current_url == self.page_url
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)
def is_browser_on_page(self):
return (
super(CourseEnrollmentDemographicsPage, self).is_browser_on_page()
and 'Enrollment Demographics by {0}'.format(self.demographic.title())
in self.browser.title
)
class CourseEnrollmentDemographicsAgePage(CourseEnrollmentDemographicsPage):
demographic = 'age'
from bok_choy.web_app_test import WebAppTest
from a11y_tests.pages import CourseEnrollmentDemographicsAgePage
from a11y_tests.mixins import CoursePageTestsMixin
_multiprocess_can_split_ = True
class CourseEnrollmentDemographicsAgeTests(CoursePageTestsMixin, WebAppTest):
"""
A test for the accessibility of the CourseEnrollmentDemographicsAgePage.
"""
def setUp(self):
super(CourseEnrollmentDemographicsAgeTests, self).setUp()
self.page = CourseEnrollmentDemographicsAgePage(self.browser)
def test_axs(self):
# Log in and navigate to page
self.login()
self.page.visit()
# Generate accessibillity report
report = self.page.do_axs_audit()
# Check that there was one page reviewed in this report
self.assertEqual(1, len(report))
result = report[0]
# Verify that this page has no accessibility errors.
self.assertEqual(0, len(result.errors))
# Verify that this page currently has 2 accessibility warnings.
self.assertEqual(2, len(result.warnings))
# And that these are the warnings that the page currently gives.
for warning in result.warnings:
self.assertTrue(
warning.startswith((
'Warning: AX_FOCUS_01',
'Warning: AX_COLOR_01',
)),
msg="Unexpected warning: {}".format(warning)
)
#!/usr/bin/env bash #!/usr/bin/env bash
TEST_DIR=${1?arg missing, specify a directory to find tests}
# this stops the django servers # this stops the django servers
stopServers() { stopServers() {
kill $(ps aux | grep "[m]anage.py" | awk '{print $2}') kill $(ps aux | grep "[m]anage.py" | awk '{print $2}')
...@@ -25,15 +27,16 @@ echo "Preparing Analytics Data API..." ...@@ -25,15 +27,16 @@ echo "Preparing Analytics Data API..."
cd edx-analytics-data-api/ cd edx-analytics-data-api/
make travis make travis
cd - cd -
mkdir -p logs
echo "Starting Analytics Data API Server..." echo "Starting Analytics Data API Server..."
./edx-analytics-data-api/manage.py runserver 9001 --noreload & ./edx-analytics-data-api/manage.py runserver 9001 --noreload > logs/api.log 2>&1 &
echo "Starting Analytics Dashboard Server..." echo "Starting Analytics Dashboard Server..."
./manage.py runserver 9000 --noreload & ./manage.py runserver 9000 --noreload --traceback > logs/dashboard.log 2>&1 &
echo "Running acceptance tests..." echo "Running $TEST_DIR tests..."
make accept -e NUM_PROCESSES=1 nosetests -v $TEST_DIR -e NUM_PROCESSES=1 --exclude-dir=acceptance_tests/course_validation
# capture the exit code from the test. Anything more than 0 indicates failed cases. # capture the exit code from the test. Anything more than 0 indicates failed cases.
EXIT_CODE=$? EXIT_CODE=$?
...@@ -45,5 +48,9 @@ if [[ "$EXIT_CODE" = "0" ]]; then ...@@ -45,5 +48,9 @@ if [[ "$EXIT_CODE" = "0" ]]; then
echo "All tests passed..." echo "All tests passed..."
else else
echo "Failed tests..." echo "Failed tests..."
echo -e "\033[33;34m Server Logs for Analytics Data API Server... \033[0m "
cat logs/api.log
echo -e "\033[33;34m Server logs for Analytics Dashboard Server... \033[0m "
cat logs/dashboard.log
fi fi
exit $EXIT_CODE exit $EXIT_CODE
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment