예제 #1
0
    def test_placename_reject(self):
        # Must be logged in to submit a place.
        self.assertTrue(
            self.client.login(username="******", password="******"))

        # Check we're logged in
        response = self.client.get("/api/user/auth/")
        self.assertEqual(response.json()["is_authenticated"], True)

        placename = PlaceName()
        placename.name = "test place"
        placename.creator = self.user
        placename.community = self.community
        placename.language = self.language1
        placename.save()

        created_id = placename.id

        # now update it.
        response = self.client.patch(
            "/api/placename/{}/reject/".format(created_id),
            {"status_reason": "test reason status"},
            format="json",
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        place = PlaceName.objects.get(pk=created_id)
        self.assertEqual(place.status, PlaceName.REJECTED)
예제 #2
0
    def handle(self, *args, **options):

        for rec in json.loads(
                open('./fixtures/pois.json').read())['markers']['marker']:
            n = PlaceName(point=Point(float(rec['_loc_x']),
                                      float(rec['_loc_y'])),
                          name=rec['_name'],
                          kind='poi')
            n.save()
    def test_media_post_with_placename(self):
        """
		Ensure media API POST method API works
		"""
        # Must be logged in to submit a place.
        self.assertTrue(
            self.client.login(username="******", password="******"))

        # Check we're logged in
        response = self.client.get("/api/user/auth/")
        self.assertEqual(response.json()["is_authenticated"], True)

        placename = PlaceName()
        placename.name = "test place"
        placename.other_names = "string"
        placename.common_name = "string"
        placename.community_only = True
        placename.description = "string"
        placename.community = self.community1
        placename.language = self.language1
        placename.save()

        response = self.client.post(
            "/api/media/",
            {
                "name": "Test media 001",
                "file_type": "image",
                "url": "https://google.com",
                "status": Media.UNVERIFIED,
                "placename": placename.id,
                "community_only": True,
            },
            format="json",
        )
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        created_id = response.json()["id"]

        media = Media.objects.get(pk=created_id)
        self.assertEqual(media.name, "Test media 001")
        self.assertEqual(media.file_type, "image")
        self.assertEqual(media.url, "https://google.com")
        self.assertEqual(media.status, Media.UNVERIFIED)
        self.assertEqual(media.placename.id, placename.id)
    def test_placename_flag(self):
        placename = PlaceName()
        placename.name = "test place"
        placename.community = self.community
        placename.language = self.language1
        placename.save()

        created_id = placename.id

        # now update it.
        response = self.client.patch(
            "/api/placename/{}/flag/".format(created_id),
            {"status_reason": "test reason status"},
            format="json",
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        place = PlaceName.objects.get(pk=created_id)
        self.assertEqual(place.status, PlaceName.FLAGGED)
예제 #5
0
    def create_placename(self, rec):
        # avoid duplicates on remote data source.
        try:
            node_placename = PlaceName.objects.get(
                name=rec["properties"]["name"])
            # print('Updating %s' % rec["properties"]["name"])
        except PlaceName.DoesNotExist:
            node_placename = PlaceName(name=rec["properties"]["name"])
            print('Creating %s' % rec["properties"]["name"])

        # Geometry map point with latitude and longitude
        node_placename.geom = Point(
            float(rec["geometry"]["coordinates"][0]),  # latitude
            float(rec["geometry"]["coordinates"][1]),
        ) if rec["geometry"] else None
        node_placename.description = rec["properties"]["details"]
        node_placename.kind = rec["properties"]["type"]

        node_placename.save()

        return node_placename