Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Fix Report model update
Browse files Browse the repository at this point in the history
When updating a report, fatalities are always overridden.
  • Loading branch information
rgreinho committed Feb 15, 2020
1 parent baf9bb9 commit 5bb82e4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix `model.Report` update function. `fatalities` field is now always overridden with the new values. [#234]

## [[3.0.3]] - 2020-01-11

### Fixed
Expand Down Expand Up @@ -247,3 +251,4 @@ This first version allows a user to retrieve traffic fatality repports for a cer
[#224]: https://github.com/scrapd/scrapd/pull/224
[#227]: https://github.com/scrapd/scrapd/pull/227
[#230]: https://github.com/scrapd/scrapd/pull/230
[#234]: https://github.com/scrapd/scrapd/pull/234
3 changes: 3 additions & 0 deletions scrapd/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def update(self, other, strict=False):

# Set the non-empty attributes of `other` into the empty attributes of the current instance.
for attr in attrs:
if attr == 'fatalities':
setattr(self, attr, getattr(other, attr))
continue
if not getattr(self, attr) and getattr(other, attr):
setattr(self, attr, getattr(other, attr))

Expand Down
91 changes: 90 additions & 1 deletion tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,95 @@
'strict': False,
'id': 'complex',
},
{
'input_': model.Report(
case='20-0420110',
crash=15,
date=datetime.date(2020, 2, 11),
fatalities=[
model.Fatality(
age=21,
dob=datetime.date(1998, 4, 28),
ethnicity=model.Ethnicity.white,
first='Owen',
gender=model.Gender.male,
last='Macki',
middle='William',
),
],
location='North Capital of Texas Hwy/North Mopac NB Svrd',
notes=' The preliminary investigation shows Owen William Macki was driving '
'a black, 2015 Toyota Camry eastbound in the inside lane of North Capital '
'of Texas Hwy at a high rate of speed when he struck the concrete barrier '
'wall of the North Mopac NB Svrd. Owen Macki was pronounced deceased on '
'scene. The passenger in the vehicle, Raquel Gitane Aveytia, was '
'transported to Saint David’s Round Rock Medical Center where she was '
'pronounced deceased shortly after her arrival.',
time=datetime.time(2, 2),
),
'other': model.Report(
case='20-0420110',
crash=15,
date=datetime.date(2020, 2, 11),
fatalities=[
model.Fatality(
age=21,
dob=datetime.date(1998, 4, 28),
ethnicity=model.Ethnicity.white,
first='Owen',
gender=model.Gender.male,
last='Macki',
middle='William',
),
model.Fatality(
age=24,
dob=datetime.date(1995, 7, 26),
ethnicity=model.Ethnicity.asian,
first='Aamna',
gender=model.Gender.female,
last='Najam',
middle='Gitane',
),
],
time=datetime.time(2, 2),
),
'expected': model.Report(
case='20-0420110',
crash=15,
date=datetime.date(2020, 2, 11),
fatalities=[
model.Fatality(
age=21,
dob=datetime.date(1998, 4, 28),
ethnicity=model.Ethnicity.white,
first='Owen',
gender=model.Gender.male,
last='Macki',
middle='William',
),
model.Fatality(
age=24,
dob=datetime.date(1995, 7, 26),
ethnicity=model.Ethnicity.asian,
first='Aamna',
gender=model.Gender.female,
last='Najam',
middle='Gitane',
),
],
location='North Capital of Texas Hwy/North Mopac NB Svrd',
notes=' The preliminary investigation shows Owen William Macki was driving '
'a black, 2015 Toyota Camry eastbound in the inside lane of North Capital '
'of Texas Hwy at a high rate of speed when he struck the concrete barrier '
'wall of the North Mopac NB Svrd. Owen Macki was pronounced deceased on '
'scene. The passenger in the vehicle, Raquel Gitane Aveytia, was '
'transported to Saint David’s Round Rock Medical Center where she was '
'pronounced deceased shortly after her arrival.',
time=datetime.time(2, 2),
),
'strict': False,
'id': 'update-multi-fatalities',
},
]


Expand Down Expand Up @@ -163,7 +252,7 @@ def test_update_00(self, input_, other, strict, expected):
"""Ensure models can be updated."""
actual = input_.copy(deep=True)
actual.update(other, strict)
assert actual == expected
assert actual.dict() == expected.dict()

def test_update_01(self):
"""Ensure required fields are identical in strict mode."""
Expand Down

0 comments on commit 5bb82e4

Please sign in to comment.