Skip to content

Commit

Permalink
Accessibility metric added. (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Aug 21, 2019
1 parent e5bfd27 commit bd9de02
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ components/frontend/coverage/
.python-version

# Environments
.venv
*venv
env/
venv/
ENV/
Expand Down
1 change: 1 addition & 0 deletions components/collector/src/source_collectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Metric collectors per source."""

from .axecsv import *
from .azure_devops import *
from .bandit import *
from .calendar import *
Expand Down
34 changes: 34 additions & 0 deletions components/collector/src/source_collectors/axecsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Accessibility metric source."""

from datetime import datetime
from typing import cast, List

import requests
import re
import csv

from .source_collector import SourceCollector
from utilities.type import URL, Value, ErrorMessage, Response, Entities
from io import StringIO


class AxeCSV(SourceCollector):
"""Collector class to get accessibility violations."""

def parse_source_responses_value(self, responses: List[requests.Response]) -> Value:
"""Count ..."""
csvfile = StringIO(responses[0].text, newline=None)
return str(sum(1 for row in csv.DictReader(csvfile)))


def parse_source_responses_entities(self, responses: List[requests.Response]) -> Entities:
# pylint: disable=no-self-use,unused-argument
"""Parse the response to get the entities (e.g. violation, test cases, user stories) for the metric.
This method can to be overridden by collectors when a source can provide the measured entities."""

reader = csv.DictReader(StringIO(responses[0].text, newline=None))

return [dict(key=str(index), violation_type=row["Violation Type"], impact=row["Impact"],
page=re.sub(r'http[s]?://[^/]+', '', row['URL']),
url=str(row["URL"]), element=row["DOM Element"], description=row["Messages"], help=row["Help"]
) for index, row in enumerate(reader)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Unit tests for the Azure Devops Server (formerly Team Foundation Server) source."""

from .source_collector_test_case import SourceCollectorTestCase

class AxeCSVIssuesTest(SourceCollectorTestCase):
"""Unit tests for the Azure Devops Server issues metric."""

def setUp(self):
super().setUp()
self.metric = dict(type="issues", sources=dict(
source_id=dict(type="axecsv", parameters=dict(url="http://axecsv", private_token="xxx"))), addition="sum")

def test_nr_of_issues(self):
"""Test that the number of issues is returned."""
response = self.collect(
self.metric, get_request_text=
"URL,Violation Type,Impact,Help,HTML Element,Messages,DOM Element\n1,2,,6,7\n11,12,13,14,15,16,17")
self.assert_value("2", response)

def test_no_issues(self):
"""Test zero issues."""
response = self.collect(self.metric, get_request_text="")
self.assert_value("0", response)

def test_issues(self):
"""Test that the issues are returned."""
response = self.collect(
self.metric, get_request_text=
"URL,Violation Type,Impact,Help,HTML Element,Messages,DOM Element\nhttp://axe/1,2,3,4,5,6,7")
self.assert_entities(
[{'description': '6', 'element': '7', 'help': '4', 'impact': '3',
'key': '0', 'page': '/1', 'url': 'http://axe/1', 'violation_type': '2'}],
response)
81 changes: 81 additions & 0 deletions components/server/src/data/datamodel.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,23 @@
"tags": [
"maintainability"
]
},
"accessibility": {
"name": "Accessibility violations",
"description": "Measure how many accessibility violations there are on the web user interface of the software. This metric gives an indication of the quality of the user interface.",
"unit": "violations",
"addition": "sum",
"direction": "",
"target": "0",
"near_target": "1",
"default_source": "axecsv",
"sources": [
"hq",
"axecsv"
],
"tags": [
"maintainability"
]
}
},
"sources": {
Expand Down Expand Up @@ -1528,6 +1545,70 @@
}
}
},
"axecsv": {
"name": "Axe CSV",
"description": "An CSV formatted report of Axe accessibility analysis.",
"url": "https://github.com/ICTU/axe-reports",
"parameters": {
"url": {
"name": "CSV Axe report",
"type": "string",
"mandatory": true,
"default_value": "",
"metrics": [
"accessibility"
]
},
"username": {
"name": "Username for basic authentication",
"type": "string",
"mandatory": false,
"default_value": "",
"metrics": [
"accessibility"
]
},
"password": {
"name": "Password for basic authentication",
"type": "password",
"mandatory": false,
"default_value": "",
"metrics": [
"accessibility"
]
}
},
"entities": {
"accessibility": {
"name": "accessibility violation",
"name_plural": "accessibility violations",
"attributes": [
{
"name": "Violation type",
"key": "violation_type",
"url": "help"
},
{
"name": "Impact",
"key": "impact"
},
{
"name": "Page of the violation",
"key": "page",
"url": "url"
},
{
"name": "Element",
"key": "element"
},
{
"name": "Description",
"key": "description"
}
]
}
}
},
"openvas": {
"name": "OpenVAS",
"description": "OpenVAS (Open Vulnerability Assessment System) is a software framework of several services and tools offering vulnerability scanning and vulnerability management.",
Expand Down
1 change: 1 addition & 0 deletions components/testdata/public-axe-results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
URL,Violation Type,Impact,Help,HTML Element,Messages,DOM Elementhttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<strong _ngcontent-c0="">Snel naar</strong>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: bold). Expected contrast ratio of 4.5:1,stronghttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<a _ngcontent-c0="" class="td-initial" href="http://www.politie.nl" id="home-politie-hyperlink" target="_blank">Politie</a>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: normal). Expected contrast ratio of 4.5:1,#home-politie-hyperlinkhttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<a _ngcontent-c0="" class="td-initial" href="http://www.om.nl" id="home-om-hyperlink" target="_blank">Openbaar ministerie</a>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: normal). Expected contrast ratio of 4.5:1,#home-om-hyperlinkhttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<a _ngcontent-c0="" class="td-initial" href="http://www.slachtofferhulp.nl" id="home-slachtofferhulp-hyperlink" target="_blank">Slachtofferhulp Nederland</a>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: normal). Expected contrast ratio of 4.5:1,#home-slachtofferhulp-hyperlinkhttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<a _ngcontent-c0="" class="td-initial" href="http://www.schadefonds.nl" id="home-schadefonds-hyperlink" target="_blank">Schadefonds Geweldsmisdrijven</a>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: normal). Expected contrast ratio of 4.5:1,#home-schadefonds-hyperlinkhttp://axetest.csv:2019/home,color-contrast,serious,https://dequeuniversity.com/rules/axe/3.2/color-contrast?application=webdriverjs,<a _ngcontent-c0="" class="td-initial" href="http://www.cjib.nl" id="home-cjib-hyperlink" target="_blank">Centraal Justitieel Incassobureau</a>,Element has insufficient color contrast of 3.22 (foreground color: #ffffff- background color: #e17000- font size: 13.5pt- font weight: normal). Expected contrast ratio of 4.5:1,#home-cjib-hyperlink
Expand Down

0 comments on commit bd9de02

Please sign in to comment.