Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ jobs:
tag_with_ref: true
tags: latest, django-dev
runs-on: ubuntu-latest
publish-plural:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
project_id: civic-eagle-enview-prod
credentials_json: "${{ secrets.PLURAL_OPEN_REPO_PUSHER_KEY }}"
- name: Setup Google Cloud SDK
uses: "google-github-actions/setup-gcloud@v2"
- name: Docker Auth
run: |-
gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
- name: Build and Push docker image
uses: docker/build-push-action@v3
with:
context: .
tags: "us-central1-docker.pkg.dev/civic-eagle-enview-prod/open-containers/openstates.org:latest,us-central1-docker.pkg.dev/civic-eagle-enview-prod/open-containers/openstates.org:${{ github.sha }}"
push: true
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: set poetry config path
run: poetry config virtualenvs.path ~/.virtualenvs
- name: install python dependencies
run: poetry install
run: poetry install --no-root

- name: lint with flake8 and black
run: poetry run inv lint
Expand Down
5 changes: 4 additions & 1 deletion people_admin/management/commands/check_unmatched_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ def add_arguments(self, parser):
parser.add_argument(
"--no-deltas", dest="deltas", default=True, action="store_false"
)
parser.add_argument(
"--active-sessions-only", dest="active", default=False, action="store_true"
)

def handle(self, *args, **options):
states = set()
for state, session in yield_state_sessions(
options["state"], options["session"]
options["state"], options["session"], active_only=options["active"]
):
unmatched = update_unmatched(state, session)
print(f"processed {unmatched} unmatched people for {state} {session}")
Expand Down
120 changes: 61 additions & 59 deletions public/tests/test_legislator_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from graphapi.tests.utils import populate_db
from openstates.data.models import Person
from utils.common import pretty_url

# from openstates.data.models import Person
# from utils.common import pretty_url


@pytest.mark.django_db
Expand All @@ -20,63 +21,64 @@ def test_legislators_view(client, django_assert_num_queries):
assert len(resp.context["legislators"]) == 6


@pytest.mark.django_db
def test_person_view(client, django_assert_num_queries):
p = Person.objects.get(name="Amanda Adams")
with django_assert_num_queries(9):
resp = client.get(pretty_url(p))
assert resp.status_code == 200
assert resp.context["state"] == "ak"
assert resp.context["state_nav"] == "legislators"
person = resp.context["person"]
assert person.name == "Amanda Adams"
assert person.primary_party == "Republican"
assert (
person.current_jurisdiction_id
== "ocd-jurisdiction/country:us/state:ak/government"
)
assert person.current_role == {
"org_classification": "lower",
"district": 1,
"division_id": "ocd-division/country:us/state:ak/sldl:1",
"title": "Representative",
}
assert len(person.sponsored_bills) == 2
assert len(person.vote_events) == 1
assert resp.context["retired"] is False


@pytest.mark.django_db
def test_person_view_retired(client, django_assert_num_queries):
p = Person.objects.get(name="Rhonda Retired")
# fewer views, we don't do the bill queries
with django_assert_num_queries(9):
resp = client.get(pretty_url(p))
assert resp.status_code == 200
assert resp.context["state"] == "ak"
assert resp.context["state_nav"] == "legislators"
person = resp.context["person"]
assert person.name == "Rhonda Retired"
assert resp.context["retired"] is True


@pytest.mark.django_db
def test_person_view_invalid_uuid(client, django_assert_num_queries):
p = Person.objects.get(name="Rhonda Retired")
resp = client.get(
pretty_url(p)[:-1] + "abcdefghij/"
) # this won't be a valid pretty UUID
assert resp.status_code == 404


