This repository has been archived by the owner on May 1, 2023. It is now read-only.
generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add A11yReport model #101
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
api/db_migrations/versions/e251ec3b0f77_create_a11y_reports_table.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,39 @@ | ||
"""create a11y_reports table | ||
|
||
Revision ID: e251ec3b0f77 | ||
Revises: eb58f2b364a3 | ||
Create Date: 2021-08-24 19:49:08.946361 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e251ec3b0f77" | ||
down_revision = "eb58f2b364a3" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"a11y_reports", | ||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True), | ||
sa.Column("scan_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("product", sa.String(), nullable=False), | ||
sa.Column("revision", sa.String(), nullable=False), | ||
sa.Column("url", sa.String()), | ||
sa.Column("ci", sa.Boolean, unique=False, default=False), | ||
sa.Column("summary", postgresql.JSONB(), nullable=False), | ||
sa.Column("created_at", sa.DateTime, default=sa.func.utc_timestamp()), | ||
sa.Column("updated_at", sa.DateTime, onupdate=sa.func.utc_timestamp()), | ||
sa.ForeignKeyConstraint( | ||
["scan_id"], | ||
["scans.id"], | ||
), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("a11y_reports") |
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,53 @@ | ||
import datetime | ||
import uuid | ||
|
||
from sqlalchemy import Boolean, DateTime, Column, ForeignKey, String | ||
from sqlalchemy.dialects.postgresql import JSONB, UUID | ||
from sqlalchemy.orm import relationship, validates | ||
|
||
from models import Base | ||
from models.Scan import Scan | ||
|
||
|
||
class A11yReport(Base): | ||
__tablename__ = "a11y_reports" | ||
|
||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | ||
product = Column(String, nullable=False) | ||
revision = Column(String, nullable=False) | ||
url = Column(String) | ||
ci = Column(Boolean, unique=False, default=False) | ||
summary = Column(JSONB, nullable=False) | ||
created_at = Column( | ||
DateTime, | ||
index=False, | ||
unique=False, | ||
nullable=False, | ||
default=datetime.datetime.utcnow, | ||
) | ||
updated_at = Column( | ||
DateTime, | ||
index=False, | ||
unique=False, | ||
nullable=True, | ||
onupdate=datetime.datetime.utcnow, | ||
) | ||
scan_id = Column( | ||
UUID(as_uuid=True), ForeignKey(Scan.id), index=True, nullable=False | ||
) | ||
scan = relationship("Scan", back_populates="a11y_reports") | ||
|
||
@validates("product") | ||
def validate_product(self, _key, value): | ||
assert value != "" | ||
return value | ||
|
||
@validates("revision") | ||
def validate_revision(self, _key, value): | ||
assert value != "" | ||
return value | ||
|
||
@validates("summary") | ||
def validate_summary(self, _key, value): | ||
assert value is not None | ||
return value |
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
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
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,124 @@ | ||
import pytest | ||
|
||
from sqlalchemy.exc import IntegrityError | ||
|
||
|
||
from models.A11yReport import A11yReport | ||
|
||
|
||
def test_a11y_report_belongs_to_an_scan(scan_fixture, session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
url="url", | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
session.commit() | ||
assert scan_fixture.a11y_reports[-1].id == a11y_report.id | ||
session.delete(a11y_report) | ||
session.commit() | ||
|
||
|
||
def test_a11y_report_model(scan_fixture): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
url="url", | ||
ci=True, | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
assert a11y_report.product == "product" | ||
assert a11y_report.revision == "revision" | ||
assert a11y_report.url == "url" | ||
assert a11y_report.ci is True | ||
assert a11y_report.summary == {"jsonb": "data"} | ||
assert a11y_report.scan is not None | ||
|
||
|
||
def test_a11y_report_model_saved(assert_new_model_saved, scan_fixture, session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
url="url", | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
session.commit() | ||
assert a11y_report.product == "product" | ||
assert a11y_report.revision == "revision" | ||
assert a11y_report.url == "url" | ||
assert_new_model_saved(a11y_report) | ||
assert a11y_report.ci is False | ||
assert a11y_report.summary == {"jsonb": "data"} | ||
session.delete(a11y_report) | ||
session.commit() | ||
|
||
|
||
def test_a11y_report_empty_productfails(scan_fixture, session): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar version of these tests by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes those get caught:
|
||
a11y_report = A11yReport( | ||
revision="revision", | ||
url="url", | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
with pytest.raises(IntegrityError): | ||
session.commit() | ||
session.rollback() | ||
|
||
|
||
def test_a11y_report_empty_revision_fails(scan_fixture, session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
url="url", | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
with pytest.raises(IntegrityError): | ||
session.commit() | ||
session.rollback() | ||
|
||
|
||
def test_a11y_report_empty_url_passes(scan_fixture, session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
summary={"jsonb": "data"}, | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
session.commit() | ||
assert a11y_report.url is None | ||
session.delete(a11y_report) | ||
session.commit() | ||
|
||
|
||
def test_a11y_report_empty_summary_fails(scan_fixture, session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
url="url", | ||
scan=scan_fixture, | ||
) | ||
session.add(a11y_report) | ||
with pytest.raises(IntegrityError): | ||
session.commit() | ||
session.rollback() | ||
|
||
|
||
def test_a11y_report_empty_scan_fails(session): | ||
a11y_report = A11yReport( | ||
product="product", | ||
revision="revision", | ||
url="url", | ||
summary={"jsonb": "data"}, | ||
) | ||
session.add(a11y_report) | ||
with pytest.raises(IntegrityError): | ||
session.commit() | ||
session.rollback() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still catch
""
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that just becomes an empty json string, which is not deal either. I will add both tests