def test__names_list__empty(self):
     """
     Tests LocationWrap.names_list with an empty adminnames
     """
     wrap = LocationWrap(location=None, weight=0, adminnames=None)
     expected = []
     actual = wrap.names_list()
     assert expected == actual
 def test__eq__fail_on_wrap(self):
     """
     Tests LocationWrap.__eq__ with two unequal wraps
     """
     l1 = LocationWrap('equal')
     l2 = 'i am a string and not a wrap'
     l1._weight = 8374
     l1.adminnames = [1, 2, 3, 4]
     assert l1 != l2
 def test__names_list__not_adminnames(self):
     """
     Tests LocationWrap.names_list with an adminnames that is not the right
     type
     """
     wrap = LocationWrap(location=None, weight=0, adminnames=1)
     expected = []
     actual = wrap.names_list()
     assert expected == actual
 def test__index_of_admin_name__0(self):
     """
     Tests LocationWrap.index_of_admin_name for countryname
     """
     NAME = 'banana'
     names = LocationAdminNames(countryname=NAME, admin4name='no')
     wrap = LocationWrap(location=None, weight=0, adminnames=names)
     expected = 0
     actual = wrap.index_of_admin_name(NAME)
     assert expected == actual
 def test__index_of_admin_name__1(self):
     """
     Tests LocationWrap.index_of_admin_name for admin1name
     """
     NAME = 'fruit'
     names = LocationAdminNames(countryname='banana', admin1name=NAME)
     wrap = LocationWrap(location=None, weight=0, adminnames=names)
     expected = 1
     actual = wrap.index_of_admin_name(NAME)
     assert expected == actual
 def test__increment_weight_on_match__0(self):
     """
     Tests LocationWrap.increment_weight_on_match with country match
     """
     NAME = 'orange'
     names = LocationAdminNames(countryname=NAME, admin4name='not')
     wrap = LocationWrap(location=None, weight=0, adminnames=names)
     actual = wrap.increment_weight_on_match(NAME)
     assert actual
     expected_weight = 1
     actual_weight = wrap._weight
     assert expected_weight == actual_weight
 def test__increment_weight_on_match__1(self):
     """
     Tests LocationWrap.increment_weight_on_match with admin1 match
     """
     NAME = 'orange'
     names = LocationAdminNames(countryname='not orange', admin4name=NAME)
     wrap = LocationWrap(location=None, weight=3, adminnames=names)
     actual = wrap.increment_weight_on_match(NAME)
     assert actual is True
     expected_weight = 4
     actual_weight = wrap._weight
     assert expected_weight == actual_weight
Exemple #8
0
def dbtest():
    """
    This is a hidden url route not available through website GUI.

    It serves as a test for developer's to make sure that their
    database and environment are up and running correctly.

    If the dev does not get an error message when louding this URL,
    then it can be assumed that the environment is working.
    """
    from app.models import Location, Feature
    from app.weighter import Weightifier
    from app.geolocator import LocationWrap
    weightifier = Weightifier()
    location = Location.query.filter_by(
        name='Phoenix', countrycode='US').order_by('id').first()
    feature = Feature.query.first()
    wrap = LocationWrap(location)
    codes = weightifier._get_admin_codes(wrap, 5)
    names = weightifier._get_admin_names(codes)
    # wrap.set_adminnames(names)
    return render_template('dbtest.html',
                           first_location=location,
                           admin_codes=codes,
                           admin_names=names,
                           first_feature=feature)
 def test__increment_weight_on_match__no_match(self):
     """
     Tests LocationWrap.increment_weight_on_match with no match
     """
     NAME = 'orange'
     names = LocationAdminNames(
         countryname='not orange',
         admin1name='banana',
         admin2name='strawberry',
         admin3name='carrot',
         admin4name='apple')
     wrap = LocationWrap(location=None, weight=3, adminnames=names)
     actual = wrap.increment_weight_on_match(NAME)
     assert not actual
     expected_weight = 3
     actual_weight = wrap._weight
     assert expected_weight == actual_weight
 def test__names_list__pass(self):
     """
     Tests LocationWrap.names_list with a populated adminnames
     """
     A1 = 'orange'
     A2 = 'banana'
     A3 = 'cranberry'
     A4 = 'peach'
     CO = 'carrot'
     names = LocationAdminNames(
         countryname=CO,
         admin1name=A1,
         admin2name=A2,
         admin3name=A3,
         admin4name=A4)
     wrap = LocationWrap(location=None, weight=0, adminnames=names)
     expected = [A4, A3, A2, A1, CO]
     actual = wrap.names_list()
     assert expected == actual
 def test__eq__fail_on_location(self):
     """
     Tests LocationWrap.__eq__ with two unequal wraps
     """
     l1 = LocationWrap('equal')
     l2 = LocationWrap('not equal')
     l1._weight = 8374
     l2._weight = 8374
     l1.adminnames = [1, 2, 3, 4]
     l2.adminnames = [1, 2, 3, 4]
     assert l1 != l2
    def test__increment_weight_on_match__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.increment_weight_on_match`
        """
        loc = Location('Phoenix', 82.546, 36.111, 'phx')
        locwrap = LocationWrap(loc)
        s1 = LocationAdminNames(
            countryname='Jang',
            admin1name='Bob',
            admin2name=None,
            admin3name=None,
            admin4name=None)
        locwrap.set_adminnames(s1)
        loc2 = Location('Denver', 18.546, 44.111, 'den')
        locwrap2 = LocationWrap(loc2)
        s2 = s1
        locwrap2.set_adminnames(s2)
        l1 = [locwrap, locwrap2]
        self.init(l1)
        self.hits.increment_weight_on_match('Phoenix')

        f1 = self.hits.max_weight
        assert f1 != 1
    def test_LocationItems(self):
        """
        Tests the "getter" functions for the locationwrapper
        """
        loc = Location('Phoenix', 82.546, 36.111, 'phx')
        locwrap = LocationWrap(loc)
        COUNTRY = 'Jang'
        A1 = 'Bob'
        A2 = '1'
        A3 = '2'
        A4 = '3'
        l1 = LocationAdminNames(
            countryname='Jang',
            admin1name='Bob',
            admin2name='1',
            admin3name='2',
            admin4name='3')
        locwrap.set_adminnames(l1)
        locwrap._weight = 1

        assert locwrap.name() == 'Phoenix'
        assert locwrap.longitude() == 82.546
        assert locwrap.latitude() == 36.111
        assert locwrap.geonameid() == 'phx'
        assert locwrap.weight() == 1
        assert locwrap.countryname() == COUNTRY
        assert locwrap.admin1name() == A1
        assert locwrap.admin2name() == A2
        assert locwrap.admin3name() == A3
        assert locwrap.admin4name() == A4

        return