예제 #1
0
 def test_update_othername(self):
     data = {"family_name": "jambul"}
     person = Person.objects.language("en").get(id="8497ba86-7485-42d2-9596-2ab14520f1f4")
     other_name = person.other_names.language("en").get(id="cf93e73f-91b6-4fad-bf76-0782c80297a8")
     serializer = OtherNameSerializer(other_name, data=data, language="en", partial=True)
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     serializer.save(content_object=person)
     other_name_ = OtherName.objects.language("en").get(id="cf93e73f-91b6-4fad-bf76-0782c80297a8")
     self.assertEqual(other_name_.family_name, "jambul")
예제 #2
0
 def test_create_othername_without_parent(self):
     data = {
         "name": "jane",
         "family_name": "jambul",
         "given_name": "test person",
         "start_date": "1950-01-01",
         "end_date": "2010-01-01",
     }
     person = Person.objects.language("en").get(id="ab1a5788e5bae955c048748fa6af0e97")
     serializer = OtherNameSerializer(data=data, language="en")
     serializer.is_valid()
     self.assertEqual(serializer.errors, {})
     with self.assertRaises(ContentObjectNotAvailable):
         serializer.save()
예제 #3
0
파일: post.py 프로젝트: leowmjw/popit_ng
 def put(self, request, language, parent_pk, pk, format=None):
     other_labels = self.get_object(parent_pk, pk)
     serializer = OtherNameSerializer(other_labels, data=request.data, language=language)
     if serializer.is_valid():
         serializer.save()
         data = { "results": serializer.data }
         return Response(data, status.HTTP_200_OK)
     return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)
예제 #4
0
    def test_create_othername(self):
        data = {
            "name": "jane",
            "family_name": "jambul",
            "given_name": "test person",
            "start_date": "1950-01-01",
            "end_date": "2010-01-01",
        }
        person = Person.objects.language("en").get(id="ab1a5788e5bae955c048748fa6af0e97")
        serializer = OtherNameSerializer(data=data, language="en")
        serializer.is_valid()
        self.assertEqual(serializer.errors, {})
        serializer.save(content_object=person)

        person_ = Person.objects.language("en").get(id="ab1a5788e5bae955c048748fa6af0e97")
        other_name = person_.other_names.language("en").get(name="jane")
        self.assertEqual(other_name.given_name, "test person")
예제 #5
0
파일: post.py 프로젝트: leowmjw/popit_ng
 def post(self, request, language, parent_pk):
     post = Post.objects.untranslated().get(id=parent_pk)
     serializer = OtherNameSerializer(data=request.data, language=language)
     if serializer.is_valid():
         serializer.save(content_object=post)
         data = { "results": serializer.data }
         return Response(data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)