Exemple #1
0
    def test_update_location_post(self):
        # create some test data
        l = Location(name="awesome")
        l.save()

        responses.add(responses.GET,
                      self.url_re,
                      body=GEOCODE_BODY,
                      status=200,
                      content_type='application/json')

        factory = APIRequestFactory()

        request = factory.put('/api/v1/location/' + str(l.id) + '/', {
            'address1': 'test',
            'city': 'Palo Alto',
            'state': 'CA',
            'zip': '94043'
        },
                              format='json')
        resp = UpdateLocation.as_view()(request, id=str(l.id))
        self.assertEquals(resp.status_code, status.HTTP_200_OK)

        new_l = Location.objects.get(id=l.id)
        self.assertEquals(new_l.address1, 'test')
        self.assertEquals(new_l.points, {
            'coordinates': [-122.0854212, 37.4229181],
            'type': 'Point'
        })
Exemple #2
0
    def test_get_point_location_with_serializer(self):
        lt = LocationType(name="btest_loc_type2", icon="star.png")
        lt.save()
        l = Location(name="test", points=[1, 2], location_type=lt)
        l.save()
        self.assertEquals(l.points, [1, 2])

        serializer = LocationSerializer(l)
        lt.delete()
        l.delete()
        self.assertEquals(serializer.data["points"], [1, 2])
        self.assertEquals(serializer.data["location_type"]['name'],
                          'btest_loc_type2')
        self.assertEquals(serializer.data["location_type"]['icon'], 'star.png')
Exemple #3
0
    def test_creating_location(self):
        try:
            loc = Location.objects.get(name='test')
            loc.delete()
        except:
            pass

            
        location = Location(name="test", address1="6600 Kalanianaole Hwy",zip="96825",city="Honolulu",
                                    state="HI",phone="039485493",location_type=self.location_type)
        location.save()
        self.assertEqual(location,
                         Location.objects.get(name='test'))
        location.delete()
Exemple #4
0
 def test_make_obj_return_updated_with_coords(self):
     with patch('mongoengine.Document.save') as mock_save:
         with patch(
                 'maps.data_import.admin_view.SettingsImportSystemView.make_objects'
         ) as mock_obj:
             mock_obj.return_value = [Location(name="test")]
             data = self.mock_NOTMK_json
             view = SettingsImportSystemView()
             rv = view.make_locations(data, {})
             self.assertTrue(mock_obj.called)
             self.assertEqual(
                 rv[0].points,
                 self.mock_NOTMK_json.get('features')[0].get(
                     'geometry').get('coordinates'))
Exemple #5
0
    def test_location_get_tags(self):
        for l in Location.objects.filter(name="loc-with-cat2"):
            l.delete()

        loc = Location(name="loc-with-cat2")
        loc.save()
        cat = Categories(name="food-test2", tagged=[loc])
        cat.save()
    
        self.assertIn(cat, loc.tags)
        self.assertEqual(1, len(loc.tags))


        loc.delete()
        cat.delete()
        
        pass
Exemple #6
0
 def upload_tmk_data(self, f):
     ''' Due to Ainbilities dependence on TMK 
         data it should get special treatment'''
     lt = LocationType.objects.get(name='TMK')
     for feature in f["features"]:
         try:
             location = Location()
             properties = feature["properties"]
             location.name = properties.get("MajorOwner", "NoMajorOwner")+unicode(properties.get("TMK"))
             location.points = feature.get("geometry").get("coordinates")
             location.location_type = lt
             location.save()
         except (mongoengine.ValidationError, mongoengine.OperationError) as e:
             if e == mongoengine.OperationError:
                 print ('bad coordinates')
             elif isinstance(e, mongoengine.errors.NotUniqueError):
                 pass
                 #print("location already loaded skipping")
             else:
                 print(e)
                 print ('invalid geojson, maybe, check error above')
                 print (feature)
Exemple #7
0
 def test_create_polygon_location(self):
     l = Location(name="test", points=[[[1, 2], [2, 3], [4, 5], [1, 2]]])
     l.save()
     self.assertEquals(l.points, [[[1, 2], [2, 3], [4, 5], [1, 2]]])
     l.delete()
Exemple #8
0
 def test_create_point_location(self):
     l = Location(name="test", points=[1, 2])
     l.save()
     self.assertEquals(l.points, [1, 2])
     self.assertEquals(l.name, "test")
     l.delete()
Exemple #9
0
    def setUp(self):
        for cat in Categories.objects.filter(name="test cat"):
            cat.delete()

        self.loc = Location(name="test_loc")
        self.loc.save()