diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d0e27aeb..c82bfbeb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2e03712..3f946e7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/people_admin/management/commands/check_unmatched_names.py b/people_admin/management/commands/check_unmatched_names.py index 0a64346b..cc912ce9 100644 --- a/people_admin/management/commands/check_unmatched_names.py +++ b/people_admin/management/commands/check_unmatched_names.py @@ -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}") diff --git a/public/tests/test_legislator_views.py b/public/tests/test_legislator_views.py index 1de78cb0..3b0b60fc 100644 --- a/public/tests/test_legislator_views.py +++ b/public/tests/test_legislator_views.py @@ -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 @@ -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 diff --git a/public/views/legislators.py b/public/views/legislators.py index 61d8c559..8719f2bb 100644 --- a/public/views/legislators.py +++ b/public/views/legislators.py @@ -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 @@ -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 + ) diff --git a/utils/cli.py b/utils/cli.py index 5493e975..c4535cbe 100644 --- a/utils/cli.py +++ b/utils/cli.py @@ -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 """ @@ -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 diff --git a/utils/common.py b/utils/common.py index 44cb51b2..e9abfd3e 100644 --- a/utils/common.py +++ b/utils/common.py @@ -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") + )