Skip to content

Commit

Permalink
black and flake8 linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Mar 16, 2024
1 parent 2f1a97e commit c2b301f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion parsons/action_builder/action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def add_section_field_values_to_record(
{
"action_builder:name": tag,
"action_builder:field": field,
"action_builder:section": section
"action_builder:section": section,
}
for field, tag in field_values.items()
]
Expand Down
38 changes: 20 additions & 18 deletions test/test_action_builder/test_action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def setUp(self, m):

self.fake_field_values = {
"Fake Field 2": "Fake Tag 5",
self.fake_field_1: self.fake_tag_4
self.fake_field_1: self.fake_tag_4,
}

self.fake_tagging = [
Expand All @@ -140,7 +140,7 @@ def setUp(self, m):
"action_builder:name": "Fake Tag 5",
"action_builder:field": "Fake Field 2",
"action_builder:section": self.fake_section,
}
},
]

self.fake_entity_id = "fake-entity-id-1"
Expand All @@ -162,7 +162,7 @@ def setUp(self, m):
"status": "unsubscribed",
"source": "api",
}
]
],
}

self.fake_upsert_person = {
Expand All @@ -179,9 +179,9 @@ def setUp(self, m):
"action_builder:identifier": "action_builder:fake-email-id-1",
"address": "fakey@mcfakerson.com",
"address_type": "Work",
"status": "unsubscribed"
"status": "unsubscribed",
}
]
],
}
}

Expand All @@ -197,7 +197,7 @@ def setUp(self, m):
"created_date": self.fake_datetime,
"modified_date": self.fake_datetime,
}
}
},
}

self.fake_update_person = {
Expand Down Expand Up @@ -234,7 +234,8 @@ def test_get_all_records(self, m):
text=json.dumps({"_embedded": {"osdi:tags": []}}),
)
assert_matching_tables(
self.bldr._get_all_records(self.campaign, "tags"), Table(self.fake_tags_list)
self.bldr._get_all_records(self.campaign, "tags"),
Table(self.fake_tags_list),
)

@requests_mock.Mocker()
Expand Down Expand Up @@ -274,14 +275,15 @@ def prepare_dict_key_intersection(self, dict1, dict2):
# Internal method to compare a reference dict to a new incoming one, keeping only common
# keys whose values are not lists (i.e. nested).

common_keys = {key for key, value in dict1.items() if key in dict2
and not isinstance(value, list)}
common_keys = {
key
for key, value in dict1.items()
if key in dict2 and not isinstance(value, list)
}

dict1_comp = {key: value for key, value in dict1.items()
if key in common_keys}
dict1_comp = {key: value for key, value in dict1.items() if key in common_keys}

dict2_comp = {key: value for key, value in dict2.items()
if key in common_keys}
dict2_comp = {key: value for key, value in dict2.items() if key in common_keys}

return dict1_comp, dict2_comp

Expand All @@ -291,7 +293,9 @@ def test_upsert_entity(self, m):

# Flatten and remove items added for spreadable arguments
upsert_person = self.fake_upsert_person["person"]
upsert_response = self.bldr._upsert_entity(self.fake_upsert_person, self.campaign)
upsert_response = self.bldr._upsert_entity(
self.fake_upsert_person, self.campaign
)

person_comp, upsert_response_comp = self.prepare_dict_key_intersection(
upsert_person, upsert_response
Expand Down Expand Up @@ -348,15 +352,13 @@ def tagging_callback(self, request, context):
tagging_data = post_data["add_tags"]

# Force the sort to allow for predictable comparison
return sorted(tagging_data, key=lambda k: k['action_builder:name'])
return sorted(tagging_data, key=lambda k: k["action_builder:name"])

@requests_mock.Mocker()
def test_add_section_field_values_to_record(self, m):
m.post(f"{self.api_url}/people", json=self.tagging_callback)
add_tags_response = self.bldr.add_section_field_values_to_record(
self.fake_entity_id,
self.fake_section,
self.fake_field_values
self.fake_entity_id, self.fake_section, self.fake_field_values
)
self.assertEqual(add_tags_response, self.fake_tagging)

Expand Down
21 changes: 14 additions & 7 deletions useful_resources/sample_code/ngpvan_sample_printedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
This script pulls turf information (i.e. precinct name, list number, people count, door count, etc.)
from a specificed NGP VAN folder and creates a master check list and pdf printouts to circumvent
the sometimes lengthy process in VAN.
To use the script, be sure to set your environmental variables for VAN_API_KEY and GOOGLE_DRIVE_CREDENTIALS.
The blog post explaining contextual information for this script can be found here: .
Please also note that due to the inability to test the script, I decided to pare it down. It does not
include turf prioritization, apartment demarcation, and walkability scores as shown in the blog post.
To use the script, be sure to set your environmental variables for VAN_API_KEY and
GOOGLE_DRIVE_CREDENTIALS.
The blog post explaining contextual information for this script can be found here: .
Please also note that due to the inability to test the script,
I decided to pare it down. It does not include turf prioritization, apartment demarcation,
and walkability scores as shown in the blog post.
To execute the script, run:
python3 ngpvan_sample_printedlist.py --van_folder_name="{Name of NGP VAN folder where printed lists are stored}" --gsheet_uri={URI for gsheet where NGP VAN data will be stored}""
python3 ngpvan_sample_printedlist.py \
--van_folder_name="{Name of NGP VAN folder where printed lists are stored}" \
--gsheet_uri="{URI for gsheet where NGP VAN data will be stored}"
"""

import pandas as pd
from fpdf import FPDF
from parsons import VAN, GoogleSheets, Table
import json
import click


# ~~~~~~~~~~~~~~ Get Printed and Saved List Info From VAN ~~~~~~~~~~~~~~~~#


Expand Down

0 comments on commit c2b301f

Please sign in to comment.