Beispiel #1
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')
Beispiel #2
0
    def test_patch_to_one(self):
        resource = FullCategoryResource()
        cat1 = Category.objects.create(name="Dad")
        cat2 = Category.objects.create(parent=cat1, name="Child")

        request = HttpRequest()
        request.GET = {"format": "json"}
        request.method = "PATCH"
        request._read_started = False

        data = {"name": "Kid"}

        request._raw_post_data = request._body = json.dumps(data)
        self.assertEqual(cat2.name, "Child")
        resp = resource.patch_detail(request, pk=cat2.pk)
        self.assertEqual(resp.status_code, 202)
        cat2 = Category.objects.get(pk=2)
        self.assertEqual(cat2.name, "Kid")
Beispiel #3
0
    def test_patch_to_one(self):
        resource = FullCategoryResource()
        cat1 = Category.objects.create(name='Dad')
        cat2 = Category.objects.create(parent=cat1, name='Child')

        request = HttpRequest()
        request.GET = {'format': 'json'}
        request.method = 'PATCH'
        request._read_started = False

        data = {'name': 'Kid'}

        request._raw_post_data = request._body = json.dumps(data)
        self.assertEqual(cat2.name, 'Child')
        resp = resource.patch_detail(request, pk=cat2.pk)
        self.assertEqual(resp.status_code, 202)
        cat2 = Category.objects.get(pk=2)
        self.assertEqual(cat2.name, 'Kid')
    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")
Beispiel #5
0
    def test_patch_to_one(self):
        resource = FullCategoryResource()
        cat1 = Category.objects.create(name='Dad')
        cat2 = Category.objects.create(parent=cat1, name='Child')

        request = HttpRequest()
        request.GET = {'format': 'json'}
        request.method = 'PATCH'
        request._read_started = False

        data = {
            'name': 'Kid'
        }

        request._raw_post_data = request._body = json.dumps(data)
        self.assertEqual(cat2.name, 'Child')
        resp = resource.patch_detail(request, pk=cat2.pk)
        self.assertEqual(resp.status_code, 202)
        cat2 = Category.objects.get(pk=2)
        self.assertEqual(cat2.name, 'Kid')