-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update main vote analyzer to also handle special vote titles (#1060)
- Loading branch information
Showing
7 changed files
with
115 additions
and
23 deletions.
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
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
Empty file.
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,64 @@ | ||
from howtheyvote.analysis.votes import MainVoteAnalyzer | ||
from howtheyvote.models.common import Fragment | ||
|
||
from ..helpers import record_to_dict | ||
|
||
|
||
def test_main_vote_analyzer_description(): | ||
analyzer = MainVoteAnalyzer( | ||
vote_id=1, | ||
description="Am 123", | ||
title="Lorem Ipsum", | ||
) | ||
assert analyzer.run() is None | ||
|
||
analyzer = MainVoteAnalyzer( | ||
vote_id=2, | ||
description="Proposition de résolution", | ||
title="Lorem ipsum", | ||
) | ||
expected = Fragment( | ||
model="Vote", | ||
source_id=2, | ||
source_name="MainVoteAnalyzer", | ||
group_key=2, | ||
data={"is_main": True}, | ||
) | ||
assert record_to_dict(analyzer.run()) == record_to_dict(expected) | ||
|
||
analyzer = MainVoteAnalyzer( | ||
vote_id=3, | ||
description="Accord provisoire - Am 123", | ||
title="Lorem ipsum", | ||
) | ||
expected = Fragment( | ||
model="Vote", | ||
source_id=3, | ||
source_name="MainVoteAnalyzer", | ||
group_key=3, | ||
data={"is_main": True}, | ||
) | ||
assert record_to_dict(analyzer.run()) == record_to_dict(expected) | ||
|
||
|
||
def test_main_vote_analyzer_title(): | ||
analyzer = MainVoteAnalyzer( | ||
vote_id=1, | ||
description=None, | ||
title="Ordre du jour de mardi", | ||
) | ||
assert analyzer.run() is None | ||
|
||
expected = Fragment( | ||
model="Vote", | ||
source_id=2, | ||
source_name="MainVoteAnalyzer", | ||
group_key=2, | ||
data={"is_main": True}, | ||
) | ||
analyzer = MainVoteAnalyzer( | ||
vote_id=2, | ||
description=None, | ||
title="Élection de la Commission", | ||
) | ||
assert record_to_dict(analyzer.run()) == record_to_dict(expected) |
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,7 @@ | ||
from typing import Any | ||
|
||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
|
||
def record_to_dict(record: DeclarativeBase) -> dict[str, Any]: | ||
return {c.name: getattr(record, c.name) for c in record.__table__.columns} |
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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
FIXTURES_BASE = Path(__file__).resolve().parent / "data" | ||
|
||
|
||
def load_fixture(path: str) -> str: | ||
return FIXTURES_BASE.joinpath(path).read_text() | ||
|
||
|
||
def record_to_dict(record: DeclarativeBase) -> dict[str, Any]: | ||
return {c.name: getattr(record, c.name) for c in record.__table__.columns} |
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