Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxachis committed Dec 17, 2024
1 parent 35f7fee commit 13144a4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 49 deletions.
7 changes: 1 addition & 6 deletions database_client/database_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,12 +1213,7 @@ def _build_column_references(
linked_relation=Relations.LOCATIONS_EXPANDED,
linked_relation_linking_column="id",
columns_to_retrieve=["state_name", "county_name", "locality_name", "id"],
alias_mappings={
"state_name": "state",
"county_name": "county",
"locality_name": "locality",
"id": "location_id",
},
build_metadata=True,
)

DataRequestIssueInfo = namedtuple(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class SearchRequestSchema(Schema):
)



class SearchResultsInnerSchema(Schema):
id = fields.Int(
required=True,
Expand Down Expand Up @@ -158,25 +157,25 @@ class SearchResponseSchema(Schema):


class FollowSearchResponseSchema(Schema):
state = fields.Str(
state_name = fields.Str(
required=True,
metadata=get_json_metadata("The state of the search."),
)
county = fields.Str(
county_name = fields.Str(
required=False,
allow_none=True,
metadata=get_json_metadata(
"The county of the search. If empty, all counties for the given state will be searched."
),
)
locality = fields.Str(
locality_name = fields.Str(
required=False,
allow_none=True,
metadata=get_json_metadata(
"The locality of the search. If empty, all localities for the given county will be searched."
),
)
location_id = fields.Int(
id = fields.Int(
required=True,
metadata=get_json_metadata("The location ID of the search."),
)
Expand Down
20 changes: 13 additions & 7 deletions tests/integration/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
TEST_COUNTY = "Allegheny"
TEST_LOCALITY = "Pittsburgh"


@dataclass
class SearchTestSetup:
tdc: TestDataCreatorFlask
location_id: int
tus: TestUserSetup


@pytest.fixture
def search_test_setup(test_data_creator_flask: TestDataCreatorFlask):
tdc = test_data_creator_flask
Expand All @@ -49,10 +51,12 @@ def search_test_setup(test_data_creator_flask: TestDataCreatorFlask):
"state_name": TEST_STATE,
"county_name": TEST_COUNTY,
"locality_name": TEST_LOCALITY,
}),
}
),
tus=tdc.standard_user(),
)


def test_search_get(search_test_setup: SearchTestSetup):
sts = search_test_setup
tdc = sts.tdc
Expand Down Expand Up @@ -252,12 +256,14 @@ def follow_extant_location(
tus=tus_1,
expected_json_content={
"metadata": {"count": 1},
"data": [{
"state": TEST_STATE,
"county": TEST_COUNTY,
"locality": TEST_LOCALITY,
"location_id": sts.location_id
}],
"data": [
{
"state_name": TEST_STATE,
"county_name": TEST_COUNTY,
"locality_name": TEST_LOCALITY,
"id": sts.location_id,
}
],
"message": "Followed searches found.",
},
)
Expand Down
18 changes: 15 additions & 3 deletions tests/integration/test_user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ def test_user_profile_get_by_id(test_data_creator_flask: TestDataCreatorFlask):
# Create a recent search
tdc.request_validator.search(
headers=tus.api_authorization_header,
location_id=tdc.db_client.get_location_id(where_mappings={"state_name": "Pennsylvania", "county_name": None, "locality_name": None}),
location_id=tdc.db_client.get_location_id(
where_mappings={
"state_name": "Pennsylvania",
"county_name": None,
"locality_name": None,
}
),
)

# Have the user follow a search
tdc.request_validator.follow_search(
headers=tus.jwt_authorization_header,
location_id=tdc.db_client.get_location_id(where_mappings={"state_name": "California", "county_name": None, "locality_name": None}),
location_id=tdc.db_client.get_location_id(
where_mappings={
"state_name": "California",
"county_name": None,
"locality_name": None,
}
),
)

# Have the user create a data request
Expand All @@ -77,7 +89,7 @@ def test_user_profile_get_by_id(test_data_creator_flask: TestDataCreatorFlask):
assert data["email"] == tus.user_info.email
assert data["external_accounts"]["github"] == str(github_user_id)
assert data["recent_searches"]["data"][0]["state_iso"] == "PA"
assert data["followed_searches"]["data"][0]["state"] == "California"
assert data["followed_searches"]["data"][0]["state_name"] == "California"
assert data["data_requests"]["data"][0]["id"] == int(data_request_id)
assert data["permissions"] == [PermissionsEnum.READ_ALL_USER_INFO.value]

