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

Commit

Permalink
Only consider vaccinefinder_org, vaccinespotter_org, getmyvax_org whe…
Browse files Browse the repository at this point in the history
…n deriving data, refs #650
  • Loading branch information
simonw committed Jun 21, 2021
1 parent 9b7cc30 commit 5684ffd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
11 changes: 9 additions & 2 deletions vaccinate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ def derive_availability_and_inventory(
Returns namedtuple of changes it would make. save=True to save those changes.
"""
SOURCE_NAMES_TO_CONSIDER = (
"vaccinefinder_org",
"vaccinespotter_org",
"getmyvax_org",
)
vaccines_offered = None
vaccines_offered_provenance_report = None
vaccines_offered_provenance_source_location = None
Expand All @@ -540,8 +545,9 @@ def derive_availability_and_inventory(
)
most_recent_source_location_on_vaccines_offered = (
self.matched_source_locations.all()
.order_by("-last_imported_at")
.filter(source_name__in=SOURCE_NAMES_TO_CONSIDER)
.exclude(import_json__inventory=None)
.order_by("-last_imported_at")
.first()
)

Expand Down Expand Up @@ -595,8 +601,9 @@ def derive_availability_and_inventory(
)
most_recent_source_location_on_availability = (
self.matched_source_locations.all()
.order_by("-last_imported_at")
.filter(source_name__in=SOURCE_NAMES_TO_CONSIDER)
.exclude(import_json__availability=None)
.order_by("-last_imported_at")
.first()
)

Expand Down
58 changes: 46 additions & 12 deletions vaccinate/core/test_derive_availability_and_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def test_two_reports_vaccines_offered_should_use_most_recent(location, reporter)

def test_one_source_location_vaccines_offered(location):
source_location = location.matched_source_locations.create(
source_uid="test_source_location:1",
source_name="test_source_location",
source_uid="vaccinefinder_org:1",
source_name="vaccinefinder_org",
name="Blah",
import_json={
"inventory": [
Expand Down Expand Up @@ -142,8 +142,8 @@ def test_one_source_location_vaccines_offered(location):

def test_two_source_locations_vaccines_offered(location):
location.matched_source_locations.create(
source_uid="test_source_location:1",
source_name="test_source_location",
source_uid="vaccinefinder_org:1",
source_name="vaccinefinder_org",
name="Blah",
import_json={
"inventory": [
Expand All @@ -153,8 +153,8 @@ def test_two_source_locations_vaccines_offered(location):
last_imported_at=timezone.now() - datetime.timedelta(hours=2),
)
source_location2 = location.matched_source_locations.create(
source_uid="test_source_location:2",
source_name="test_source_location",
source_uid="vaccinefinder_org:2",
source_name="vaccinefinder_org",
name="Blah",
import_json={
"inventory": [
Expand Down Expand Up @@ -201,8 +201,8 @@ def test_report_and_source_location_vaccines_offered_most_recent_wins(
created_at=report_created_at,
)
source_location = location.matched_source_locations.create(
source_uid="test_source_location:1",
source_name="test_source_location",
source_uid="vaccinefinder_org:1",
source_name="vaccinefinder_org",
name="Blah",
import_json={
"inventory": [
Expand Down Expand Up @@ -313,8 +313,8 @@ def test_one_source_location_availability(
expected_accepts_walkins,
):
source_location = location.matched_source_locations.create(
source_uid="test_source_location:1",
source_name="test_source_location",
source_uid="vaccinefinder_org:1",
source_name="vaccinefinder_org",
name="Blah",
import_json={
"availability": import_json_availability,
Expand All @@ -341,6 +341,40 @@ def test_one_source_location_availability(
)


@pytest.mark.parametrize(
"source_name,should_be_trusted",
(
("vaccinefinder_org", True),
("vaccinespotter_org", True),
("getmyvax_org", True),
("not_one_of_them", False),
),
)
def test_only_trust_source_locations_from_specific_source_names(
location,
source_name,
should_be_trusted,
):
source_location = location.matched_source_locations.create(
source_uid="{}:1".format(source_name),
source_name=source_name,
name="Blah",
import_json={"availability": {"appointments": True, "drop_in": True}},
last_imported_at=timezone.now() - datetime.timedelta(hours=1),
)
derived = location.derive_availability_and_inventory()
if should_be_trusted:
assert (
derived.appointments_walkins_provenance_source_location == source_location
)
assert derived.accepts_appointments
assert derived.accepts_walkins
else:
assert derived.appointments_walkins_provenance_source_location is None
assert not derived.accepts_appointments
assert not derived.accepts_walkins


@pytest.mark.parametrize("report_is_most_recent", (True, False))
def test_report_and_source_location_availability_most_recent_wins(
report_is_most_recent, reporter, location
Expand All @@ -361,8 +395,8 @@ def test_report_and_source_location_availability_most_recent_wins(
report.availability_tags.add(AvailabilityTag.objects.get(slug="walk_ins_only"))
# The source location says appointments only:
source_location = location.matched_source_locations.create(
source_uid="test_source_location:3",
source_name="test_source_location",
source_uid="vaccinefinder_org:3",
source_name="vaccinefinder_org",
name="Blah",
import_json={"availability": {"appointments": True, "drop_in": False}},
last_imported_at=source_location_imported_at,
Expand Down

0 comments on commit 5684ffd

Please sign in to comment.