def test_fields(self, attrgetter_mock): base_resource = BaseResource(resolwe=self.resolwe_mock) base_resource.WRITABLE_FIELDS = ('writable', ) base_resource.UPDATE_PROTECTED_FIELDS = ('update_protected', ) base_resource.READ_ONLY_FIELDS = ('read_only', ) self.assertEqual(base_resource.fields(), ('writable', 'update_protected', 'read_only'))
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_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_field_constraints(self, attrgetter_mock): base_resource = BaseResource(resolwe=self.resolwe_mock) base_resource.WRITABLE_FIELDS = ('writable_scalar', ) base_resource.READ_ONLY_FIELDS = ('read_only_scalar', ) base_resource._original_values = {'writable_scalar': None, 'read_only_scalar': None} base_resource.writable_scalar = None base_resource.read_only_scalar = None message = 'Can not change read only field read_only_scalar' with six.assertRaisesRegex(self, ValueError, message): base_resource.read_only_scalar = 42 base_resource.writable_scalar = '42' self.assertEqual(base_resource.writable_scalar, '42')