示例#1
0
    def test_patch_detail_dont_update_related_without_permission(self):
        """
        When fields are excluded the value of the field should not be set to a
        default value if updated by bmga.
        """
        resource = NoteResource()
        note = Note.objects.create(author_id=1)
        user = User.objects.get(pk=1)

        self.assertEqual(user.password, 'this_is_not_a_valid_password_string')

        request = MockRequest()
        request.GET = {'format': 'json'}
        request.method = 'PATCH'
        request.path = "/v1/note/%(pk)s/" % {'pk': note.pk}

        data = {
            'author': {
                'id': 1,
                'username': '******',
                'email': '*****@*****.**',
            }
        }

        request.set_body(json.dumps(data))

        resp = resource.patch_detail(request, pk=note.pk)

        self.assertEqual(resp.status_code, 202)

        user2 = User.objects.get(pk=1)

        self.assertEqual(user2.email, '*****@*****.**')
        self.assertEqual(user2.password, 'this_is_not_a_valid_password_string')
示例#2
0
    def test_patch_detail_dont_update_related_without_permission(self):
        """
        When fields are excluded the value of the field should not be set to a
        default value if updated by tastypie.
        """
        resource = NoteResource()
        note = Note.objects.create(author_id=1)
        user = User.objects.get(pk=1)

        self.assertEqual(user.password, 'this_is_not_a_valid_password_string')

        request = MockRequest()
        request.GET = {'format': 'json'}
        request.method = 'PATCH'
        request.path = "/v1/note/%(pk)s/" % {'pk': note.pk}

        data = {
            'author': {
                'id': 1,
                'username': '******',
                'email': '*****@*****.**',
            }
        }

        request.set_body(json.dumps(data))

        resp = resource.patch_detail(request, pk=note.pk)

        self.assertEqual(resp.status_code, 202)

        user2 = User.objects.get(pk=1)

        self.assertEqual(user2.email, '*****@*****.**')
        self.assertEqual(user2.password, 'this_is_not_a_valid_password_string')
示例#3
0
    def test_patch_to_one_with_excluded_fields(self):
        """When fields are excluded the value of the field should not be set to a default value if updated by tastypie"""
        resource = NoteResource()
        note = Note.objects.create(author_id=1)
        user = User.objects.get(pk=1)
        self.assertEqual(user.password, 'this_is_not_a_valid_password_string')
        request = HttpRequest()
        request.GET = {'format': 'json'}
        request.method = 'PATCH'
        request.path = "/v1/note/%(pk)s/" % {'pk': note.pk}
        request._read_started = False

        data = {
            'author': {
                'id': 1,
                'username': '******',
                'email': '*****@*****.**',
            }
        }

        setattr(request, self.body_attr, json.dumps(data))
        resp = resource.patch_detail(request, pk=note.pk)
        user2 = User.objects.get(pk=1)
        self.assertEqual(user2.email, '*****@*****.**')
        self.assertEqual(user2.password, 'this_is_not_a_valid_password_string')
示例#4
0
    def test_patch_to_one_with_excluded_fields(self):
        """When fields are excluded the value of the field should not be set to a default value if updated by tastypie"""
        resource = NoteResource()
        note = Note.objects.create(author_id=1)
        user = User.objects.get(pk=1)
        self.assertEqual(user.password, "this_is_not_a_valid_password_string")
        request = HttpRequest()
        request.GET = {"format": "json"}
        request.method = "PATCH"
        request.path = "/v1/note/%(pk)s/" % {"pk": note.pk}
        request._read_started = False

        data = {"author": {"id": 1, "username": "******", "email": "*****@*****.**"}}

        setattr(request, self.body_attr, json.dumps(data))
        resp = resource.patch_detail(request, pk=note.pk)
        user2 = User.objects.get(pk=1)
        self.assertEqual(user2.email, "*****@*****.**")
        self.assertEqual(user2.password, "this_is_not_a_valid_password_string")