Expand Down
53 changes: 25 additions & 28 deletions tests/test_database_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,21 +577,21 @@ def test_get_typeahead_locations(live_database_client: DatabaseClient):

assert results[0]["display_name"] == "Xylodammerung"
assert results[0]["type"] == "Locality"
assert results[0]["state"] == "Xylonsylvania"
assert results[0]["county"] == "Arxylodon"
assert results[0]["locality"] == "Xylodammerung"
assert results[0]["state_name"] == "Xylonsylvania"
assert results[0]["county_name"] == "Arxylodon"
assert results[0]["locality_name"] == "Xylodammerung"

assert results[1]["display_name"] == "Xylonsylvania"
assert results[1]["type"] == "State"
assert results[1]["state"] == "Xylonsylvania"
assert results[1]["county"] is None
assert results[1]["locality"] is None
assert results[1]["state_name"] == "Xylonsylvania"
assert results[1]["county_name"] is None
assert results[1]["locality_name"] is None

assert results[2]["display_name"] == "Arxylodon"
assert results[2]["type"] == "County"
assert results[2]["state"] == "Xylonsylvania"
assert results[2]["county"] == "Arxylodon"
assert results[2]["locality"] is None
assert results[2]["state_name"] == "Xylonsylvania"
assert results[2]["county_name"] == "Arxylodon"
assert results[2]["locality_name"] is None


def test_get_typeahead_agencies(live_database_client):
Expand All @@ -603,9 +603,9 @@ def test_get_typeahead_agencies(live_database_client):
assert len(results) > 0
assert results[0]["display_name"] == "Xylodammerung Police Agency"
assert results[0]["jurisdiction_type"] == "state"
assert results[0]["state"] == "XY"
assert results[0]["county"] == "Arxylodon"
assert results[0]["locality"] == "Xylodammerung"
assert results[0]["state_iso"] == "XY"
assert results[0]["county_name"] == "Arxylodon"
assert results[0]["locality_name"] == "Xylodammerung"


def test_search_with_location_and_record_types_real_data(live_database_client):
Expand All @@ -626,7 +626,7 @@ def test_search_with_location_and_record_types_real_data(live_database_client):
county_parameter = "Allegheny"
locality_parameter = "Pittsburgh"

def search(state, record_categories = None, county = None, locality = None):
def search(state, record_categories=None, county=None, locality=None):
location_id = live_database_client.get_location_id(
where_mappings={
"state_name": state,
Expand All @@ -650,14 +650,8 @@ def search(state, record_categories = None, county = None, locality = None):
locality=locality_parameter,
)
)
S = len(
search(state=state_parameter)
)
SR = len(
search(
state=state_parameter, record_categories=[record_type_parameter]
)
)
S = len(search(state=state_parameter))
SR = len(search(state=state_parameter, record_categories=[record_type_parameter]))
SRC = len(
search(
state=state_parameter,
Expand All @@ -670,11 +664,7 @@ def search(state, record_categories = None, county = None, locality = None):
state=state_parameter, county=county_parameter, locality=locality_parameter
)
)
SC = len(
search(
state=state_parameter, county=county_parameter
)
)
SC = len(search(state=state_parameter, county=county_parameter))

assert SRLC > 0
assert SRLC < SRC
Expand All @@ -687,7 +677,11 @@ def test_search_with_location_and_record_types_real_data_multiple_records(
live_database_client,
):
location_id = live_database_client.get_location_id(
where_mappings={"state_name": "Pennsylvania", "county_name": None, "locality_name": None}
where_mappings={
"state_name": "Pennsylvania",
"county_name": None,
"locality_name": None,
}
)
record_categories = []
last_count = 0
Expand All @@ -702,7 +696,9 @@ def test_search_with_location_and_record_types_real_data_multiple_records(
results = live_database_client.search_with_location_and_record_type(
location_id=location_id, record_categories=record_categories
)
assert len(results) > last_count, f"{record_category} failed (total record_categories: {len(record_categories)})"
assert (
len(results) > last_count
), f"{record_category} failed (total record_categories: {len(record_categories)})"
last_count = len(results)

# Finally, check that all record_types is equivalent to no record types in terms of number of results
Expand Down Expand Up @@ -1061,6 +1057,7 @@ def test_get_linked_rows(
"id",
"name",
],
build_metadata=True,
)

assert results["metadata"]["count"] == len(results["data"]) > 0
Expand Down

0 comments on commit 13144a4

Please sign in to comment.