Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DMalone87 committed Dec 10, 2024
1 parent cbcec2e commit 4243b83
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scrapers/fifty_a/fifty_a/spiders/officer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def parse_officer(self, response):
# Yield Litigation Items
yield from self.parse_litigation(response)

def parse_litigation(self, response) -> List[CreateLitigation]:
def parse_litigation(self, response):
container = response.css("div.lawsuits-details")
if not container:
return []
Expand Down
4 changes: 3 additions & 1 deletion tests/fifty_a/fifty_a/spiders/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from scrapy.http import HtmlResponse

from models.agencies import CreateUnit
from scrapers.fifty_a.fifty_a.items import AGENCY_UID, SOURCE_UID
from scrapers.fifty_a.fifty_a.spiders.command import CommandSpider
from tests.fifty_a.fifty_a.spiders.command_page import command_1

Expand All @@ -18,7 +19,8 @@ def test_parse_command(self):
unit = results[0]
assert unit.url == mock_response.url
assert unit.model == "unit"
assert unit.source == "50-a.org"
assert unit.source_uid == SOURCE_UID
assert unit.agency == AGENCY_UID

try:
valid_data = CreateUnit(**unit.data)
Expand Down
41 changes: 39 additions & 2 deletions tests/fifty_a/fifty_a/spiders/test_officer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from datetime import date

import pytest
from scrapy.http import HtmlResponse

from models.litigation import CreateLitigation
from models.officers import CreateOfficer
from scrapers.fifty_a.fifty_a.items import AGENCY_UID, SOURCE_UID
from scrapers.fifty_a.fifty_a.spiders.officer import OfficerSpider
from tests.fifty_a.fifty_a.spiders.officer_page import officer_1

Expand Down Expand Up @@ -31,14 +35,18 @@ def test_parse_complaints(self):
def test_parse_officer(self):
spider = OfficerSpider()
results = [i for i in spider.parse_officer(mock_response)]
assert len(results) == 1
assert len(results) == 6

officer = results[0]
assert officer.url == mock_response.url
assert officer.model == "officer"
assert officer.source == "50-a.org"
assert officer.source_uid == SOURCE_UID
assert officer.service_start == "July 2009"

for e in officer.employment:
assert e["agency_uid"] == AGENCY_UID
assert "/command/" in e["unit_uid"]

try:
valid_data = CreateOfficer(**officer.data)
except ValueError as e:
Expand All @@ -50,3 +58,32 @@ def test_parse_officer(self):
assert valid_data.gender == "Male"
assert valid_data.state_ids[0].value == "948283"
assert valid_data.state_ids[0].id_name == "Tax ID"
assert (
valid_data.attachments[0].url
== "https://www.documentcloud.org/documents/21019814-daf-wang948283"
)
assert valid_data.attachments[0].title == "DA Disclosure Letter"

litigation = results[1]

try:
valid_lawsuit = CreateLitigation(**litigation.data)
except ValueError as e:
pytest.fail(f"Litigation Data is invalid: {e}")

assert valid_lawsuit.case_title == "Cavender, Shawn vs City of New York, et al."
assert (
valid_lawsuit.url
== "https://www.courtlistener.com/docket/60324680/cavender-v-city-of-new-york/"
)
assert valid_lawsuit.settlement_amount == 60000
assert valid_lawsuit.docket_number == "21CV07290"
assert valid_lawsuit.court_level == "Federal District Court"
assert valid_lawsuit.start_date == date(2021, 10, 28)
assert valid_lawsuit.end_date == date(2022, 11, 2)
assert valid_lawsuit.documents[0].title == "Complaint"
assert (
valid_lawsuit.documents[0].url
== "https://storage.courtlistener.com/recap/gov.uscourts.nysd.565800/gov.uscourts.nysd.565800.17.0.pdf"
)
assert valid_lawsuit.defendants[0] == mock_response.url

0 comments on commit 4243b83

Please sign in to comment.