From 4243b833a9de340d6cfe483e0730dd1ca989c331 Mon Sep 17 00:00:00 2001 From: Darrell Malone Jr Date: Mon, 9 Dec 2024 19:29:59 -0600 Subject: [PATCH] Update tests --- scrapers/fifty_a/fifty_a/spiders/officer.py | 2 +- tests/fifty_a/fifty_a/spiders/test_command.py | 4 +- tests/fifty_a/fifty_a/spiders/test_officer.py | 41 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/scrapers/fifty_a/fifty_a/spiders/officer.py b/scrapers/fifty_a/fifty_a/spiders/officer.py index 114940a..144a561 100644 --- a/scrapers/fifty_a/fifty_a/spiders/officer.py +++ b/scrapers/fifty_a/fifty_a/spiders/officer.py @@ -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 [] diff --git a/tests/fifty_a/fifty_a/spiders/test_command.py b/tests/fifty_a/fifty_a/spiders/test_command.py index 616edfa..c6f7118 100644 --- a/tests/fifty_a/fifty_a/spiders/test_command.py +++ b/tests/fifty_a/fifty_a/spiders/test_command.py @@ -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 @@ -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) diff --git a/tests/fifty_a/fifty_a/spiders/test_officer.py b/tests/fifty_a/fifty_a/spiders/test_officer.py index 7958ee6..a9a4739 100644 --- a/tests/fifty_a/fifty_a/spiders/test_officer.py +++ b/tests/fifty_a/fifty_a/spiders/test_officer.py @@ -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 @@ -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: @@ -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