-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ivan
committed
Aug 21, 2019
1 parent
e5bfd27
commit bd9de02
Showing
6 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ components/frontend/coverage/ | |
.python-version | ||
|
||
# Environments | ||
.venv | ||
*venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
33 changes: 33 additions & 0 deletions
33
components/collector/tests/unittests/source_collectors_tests/test_axecsv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters