def test_locate_put(self):
        """
        PUTting to a locatedmodel's viewset with a GeoJSON FeatureCollection in
        the "locations" field should result in existing Location objects being
        updated, or (if necessary) new Location objects being created.
        """

        existing = self.instance.locations.all()
        eid1 = existing[0].id
        eid2 = existing[1].id

        form = {
            'name': 'Test 1 - Updated',
            'locations': json.dumps({
                "type": "FeatureCollection",
                "features": [
                    {
                        "type": "Feature",
                        "id": eid1,
                        "geometry": {
                            "type": "Point",
                            "coordinates": [-92, 47]
                        }
                    },
                    {
                        "type": "Feature",
                        "id": eid2,
                        "geometry": {
                            "type": "Point",
                            "coordinates": [-93, 48]
                        }
                    },
                    {
                        "type": "Feature",
                        "geometry": {
                            "type": "Point",
                            "coordinates": [-94, 49]
                        }
                    }
                ]
            })
        }

        # Test for expected response
        response = self.client.put(
            '/locatedmodels/%s.json' % self.instance.pk,
            form
        )
        self.assertEqual(
            response.status_code, status.HTTP_200_OK, response.data
        )
        self.instance = LocatedModel.objects.get(pk=self.instance.pk)
        self.assertEqual(self.instance.name, "Test 1 - Updated")
        self.assertIn("locations", response.data)
        self.assertEqual(len(response.data["locations"]), 3)

        # Double-check ORM models & geometry attributes
        locs = self.instance.locations.all()
        geom = locs.get(id=eid1).geometry
        self.assertEqual(geom.srid, 4326)
        self.assertEqual(geom.x, -92)
        self.assertEqual(geom.y, 47)

        newlocs = locs.exclude(id__in=[eid1, eid2]).all()
        self.assertEqual(len(newlocs), 1)
dataset/ETHPy150Open wq/wq.db/tests/test_locate.py/LocateRestTestCase.test_locate_put/original