Пример #1
0
 def put(self, request, language, pk, format=None):
     area = self.get_object(pk)
     serializer = AreaSerializer(area, data=request.data, language=language, partial=True)
     if serializer.is_valid():
         serializer.save()
         data = { "results": serializer.data }
         return Response(data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def test_update_area_link(self):
     data = {"links": [{"id": "ed8a52d8-5503-45aa-a2ad-9931461172d2", "note": "just a link"}]}
     area = Area.objects.untranslated().get(id="640c0f1d-2305-4d17-97fe-6aa59f079cc4")
     serializer = AreaSerializer(area, data=data, language="en", partial=True)
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save()
     link = area.links.language("en").get(id="ed8a52d8-5503-45aa-a2ad-9931461172d2")
     self.assertEqual(link.note, "just a link")
Пример #3
0
 def test_create_area_link(self):
     data = {"classification": "city", "links": [{"url": "http://www.google.com", "note": "just a link"}]}
     area = Area.objects.untranslated().get(id="640c0f1d-2305-4d17-97fe-6aa59f079cc4")
     serializer = AreaSerializer(area, data=data, language="en", partial=True)
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save()
     link = area.links.language("en").get(url="http://www.google.com")
     self.assertEqual(link.note, "just a link")
Пример #4
0
 def test_update_area(self):
     data = {"classification": "city"}
     area = Area.objects.untranslated().get(id="640c0f1d-2305-4d17-97fe-6aa59f079cc4")
     serializer = AreaSerializer(area, data=data, language="en", partial=True)
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save()
     area = Area.objects.language("en").get(id="640c0f1d-2305-4d17-97fe-6aa59f079cc4")
     self.assertEqual(area.classification, "city")
Пример #5
0
    def test_create_area(self):
        data = {"name": "timbuktu"}
        serializer = AreaSerializer(data=data, language="en")
        serializer.is_valid()
        self.assertEqual(serializer.errors, {})

        serializer.save()
        area = Area.objects.language("en").get(name="timbuktu")
        # Just to proof that it save into database
        self.assertEqual(area.name, "timbuktu")
Пример #6
0
 def test_create_area(self):
     data = {
         "name":"petaling jaya",
         "classification": "town"
     }
     serializer = AreaSerializer(data=data, language="en")
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save()
     area = Area.objects.language("en").get(name="petaling jaya")
     self.assertEqual(area.classification, "town")
Пример #7
0
 def test_update_area_translated(self):
     data = {
         "name": "Subang Jaya",
         "classification": "bandar"
     }
     area = Area.objects.untranslated().get(id="b0c2dbaba8ea476f91db1e3c2320dcb7")
     serializer = AreaSerializer(area, data=data, language="ms", partial=True)
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save()
     area = Area.objects.language("ms").get(id="b0c2dbaba8ea476f91db1e3c2320dcb7")
     self.assertEqual(area.classification, "bandar")
Пример #8
0
    def test_update_area(self):
        data = {
            "identifier": "P21"
        }
        area = Area.objects.untranslated().get(id="b0c2dbaba8ea476f91db1e3c2320dcb7")
        serializer = AreaSerializer(area, data=data, language="en", partial=True)
        serializer.is_valid()
        self.assertEqual(serializer.errors, {})
        serializer.save()
        area = Area.objects.language("en").get(id="b0c2dbaba8ea476f91db1e3c2320dcb7")

        self.assertEqual(area.identifier, "P21")
Пример #9
0
 def post(self, request, language, format=None):
     serializer = AreaSerializer(data=request.data, language=language)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST)