Beispiel #1
0
 def test_can_load_page(self):
     mp1 = MapPoint(lat=43.0831, lon=73.7846)
     mp1.save()
     response = self.client.get('/api-count/', {'min_lat': 12.12, 'max_lat': 108.00, 'dataset': '1,2',
                                                'unit': 'km', 'state': 'NY'})
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, str(mp1))
Beispiel #2
0
 def test_can_create_new_mappoint(self):
     original_count = MapPoint.objects.all().count()
     point = MapPoint(lat=42.7302, lon=73.6788, city='Troy', state='NY')
     point.save()
     sleep(1)
     self.assertEqual(MapPoint.objects.all().count(), original_count + 1)
     self.assertEqual(point.lat, Decimal(42.7302))
     status = point.geocode()['status']
     self.assertTrue(status == 'OK' or status == 'OVER_QUERY_LIMIT'
                     or status == 'ZERO_RESULTS')
Beispiel #3
0
 def test_can_load_page(self):
     self.user = User.objects.create_superuser(username='******',
                                               email='*****@*****.**',
                                               password='******')
     self.assertTrue(self.client.login(username='******', password='******'))
     mp1 = MapPoint(lat=43.0831, lon=73.7846)
     mp1.save()
     response = self.client.get('/api-dist2/', {'min_lat': 12.12, 'max_lat': 108.00, 'dataset': '1,2', 'unit': 'km'})
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, str(mp1))
     response = self.client.get('/api-dist2/', {'min_lat': 12.12, 'max_lat': 108.00, 'dataset': '1,2', 'unit': ['km', 'm']})
     self.assertEqual(response.status_code, 400)
Beispiel #4
0
    def setUp(self):
        ds = Dataset.objects.get(pk=3)
        self.mp = MapPoint.objects.get(pk=1)
        self.mp.dataset = ds
        self.mp.point = Point(5, 23)
        MapPoint(lat=23.41, lon=98.0, dataset=ds, point=Point(5, 23)).save()
        tag1 = Tag(dataset=ds, tag='tag1', approved=True, count=1)
        tag1.save()
        tag2 = Tag(dataset=ds, tag='tag2', approved=True, count=1)
        tag2.save()
        tagindiv1 = TagIndiv(tag=tag1, mapelement=self.mp)
        tagindiv1.save()
        tagindiv2 = TagIndiv(tag=tag2, mapelement=self.mp)
        tagindiv2.save()
        p1 = GEOSGeometry(
            "SRID=4326;POLYGON ((5 23.00902982868961, 5.004877257506506 23.00781998654152, 5.00844745207902 23.00451469036915, 5.009753953024734 22.99999969967893, 5.008446890194161 22.99548485657674, 5.004876695621637 22.99217985558042, 5 22.99097016102037, 4.995123304378363 22.99217985558042, 4.991553109805839 22.99548485657674, 4.990246046975266 22.99999969967893, 4.99155254792098 23.00451469036915, 4.995122742493493 23.00781998654153, 5 23.00902982868961))"
        )
        p2 = GEOSGeometry(
            "SRID=4326;POLYGON ((5 23.02708945518625, 5.014633459242311 23.02345948568706, 5.025344042308789 23.01354271143227, 5.029261858728946 22.99999729711045, 5.025338985345226 22.98645321108062, 5.014628402277986 22.97653909341024, 5 22.97291045220348, 4.985371597722013 22.97653909341024, 4.974661014654773 22.98645321108062, 4.970738141271054 22.99999729711045, 4.974655957691211 23.01354271143227, 4.985366540757689 23.02345948568706, 5 23.02708945518625))"
        )
        p3 = GEOSGeometry(
            "SRID=4326;POLYGON ((5 23.0451490404854, 5.024391911722986 23.03909835241012, 5.042242881329157 23.02256891874033, 5.048769763397385 22.99999249197385, 5.042228834209113 22.97741975490609, 5.024377864597061 22.96089770063709, 5 22.95485070226389, 4.975622135402939 22.96089770063709, 4.957771165790887 22.97741975490609, 4.951230236602615 22.99999249197385, 4.957757118670842 23.02256891874033, 4.975608088277014 23.03909835241012, 5 23.0451490404854))"
        )
        mpoly1 = MultiPolygon(fromstr(str(p1)))
        polygon1 = MapPolygon(lat='50',
                              lon='22',
                              field1=1.0,
                              field2=2.0,
                              mpoly=mpoly1,
                              dataset=ds,
                              remote_id=10)
        polygon1.save()
        mpoly2 = MultiPolygon(fromstr(str(p2)))
        polygon2 = MapPolygon(lat='12',
                              lon='17',
                              field1=1.0,
                              field2=2.0,
                              mpoly=mpoly2,
                              dataset=ds,
                              remote_id=9)
        polygon2.save()
        mpoly3 = MultiPolygon(fromstr(str(p3)))
        polygon3 = MapPolygon(lat='23',
                              lon='27',
                              field1=1.0,
                              field2=2.0,
                              mpoly=mpoly3,
                              dataset=ds,
                              remote_id=9)
        polygon3.save()

        self.request = HttpRequest()
        qdict = QueryDict('', mutable=True)
        qdict.update({'year': '2010'})
        qdict.update({'year': '2014'})
        qdict.update({'year': '2016'})
        qdict.update({'unit': 'km'})
        self.request.GET = qdict
        self.serializer = AnalyzeAreaSerializer(
            context={'request': self.request})
Beispiel #5
0
 def test_contains_mappoint(self):
     mp1 = MapPoint(lat=43.0831, lon=73.7846)
     mp1.save()
     mp2 = MapPoint(lat=20.1515, lon=25.2523)
     mp2.save()
     response = self.client.get('/api-dist/', {'min_lat': 12.12, 'max_lat': 108.00, 'dataset': '1,2', 'unit': 'km'})
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, str(mp1))
     response = self.client.get('/around-point/%d/' % mp2.id)
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, str(mp2))
Beispiel #6
0
 def test_can_create_datapoint(self):
     user = User.objects.create_superuser(username='******',
                                          email='*****@*****.**',
                                          password='******')
     mappoint = MapPoint(lat=43.0831, lon=73.7846)
     mappoint.save()
     sensor = Sensor.objects.create(name='test',
                                    user=user,
                                    mappoint=mappoint)
     sensor.save()
     self.assertEqual(str(sensor), 'id: test')
     dp1 = DataPoint(value=25)
     dp1.save()
     sensor.datapoints.add(dp1)
     dp2 = DataPoint(value=20)
     dp2.save()
     sensor.datapoints.add(dp2)
     self.assertEqual(sensor.mappoint.lat, 43.0831)
     self.assertEqual(sensor.datapoints.filter(value=20).count(), 1)
     self.assertEqual(str(dp1), 'value: 25 time: None')