Skip to content

Commit

Permalink
Add tests for annotation and whipreport viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Dec 20, 2024
1 parent 16df764 commit 144da6a
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 0 deletions.
164 changes: 164 additions & 0 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
from django.test import Client

import pytest

from votes.models import (
Agreement,
AgreementAnnotation,
Division,
DivisionAnnotation,
VoteAnnotation,
)

pytestmark = pytest.mark.django_db


@pytest.fixture
def agreement_annotation():
da = AgreementAnnotation(
agreement=Agreement.objects.get(key="a-commons-2021-12-13-e.876.1.2"),
detail="Link to BBC Sport",
link="https://www.bbc.co.uk/sport",
)
da.save()
yield da
da.delete()


@pytest.fixture
def division_annotation():
da = DivisionAnnotation(
division=Division.objects.get(key="pw-2016-12-13-109-commons"),
detail="Link to BBC News",
link="https://www.bbc.co.uk/news",
)
da.save()
yield da
da.delete()


@pytest.fixture
def vote_annotation():
va = VoteAnnotation(
division=Division.objects.get(key="pw-2016-12-13-109-commons"),
person_id=10001,
detail="Link to Google",
link="https://www.google.com",
)
va.save()
yield va
va.delete()


def test_original_data_agreement(client: Client):
response = client.get("/decisions/agreement/commons/2021-12-13/e.876.1.2")
content = response.content.decode()
assert "Link to BBC Sport" not in content
assert "https://www.bbc.co.uk/sport" not in content


def test_original_data_agreement_json(client: Client):
response = client.get("/decisions/agreement/commons/2021-12-13/e.876.1.2.json")
content = response.content.decode()
assert "Link to BBC Sport" not in content
assert "https://www.bbc.co.uk/sport" not in content


def test_agreement_annotation(
client: Client, agreement_annotation: AgreementAnnotation
):
response = client.get("/decisions/agreement/commons/2021-12-13/e.876.1.2")
content = response.content.decode()
assert "Link to BBC Sport" in content
assert "https://www.bbc.co.uk/sport" in content


def test_agreement_annotation_json(
client: Client, agreement_annotation: AgreementAnnotation
):
response = client.get("/decisions/agreement/commons/2021-12-13/e.876.1.2.json")
content = response.content.decode()
assert "Link to BBC Sport" in content
assert "https://www.bbc.co.uk/sport" in content


def test_original_data(client: Client):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
for text in ["Link to BBC News", "Link to Google"]:
assert text not in content
for url in ["https://www.bbc.co.uk/news", "https://www.google.com"]:
assert url not in content


def test_original_data_json(client: Client):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
content = response.content.decode()
for text in ["Link to BBC News", "Link to Google"]:
assert text not in content
for url in ["https://www.bbc.co.uk/news", "https://www.google.com"]:
assert url not in content


def test_division_annotation(client: Client, division_annotation: DivisionAnnotation):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
assert "Link to BBC News" in content
assert "https://www.bbc.co.uk/news" in content
assert "Link to Google" not in content
assert "https://www.google.com" not in content


def test_division_annotation_json(
client: Client, division_annotation: DivisionAnnotation
):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
content = response.content.decode()
assert "Link to BBC News" in content
assert "https://www.bbc.co.uk/news" in content
assert "Link to Google" not in content
assert "https://www.google.com" not in content


def test_vote_annotation(client: Client, vote_annotation: VoteAnnotation):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
assert "Link to BBC News" not in content
assert "https://www.bbc.co.uk/news" not in content
assert "Link to Google" in content
assert "https://www.google.com" in content


def test_vote_annotation_json(client: Client, vote_annotation: VoteAnnotation):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
content = response.content.decode()
assert "Link to BBC News" not in content
assert "https://www.bbc.co.uk/news" not in content
assert "Link to Google" in content
assert "https://www.google.com" in content


def test_division_and_vote_annotation(
client: Client,
division_annotation: DivisionAnnotation,
vote_annotation: VoteAnnotation,
):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
assert "Link to BBC News" in content
assert "https://www.bbc.co.uk/news" in content
assert "Link to Google" in content
assert "https://www.google.com" in content


def test_division_and_vote_annotation_json(
client: Client,
division_annotation: DivisionAnnotation,
vote_annotation: VoteAnnotation,
):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
content = response.content.decode()
assert "Link to BBC News" in content
assert "https://www.bbc.co.uk/news" in content
assert "Link to Google" in content
assert "https://www.google.com" in content
59 changes: 59 additions & 0 deletions tests/test_whip_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.test import Client

import pytest

from votes.consts import EvidenceType, WhipDirection, WhipPriority
from votes.models import (
Division,
Organization,
WhipReport,
)

pytestmark = pytest.mark.django_db


@pytest.fixture
def whip_report():
da = WhipReport(
division=Division.objects.get(key="pw-2016-12-13-109-commons"),
whip_direction=WhipDirection.AGAINST,
whip_priority=WhipPriority.THREE_LINE,
party=Organization.objects.get(slug="labour"),
evidence_type=EvidenceType.OTHER,
)
da.save()
yield da
da.delete()


def test_original_data(client: Client):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
for text in ["Whip reports", "against", "three_line"]:
assert text not in content


def test_original_data_json(client: Client):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
content = response.content.decode()
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
for text in ["Whip reports", "against", "three_line"]:
assert text not in content


def test_whip_report(client: Client, whip_report: WhipReport):
response = client.get("/decisions/division/commons/2016-12-13/109")
content = response.content.decode()
for text in ["Whip reports", "against", "three_line"]:
assert text in content


def test_whip_report_json(client: Client, whip_report: WhipReport):
response = client.get("/decisions/division/commons/2016-12-13/109.json")
data = response.json()
assert len(data["whip_reports"]) > 0
labour_whip = [x for x in data["whip_reports"] if x["party"] == "Labour"]
assert len(labour_whip) == 1
assert labour_whip[0]["whip_direction"] == "against"
assert labour_whip[0]["whip_priority"] == "three_line"

0 comments on commit 144da6a

Please sign in to comment.