예제 #1
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")
예제 #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_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")
예제 #4
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")
예제 #5
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")
예제 #6
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")
예제 #7
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")
예제 #8
0
파일: misc.py 프로젝트: Sinar/popit_ng
 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)
예제 #9
0
파일: misc.py 프로젝트: Sinar/popit_ng
 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)