class GeohashFieldTestCase(TestCase): def setUp(self): self.shop = CoffeeShop(name='The Marwood') def get_shop(self): return CoffeeShop.objects.get() def test_basic_string_behaviour(self): self.shop.location = GEOHASH self.shop.save() shop = self.get_shop() self.assertEqual(shop.location, GEOHASH) def test_queryset_cloning(self): self.shop.location = GEOHASH self.shop.save() shop = CoffeeShop.objects.all().values('location').distinct().first() self.assertEqual(shop['location'], GEOHASH) def test_type_conversion_to_database(self): self.shop.location = (LAT, LON) self.shop.save() shop = self.get_shop() self.assertIsInstance(shop.location, Geohash) self.assertEqual(shop.location, GEOHASH) def test_type_conversion_from_database(self): self.shop.location = (LAT, LON) self.shop.save() shop = self.get_shop() geohash = shop.location self.assertAlmostEqual(geohash.point.latitude, LAT, places=5) self.assertAlmostEqual(geohash.point.longitude, LON, places=5) # Various different access methods self.assertAlmostEqual(geohash.latitude, LAT, places=5) self.assertAlmostEqual(geohash.longitude, LON, places=5) self.assertAlmostEqual(geohash.as_dict()['latitude'], LAT, places=5) self.assertAlmostEqual(geohash.as_dict()['longitude'], LON, places=5) self.assertAlmostEqual(geohash.as_tuple()[0], LAT, places=5) self.assertAlmostEqual(geohash.as_tuple()[1], LON, places=5)
def setUp(self): self.shop = CoffeeShop(name='The Marwood')