Example #1
0
 def test_location_save_parses_input_ignores_lat_long_numeric(self):
     location = Location(user_input='41.2342, -76.2928')
     location.save()
     # Because latitude and longitude are now parsed and geocoded
     # from the client during form input instead, doing a save on the
     # location model does not populate the individual fields.
     self.assertEqual(location.latitude, None)
     self.assertEqual(location.longitude, None)
Example #2
0
 def test_location_save_parses_input_ignores_garbage_mixed(self):
     location = Location(user_input='aoeua87aoe349a8712b8qjk37a')
     location.save()
     self.assertIsNone(location.street)
     self.assertIsNone(location.city)
     self.assertIsNone(location.state)
     self.assertIsNone(location.postal_code)
     self.assertIsNone(location.latitude)
     self.assertIsNone(location.longitude)
Example #3
0
 def test_location_save_parses_input_ignores_garbage_numbers(self):
     location = Location(user_input='12873498712983749182')
     location.save()
     self.assertIsNone(location.street)
     self.assertIsNone(location.city)
     self.assertIsNone(location.state)
     self.assertIsNone(location.postal_code)
     self.assertIsNone(location.latitude)
     self.assertIsNone(location.longitude)
Example #4
0
 def test_location_save_parses_input_ignores_garbage_letters(self):
     location = Location(user_input='enutharocegusahosecsahkm')
     location.save()
     self.assertIsNone(location.street)
     self.assertIsNone(location.city)
     self.assertIsNone(location.state)
     self.assertIsNone(location.postal_code)
     self.assertIsNone(location.latitude)
     self.assertIsNone(location.longitude)
Example #5
0
 def clean_location(self):
     if not 'location' in self.cleaned_data:
         return None
     user_text = self.cleaned_data['location']
     # Look for a Location record with the user input text.
     locations = Location.objects.filter(user_input=user_text)
     if locations.count() > 0:
         # The first one is OK because any duplicates are equivalent.
         location = locations[0]
     else:
         # Create a new location record.
         location = Location(user_input=user_text)
         location.save()
     return location
 def _create_dummy_sighting(self, username):
     user = User.objects.get(username=username)
     year = datetime.now().year
     start = datetime(year, 1, 1, 00, 00)
     end = datetime(year, 12, 31, 23, 59)
     created = self._random_datetime(start, end)
     identification = 'Acer saccharum'
     location = Location(user_input='Boston, Ma.')
     location.latitude = 41.73 + random.uniform(-0.1, 0.1)
     location.longitude = 71.43 + random.uniform(-0.1, 0.1)
     location.save()
     self.stdout.write('_create_dummy_sighting: %s, %s, %s, %s' %
                       (user, created, identification, location))
     sighting = Sighting(user=user,
                         created=created,
                         identification=identification,
                         location=location)
     sighting.save()
Example #7
0
 def test_location_save_parses_input_address_city_state(self):
     location = Location(user_input='180 Hemenway Road, Framingham, MA')
     location.save()
     self.assertEqual(location.street, '180 Hemenway Road')
     self.assertEqual(location.city, 'Framingham')
     self.assertEqual(location.state, 'MA')
Example #8
0
 def test_location_save_parses_input_city_state(self):
     location = Location(user_input='Framingham, MA')
     location.save()
     self.assertEqual(location.city, 'Framingham')
     self.assertEqual(location.state, 'MA')