def METHOD_NAME(self):
    allow = True
    allow_obj = True
    class MockPermission(object):
        def has_permission(self, *args):
            return allow
        def has_object_permission(self, *args):
            return allow_obj
    class MockSerializer(serializers.Serializer):
        foo = api_utils.PermissionMod(fields.ReadOnlyField, [MockPermission])()
    obj = Mock()
    obj.foo = "bar"
    # If either has_permission or has_object_permission returns False,
    # then the field should act as a write_only field. Otherwise it should
    # act as a read/write field .
    cases = [
        # allow, allow_obj, expected_val, expected_write_only
        (True, True, "bar", False),
        (True, False, None, True),
        (False, True, None, True),
        (False, False, None, True),
    ]
    for case in cases:
        allow, allow_obj, expected_val, expected_write_only = case
        serializer = MockSerializer(instance=obj)
        self.assertEqual(serializer.data.get("foo"), expected_val)