How to use the uszipcode.search.Zipcode function in uszipcode

To help you get started, we’ve selected a few uszipcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MacHu-GWU / uszipcode-project / tests / search / test_search_by_coordinate.py View on Github external
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")
github MacHu-GWU / uszipcode-project / tests / search / test_search_by_value_range.py View on Github external
def test_by_range(self):
        test_cases = [
            (Zipcode.population.name, 10000, 50000),
            (Zipcode.population_density.name, 1000, 2000),
            (Zipcode.land_area_in_sqmi.name, 5, 10),
            (Zipcode.water_area_in_sqmi.name, 0.5, 1),
            (Zipcode.housing_units.name, 1000, 2000),
            (Zipcode.occupied_housing_units.name, 1000, 2000),
            (Zipcode.median_home_value.name, 200000, 400000),
            (Zipcode.median_household_income.name, 50000, 60000),
        ]
        for field, lower, upper in test_cases:
            func_name = "by_{}".format(field)
            query_func = getattr(self.search, func_name)
            z_list = query_func(lower, upper)
            assert len(z_list) > 0
            assert_descending_by(z_list, field)
github MacHu-GWU / uszipcode-project / tests / search / test_search_by_coordinate.py View on Github external
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)
github MacHu-GWU / uszipcode-project / tests / search / test_search_by_value_range.py View on Github external
def test_by_range(self):
        test_cases = [
            (Zipcode.population.name, 10000, 50000),
            (Zipcode.population_density.name, 1000, 2000),
            (Zipcode.land_area_in_sqmi.name, 5, 10),
            (Zipcode.water_area_in_sqmi.name, 0.5, 1),
            (Zipcode.housing_units.name, 1000, 2000),
            (Zipcode.occupied_housing_units.name, 1000, 2000),
            (Zipcode.median_home_value.name, 200000, 400000),
            (Zipcode.median_household_income.name, 50000, 60000),
        ]
        for field, lower, upper in test_cases:
            func_name = "by_{}".format(field)
            query_func = getattr(self.search, func_name)
            z_list = query_func(lower, upper)
            assert len(z_list) > 0
            assert_descending_by(z_list, field)