@pytest.mark.django_db
def test_canonicalize_person(client):
p = Person.objects.get(name="Amanda Adams")
url = pretty_url(p).replace("amanda", "xyz")
assert "xyz" in url
resp = client.get(url)
assert resp.status_code == 301
assert resp.url == pretty_url(p)
# Person view is disabled in favor of Plural app
# @pytest.mark.django_db
# def test_person_view(client, django_assert_num_queries):
# p = Person.objects.get(name="Amanda Adams")
# with django_assert_num_queries(9):
# resp = client.get(pretty_url(p))
# assert resp.status_code == 200
# assert resp.context["state"] == "ak"
# assert resp.context["state_nav"] == "legislators"
# person = resp.context["person"]
# assert person.name == "Amanda Adams"
# assert person.primary_party == "Republican"
# assert (
# person.current_jurisdiction_id
# == "ocd-jurisdiction/country:us/state:ak/government"
# )
# assert person.current_role == {
# "org_classification": "lower",
# "district": 1,
# "division_id": "ocd-division/country:us/state:ak/sldl:1",
# "title": "Representative",
# }
# assert len(person.sponsored_bills) == 2
# assert len(person.vote_events) == 1
# assert resp.context["retired"] is False
#
#
# @pytest.mark.django_db
# def test_person_view_retired(client, django_assert_num_queries):
# p = Person.objects.get(name="Rhonda Retired")
# # fewer views, we don't do the bill queries
# with django_assert_num_queries(9):
# resp = client.get(pretty_url(p))
# assert resp.status_code == 200
# assert resp.context["state"] == "ak"
# assert resp.context["state_nav"] == "legislators"
# person = resp.context["person"]
# assert person.name == "Rhonda Retired"
# assert resp.context["retired"] is True
#
#
# @pytest.mark.django_db
# def test_person_view_invalid_uuid(client, django_assert_num_queries):
# p = Person.objects.get(name="Rhonda Retired")
# resp = client.get(
# pretty_url(p)[:-1] + "abcdefghij/"
# ) # this won't be a valid pretty UUID
# assert resp.status_code == 404
#
#
# @pytest.mark.django_db
# def test_canonicalize_person(client):
# p = Person.objects.get(name="Amanda Adams")
# url = pretty_url(p).replace("amanda", "xyz")
# assert "xyz" in url
# resp = client.get(url)
# assert resp.status_code == 301
# assert resp.url == pretty_url(p)


# TODO: test find_your_legislator
10 changes: 6 additions & 4 deletions public/views/legislators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.shortcuts import get_object_or_404, render, redirect
from django.shortcuts import render, redirect
from django.http import JsonResponse
from graphapi.schema import schema
from openstates.data.models import Person, Bill
from utils.common import decode_uuid, jid_to_abbr, pretty_url
from openstates.data.models import Person
from utils.common import decode_uuid, pretty_url
from utils.orgs import get_chambers_from_abbr
from utils.people import person_as_dict

Expand Down Expand Up @@ -103,4 +103,6 @@ def person(request, person_id):
person_id # will be invalid and raise 404, but useful in logging later
)
redirect_person_id = ocd_person_id.replace("ocd-person/", "")
return redirect(f"https://pluralpolicy.com/app/person/{redirect_person_id}/", permanent=True)
return redirect(
f"https://pluralpolicy.com/app/person/{redirect_person_id}/", permanent=True
)
7 changes: 5 additions & 2 deletions utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from utils.common import abbr_to_jid, states, sessions_with_bills


def yield_state_sessions(state: str, session: Optional[str]):
def yield_state_sessions(state: str, session: Optional[str], active_only=False):
"""
parse provided options to get a list of sessions to process
"""
Expand All @@ -25,6 +25,9 @@ def yield_state_sessions(state: str, session: Optional[str]):
yield state, session
else:
# single state
sessions = sorted(s.identifier for s in sessions_with_bills(abbr_to_jid(state)))
sessions = sorted(
s.identifier
for s in sessions_with_bills(abbr_to_jid(state), active_only=active_only)
)
for session in sessions:
yield state, session
23 changes: 16 additions & 7 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ def pretty_url(obj):
raise NotImplementedError(obj)


def sessions_with_bills(jid):
return (
LegislativeSession.objects.filter(jurisdiction_id=jid)
.annotate(bill_count=Count("bills"))
.filter(bill_count__gt=0)
.order_by("-start_date", "-identifier")
)
def sessions_with_bills(jid, active_only=False):
if active_only:
return (
LegislativeSession.objects.filter(jurisdiction_id=jid)
.annotate(bill_count=Count("bills"))
.filter(bill_count__gt=0)
.filter(active=True)
.order_by("-start_date", "-identifier")
)
else:
return (
LegislativeSession.objects.filter(jurisdiction_id=jid)
.annotate(bill_count=Count("bills"))
.filter(bill_count__gt=0)
.order_by("-start_date", "-identifier")
)