Skip to content

Commit

Permalink
Test Coverage by Domain
Browse files Browse the repository at this point in the history
 Resolves [Reports #15](#15)

Signed-off-by: Bentley Hensel <bentleyhensel@gmail.com>
  • Loading branch information
TheBoatyMcBoatFace committed Sep 26, 2023
1 parent b298f13 commit fc2e6e8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
Empty file added .env-template
Empty file.
5 changes: 3 additions & 2 deletions .github/workflows/containerize.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🏗️📤 Build and publish 🐳 images
name: Build and publish 🐳 images

on:
push:
Expand All @@ -13,7 +13,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
build:
name: 🏗️📤 Build and push 🐳 image
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -51,6 +51,7 @@ jobs:
type=raw,value=latest,priority=100,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=sha,enable=true,prefix={{branch}}-,suffix=,format=short,priority=300
type=raw,prefix={{branch}}-,value=latest,priority=200,enable=${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
type=raw,value={{branch}},priority=500
# Caching | https://docs.docker.com/build/ci/github-actions/cache/
- name: 🏗️📤 Build and push 🐳 image
Expand Down
31 changes: 31 additions & 0 deletions app/api/axe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,34 @@ def axe_domain_error_summary():
return format_output(results, output_format, 'axe_domain_error_summary')
except Exception as e:
return jsonify({"error": str(e)}), 500

# Githib Reports #15
# https://github.com/orgs/GovA11y/projects/1?pane=issue&itemId=34493510
@axe_bp.route('/test-summary', methods=['GET'])
def axe_summary():
raw_domain = request.args.get('domain', 'gsa.gov')
domain = f"%{raw_domain}"


sql_file = "app/api/database/postgres/queries/axe/coverage.sql"
logger.info(f'Request: Test Coverage by Domain\nDomain: {raw_domain}')

# Read sql file
with open(sql_file) as file:
sql_content = file.read()
formatted_sql_content = sql_content % domain

results = []
try:
# Run the query using ClickHouse's execute method
rows = clickhouse_conn.execute(formatted_sql_content, with_column_types=True)
keys = [col[0] for col in rows[1]]
for row in rows[0]:
results.append({key: value for key,value in zip(keys, row)})
output_format = request.args.get('format', 'json')
return format_output(results, output_format, 'domain_summary')
except Exception as e:
return jsonify({"error": str(e)}), 500



19 changes: 19 additions & 0 deletions app/api/database/postgres/queries/axe/coverage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Test Coverage by Domain
-- app/api/database/postgres/queries/axe/coverage.sql

SELECT
d.domain,
COUNT(u.id) AS total_urls,
COUNT(CASE WHEN u.active_scan_axe THEN 1 END) AS active_axe_urls,
COUNT(CASE WHEN u.is_objective THEN 1 END) AS is_objective_urls,
COUNT(CASE WHEN u.errored THEN 1 END) AS errored_urls,
ROUND(
100.0 * COUNT(CASE WHEN u.active_scan_axe THEN 1 END) / NULLIF(COUNT(u.id), 0),
2
) AS domain_coverage_axe
FROM targets.domains d
LEFT JOIN targets.urls u ON d.id = u.domain_id
WHERE d."domain" ILIKE '%s'
GROUP BY d.domain
ORDER BY d.domain;

2 changes: 1 addition & 1 deletion app/api/domain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ def domain_add():
output_format = request.args.get('format', 'json')
return format_output(results, output_format, 'domain_summary')
except Exception as e:
return jsonify({"error": str(e)}), 500
return jsonify({"error": str(e)}), 500
2 changes: 2 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# Use the APP_PORT environment variable
port = os.environ.get('APP_PORT', 8080)
app.run(host='0.0.0.0', port=port, debug=True)


0 comments on commit fc2e6e8

Please sign in to comment.