def test_update_fields(self, base_mock, setattr_mock):
     fields = {'id': 1, 'slug': 'testobj'}
     base_mock.fields.return_value = ('id', 'slug')
     BaseResource._update_fields(base_mock, fields)
     setattr_mock.assert_has_calls([call(base_mock, 'id', 1),
                                    call(base_mock, 'slug', 'testobj')],
                                   any_order=True)
    def test_update_fileds(self):
        resource = BaseResource(resolwe=self.resolwe_mock)
        resource.WRITABLE_FIELDS = ('first_field',)
        resource.first_field = None

        payload = {'first_field': 42}

        resource._update_fields(payload)

        self.assertEqual(resource.first_field, 42)
Exemple #3
0
    def test_update_fileds(self):
        resource = BaseResource(resolwe=self.resolwe_mock)
        resource.WRITABLE_FIELDS = ('first_field', )
        resource.first_field = None

        payload = {'first_field': 42}

        resource._update_fields(payload)

        self.assertEqual(resource.first_field, 42)
    def test_save_patch_read_only(self, base_mock):
        base_mock.READ_ONLY_FIELDS = ('id', 'read_only_dict')
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'read_only_dict')
        read_only_dict = {}
        BaseResource._update_fields(base_mock, {'id': 1,
                                                'slug': 'test',
                                                'read_only_dict': read_only_dict})
        base_mock.read_only_dict['change'] = 'change-not-allowed'

        message = 'Not allowed to change read only fields read_only_dict'
        with six.assertRaisesRegex(self, ValueError, message):
            BaseResource.save(base_mock)
Exemple #5
0
 def test_update_fields(self, base_mock, setattr_mock):
     fields = {'a': 1, 'b': 2}
     BaseResource._update_fields(base_mock, fields)
     setattr_mock.assert_has_calls([call(base_mock, 'a', 1), call(base_mock, 'b', 2)], any_order=True)