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)
Пример #2
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