Skip to content

Commit

Permalink
Add testing action (#7)
Browse files Browse the repository at this point in the history
- Add automated testing action
- Import chambers first.
- Add various debug catches..
  • Loading branch information
ajparsons authored Nov 3, 2024
1 parent 33f4a9a commit 5de04b9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Run linting and basic file format checks

name: Test

on:
pull_request:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Run tests and try and build project
uses: mysociety/run-in-devcontainer@v1
with:
dockerfile: Dockerfile
app: web
run: |
script/setup
script/populate --all
script/test

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ services:
POSTGRES_PASSWORD: 'password'
POSTGRES_DB: 'twfy-votes'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
working_dir: /app
web:
image: mysociety/twfy-votes:${TAG:-latest}
image: mysociety/twfy-votes-django:${TAG:-latest}
build: .
command: /app/script/server --development
volumes:
Expand All @@ -42,4 +42,4 @@ services:
volumes:
pgdata:
build:
node_modules:
node_modules:
2 changes: 1 addition & 1 deletion src/votes/populate/commons_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Member(BaseModel):
PartyAbbreviation: Optional[str]
MemberFrom: str
ListAs: Optional[str]
ProxyName: None
ProxyName: Optional[str]


class Division(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/votes/populate/divisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class api_divisions_with_total_membership:
LEFT JOIN org_membership_count on
(CAST(api_divisions.division_date as DATE) between org_membership_count.start_date
and org_membership_count.end_date
and api_divisions.chamber = org_membership_count.chamber_slug)
and CAST(api_divisions.chamber as STRING) = org_membership_count.chamber_slug)
"""


Expand Down
6 changes: 5 additions & 1 deletion src/votes/populate/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def import_popolo(quiet: bool = False):
chamber_slug = ChamberSlug.from_parlparse(
post_org_or_self_org(membership), passthrough=True
)
if chamber_slug in ["crown", "london-assembly"]:
chamber_id = 0
else:
chamber_id = chamber_slug_lookup[chamber_slug]
post = membership.post()
post_label = post.role if post else ""
area_name = post.area.name if post else ""
Expand All @@ -278,7 +282,7 @@ def import_popolo(quiet: bool = False):
effective_party_slug=effective_party,
party_id=org_slug_lookup.get(membership.on_behalf_of_id or ""),
effective_party_id=org_slug_lookup.get(effective_party),
chamber_id=chamber_slug_lookup.get(chamber_slug),
chamber_id=chamber_id,
chamber_slug=chamber_slug,
area_name=area_name,
post_label=post_label,
Expand Down
15 changes: 15 additions & 0 deletions src/votes/populate/policycalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ def generate_policy_distributions(
.df()
)

if len(df) == 0:
raise ValueError("No policy calc information returned")

list_cols = ["num_comparators", "division_ids"]
for col in df.columns:
if col not in list_cols:
Expand All @@ -547,6 +550,18 @@ def run_policy_calculations(
):
partial_update = update_since is not None

sources = [
policy_divisions_relevant,
policy_agreements_relevant,
policy_votes_relevant,
policy_collective_relevant,
pw_relevant_people,
]

for s in sources:
if s.source.exists() is False:
raise ValueError(f"{s.source} not present")

count = generate_policy_distributions(update_from_hash=partial_update, quiet=quiet)

if not quiet:
Expand Down
2 changes: 1 addition & 1 deletion src/votes/populate/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def accepts_argument(func: Callable[[Any], Any], arg_name: str):

class ImportOrder(IntEnum):
DOWNLOAD = 1
CHAMBERS = 4
PEOPLE = 5
CHAMBERS = 9
LOOKUPS = 10
API_VOTES = 14
DECISIONS = 15
Expand Down

0 comments on commit 5de04b9

Please sign in to comment.