-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
151 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pathlib | ||
|
||
from bs4 import BeautifulSoup | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def sample_record(): | ||
path = pathlib.Path(__file__).parent.parent / "data" / "record.html" | ||
return path.read_text() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def soup(sample_record): | ||
return BeautifulSoup(sample_record, features="html.parser") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import pytest | ||
|
||
from bs4 import BeautifulSoup | ||
|
||
from dear_petition.portal.etl.parsers import ( | ||
case_info, | ||
) | ||
|
||
|
||
class TestCaseInfoFullRecord: | ||
def test_parse_case_type(self, soup): | ||
assert case_info.parse_case_type(soup) == "Criminal" | ||
|
||
def test_parse_case_status_date(self, soup): | ||
assert case_info.parse_case_status_date(soup) == "12/01/2001" | ||
|
||
def test_parse_case_status(self, soup): | ||
assert case_info.parse_case_status(soup) == "Disposed" | ||
|
||
def test_parse_charge_number(self, soup): | ||
tr = soup.select_one("div[ng-if*=ShowOffenses] tr.hide-sm") | ||
assert case_info.parse_charge_number(tr) == "01" | ||
|
||
def test_parse_charge_offense(self, soup): | ||
tr = soup.select_one(case_info.SELECT_OFFENSES) | ||
assert case_info.parse_charge_offense(tr) == "EXTRADITION/FUGITIVE OTH STATE" | ||
|
||
def test_parse_statute(self, soup): | ||
tr = soup.select_one(case_info.SELECT_OFFENSES) | ||
assert case_info.parse_statute(tr) == "15A-727;733;734" | ||
|
||
def test_parse_charge_degree(self, soup): | ||
tr = soup.select_one(case_info.SELECT_OFFENSES) | ||
assert case_info.parse_charge_degree(tr) == "FNC" | ||
|
||
def test_parse_charge_offense_date(self, soup): | ||
tr = soup.select_one(case_info.SELECT_OFFENSES) | ||
assert case_info.parse_charge_offense_date(tr) == "01/01/2001" | ||
|
||
def test_parse_charge_file_date(self, soup): | ||
tr = soup.select_one(case_info.SELECT_OFFENSES) | ||
assert case_info.parse_charge_filed_date(tr) == "01/09/2001" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"parser", | ||
[ | ||
case_info.parse_case_type, | ||
case_info.parse_case_status_date, | ||
case_info.parse_case_status, | ||
case_info.parse_charge_number, | ||
case_info.parse_charge_offense, | ||
case_info.parse_statute, | ||
case_info.parse_charge_degree, | ||
case_info.parse_charge_offense_date, | ||
case_info.parse_charge_filed_date, | ||
], | ||
) | ||
def test_catch_parse_error(caplog, parser): | ||
"""Ensure HTML parse exceptions are captured and logged""" | ||
soup = BeautifulSoup("<div></div>", features="html.parser") | ||
parser(soup) | ||
assert str(parser.__name__) in caplog.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dear_petition.portal.etl.parsers import case_summary | ||
|
||
|
||
class TestCaseSummaryFullRecord: | ||
def test_parse_filno(self, soup): | ||
assert case_summary.parse_case_number(soup) == "01CR012345-678" | ||
|
||
def test_parse_county(self, soup): | ||
assert case_summary.parse_county(soup) == "Wake" | ||
|
||
def test_district_court(self, soup): | ||
assert case_summary.parse_court(soup) == "District" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dear_petition.portal.etl.parsers import dispositions | ||
|
||
|
||
class TestDispositionsFullRecord: | ||
def test_parse_event_date(self, soup): | ||
div = soup.select_one(dispositions.SELECT_DISPOSITIONS) | ||
assert dispositions.parse_event_date(div) == "12/01/2001" | ||
|
||
def test_parse_event(self, soup): | ||
div = soup.select_one(dispositions.SELECT_DISPOSITIONS) | ||
assert dispositions.parse_event(div) == "Disposition" | ||
|
||
def test_parse_charge_number(self, soup): | ||
div = soup.select_one(dispositions.SELECT_DISPOSITIONS) | ||
assert dispositions.parse_charge_number(div) == "01" | ||
|
||
def test_parse_charge_offense(self, soup): | ||
div = soup.select_one(dispositions.SELECT_DISPOSITIONS) | ||
assert ( | ||
dispositions.parse_charge_offense(div) == "EXTRADITION/FUGITIVE OTH STATE" | ||
) | ||
|
||
def test_parse_criminal_disposition(self, soup): | ||
div = soup.select_one(dispositions.SELECT_DISPOSITIONS) | ||
assert ( | ||
dispositions.parse_criminal_disposition(div) | ||
== "District Dismissed by the Court - No Plea Agreement" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from dear_petition.portal.etl.parsers import party_info | ||
|
||
|
||
class TestPartyInfoFullRecord: | ||
def test_parse_defendant_name(self, soup): | ||
assert party_info.parse_defendant_name(soup) == "DOE, JANE EMMA" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import datetime as dt | ||
|
||
from dear_petition.portal.etl.models import Disposition | ||
|
||
|
||
class TestCriminalDisposition: | ||
def test_is_dismissed(self): | ||
assert Disposition( | ||
event_date=dt.date(2000, 1, 1), | ||
event="Disposition", | ||
charge_number=1, | ||
charge_offense="BREAK OR ENTER A MOTOR VEHICLE", | ||
criminal_disposition="VD-District Dismissals w/o Leave by DA - No Plea Agreement", | ||
).is_dismissed() | ||
|
||
def test_not_is_dismissed(self): | ||
assert not Disposition( | ||
event_date=dt.date(2000, 1, 1), | ||
event="Disposition", | ||
charge_number=1, | ||
charge_offense="BREAK OR ENTER A MOTOR VEHICLE", | ||
criminal_disposition="District Guilty - Judge", | ||
).is_dismissed() |