def test_update_fields(self, base_mock, setattr_mock): fields = {'id': 1, 'slug': 'testobj'} base_mock.fields.return_value = ('id', 'slug') BaseResolweResource._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_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 = {} BaseResolweResource._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): BaseResolweResource.save(base_mock)
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 = {} BaseResolweResource._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 self.assertRaisesRegex(ValueError, message): BaseResolweResource.save(base_mock)
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 = {} BaseResolweResource._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): BaseResolweResource.save(base_mock)