예제 #1
0
 def test_fields(self):
     base_resource = BaseResolweResource(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(),
                      ('read_only', 'update_protected', 'writable'))
예제 #2
0
 def test_fields(self):
     base_resource = BaseResolweResource(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(),
                      ("read_only", "update_protected", "writable"))
예제 #3
0
    def test_eq(self):
        obj_1 = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj_2 = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj_3 = BaseResource(resolwe=self.resolwe_mock, id=2)
        obj_4 = BaseResolweResource(resolwe=self.resolwe_mock, id=1)

        self.assertEqual(obj_1 == obj_2, True)
        self.assertEqual(obj_1 == obj_3, False)
        self.assertEqual(obj_1 == obj_4, False)
예제 #4
0
    def test_field_constraints(self):
        base_resource = BaseResolweResource(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}

        # Setting to same value should be fine.
        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')
예제 #5
0
    def test_field_constraints(self):
        base_resource = BaseResolweResource(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,
        }

        # Setting to same value should be fine.
        base_resource.writable_scalar = None
        base_resource.read_only_scalar = None

        message = "Can not change read only field read_only_scalar"
        with self.assertRaisesRegex(ValueError, message):
            base_resource.read_only_scalar = 42

        base_resource.writable_scalar = "42"
        self.assertEqual(base_resource.writable_scalar, "42")