Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_resolve_sort_by(self):
with raises(ValueError):
self.search._resolve_sort_by(
"InValid Field", flag_radius_query=True)
with raises(ValueError):
self.search._resolve_sort_by(
"InValid Field", flag_radius_query=False)
assert self.search._resolve_sort_by(
Zipcode.zipcode, flag_radius_query=True) == Zipcode.zipcode.name
assert self.search._resolve_sort_by(
Zipcode.population, flag_radius_query=True) == Zipcode.population.name
assert self.search._resolve_sort_by(
Zipcode.zipcode, flag_radius_query=False) == Zipcode.zipcode.name
assert self.search._resolve_sort_by(
Zipcode.population, flag_radius_query=False) == Zipcode.population.name
assert self.search._resolve_sort_by(
None, flag_radius_query=True) == SORT_BY_DIST
assert self.search._resolve_sort_by(
None, flag_radius_query=False) == None
assert self.search._resolve_sort_by(
SORT_BY_DIST, flag_radius_query=True) == SORT_BY_DIST
with raises(ValueError):
self.search._resolve_sort_by(SORT_BY_DIST, flag_radius_query=False)
dist_array = [z.dist_from(lat, lng) for z in res2]
assert_descending(dist_array)
# returns everything when `returns = 0`
res3 = self.search.by_coordinates(lat, lng, ascending=True, returns=0)
assert len(res3) > len(res1)
res4 = self.search.by_coordinates(lat, lng, ascending=False, returns=0)
assert len(res4) > len(res1)
# sort by other field
res5 = self.search.by_coordinates(
lat, lng, radius=5, sort_by=Zipcode.zipcode.name)
for z in res5:
assert z.dist_from(lat, lng) <= 5
assert_ascending_by(res5, Zipcode.zipcode.name)
# when no zipcode matching criterion, return empty list
# Use Eiffel Tower in Paris
lat, lng = 48.858388, 2.294581
res6 = self.search.by_coordinates(lat, lng)
assert len(res6) == 0
assert_ascending(dist_array)
res2 = self.search.by_coordinates(lat, lng, ascending=False)
dist_array = [z.dist_from(lat, lng) for z in res2]
assert_descending(dist_array)
# returns everything when `returns = 0`
res3 = self.search.by_coordinates(lat, lng, ascending=True, returns=0)
assert len(res3) > len(res1)
res4 = self.search.by_coordinates(lat, lng, ascending=False, returns=0)
assert len(res4) > len(res1)
# sort by other field
res5 = self.search.by_coordinates(
lat, lng, radius=5, sort_by=Zipcode.zipcode.name)
for z in res5:
assert z.dist_from(lat, lng) <= 5
assert_ascending_by(res5, Zipcode.zipcode.name)
# when no zipcode matching criterion, return empty list
# Use Eiffel Tower in Paris
lat, lng = 48.858388, 2.294581
res6 = self.search.by_coordinates(lat, lng)
assert len(res6) == 0
def test_by_prefix(self):
z_list = self.search.by_prefix("100", ascending=True)
assert_ascending_by(z_list, Zipcode.zipcode.name)
z_list = self.search.by_prefix("100", ascending=False)
assert_descending_by(z_list, Zipcode.zipcode.name)
for z in z_list:
assert z.zipcode.startswith("100")