Example #1
0
 def test_rapply_preserves_args_and_kwargs(self):
     def zero_if_not_check(item, check, checkFn=lambda n: n):
         if check and checkFn(item):
             return item
         return 0
     inputs = range(5)
     outputs = rapply(inputs, zero_if_not_check, True, checkFn=lambda n: n % 2)
     assert_equal(outputs, [0, 1, 0, 3, 0])
     outputs = rapply(inputs, zero_if_not_check, False, checkFn=lambda n: n % 2)
     assert_equal(outputs, [0, 0, 0, 0, 0])
Example #2
0
    def test_rapply_on_str(self):
        input = "bob"
        convert = lambda s: s.upper()
        outputs = rapply(input, convert)

        assert_equal("BOB", outputs)
        assert_true(isinstance(outputs, basestring))
Example #3
0
 def test_rapply_on_set(self):
     inputs = set(i for i in range(5))
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_in(i + 1, outputs)
     assert_true(isinstance(outputs, set))
Example #4
0
 def test_rapply_on_tuple(self):
     inputs = tuple(i for i in range(5))
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_equal(outputs[i], i + 1)
     assert_equal(type(outputs), tuple)
Example #5
0
def update_draft_registration(auth, node, draft, *args, **kwargs):
    """Update an existing draft registration

    :return: serialized draft registration
    :rtype: dict
    :raises: HTTPError
    """
    check_draft_state(draft)
    data = request.get_json()

    schema_data = data.get('schema_data', {})
    schema_data = rapply(schema_data, strip_html)

    schema_name = data.get('schema_name')
    schema_version = data.get('schema_version', 1)
    if schema_name:
        meta_schema = get_schema_or_fail(
            Q(name=schema_name, schema_version=schema_version))
        existing_schema = draft.registration_schema
        if (existing_schema.name, existing_schema.schema_version) != (
                meta_schema.name, meta_schema.schema_version):
            draft.registration_schema = meta_schema

    draft.update_metadata(schema_data)
    draft.save()
    return serialize_draft_registration(draft, auth), http.OK
Example #6
0
 def test_rapply_on_set(self):
     inputs = set(i for i in range(5))
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_in(i + 1, outputs)
     assert_true(isinstance(outputs, set))
Example #7
0
    def test_rapply_on_str(self):
        input = "bob"
        convert = lambda s: s.upper()
        outputs = rapply(input, convert)

        assert_equal("BOB", outputs)
        assert_true(isinstance(outputs, basestring))
Example #8
0
 def test_rapply_on_tuple(self):
     inputs = tuple(i for i in range(5))
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_equal(outputs[i], i + 1)
     assert_equal(type(outputs), tuple)
Example #9
0
    def test_rapply_preserves_args_and_kwargs(self):
        def zero_if_not_check(item, check, checkFn=lambda n: n):
            if check and checkFn(item):
                return item
            return 0

        inputs = range(5)
        outputs = rapply(inputs,
                         zero_if_not_check,
                         True,
                         checkFn=lambda n: n % 2)
        assert_equal(outputs, [0, 1, 0, 3, 0])
        outputs = rapply(inputs,
                         zero_if_not_check,
                         False,
                         checkFn=lambda n: n % 2)
        assert_equal(outputs, [0, 0, 0, 0, 0])
Example #10
0
    def test_rapply(self):
        inputs = {
            'foo': 'bar',
            'baz': {
                'boom': ['kapow'],
                'bang': 'bam'
            },
            'bat': ['man']
        }
        outputs = rapply(inputs, str.upper)
        assert_equal(outputs['foo'], 'bar'.upper())
        assert_equal(outputs['baz']['boom'], ['kapow'.upper()])
        assert_equal(outputs['baz']['bang'], 'bam'.upper())
        assert_equal(outputs['bat'], ['man'.upper()])

        r_assert = lambda s: assert_equal(s.upper(), s)
        rapply(outputs, r_assert)
Example #11
0
    def test_rapply(self):
        inputs = {
            'foo': 'bar',
            'baz': {
                'boom': ['kapow'],
                'bang': 'bam'
            },
            'bat': ['man']
        }
        outputs = rapply(inputs, str.upper)
        assert_equal(outputs['foo'], 'bar'.upper())
        assert_equal(outputs['baz']['boom'], ['kapow'.upper()])
        assert_equal(outputs['baz']['bang'], 'bam'.upper())
        assert_equal(outputs['bat'], ['man'.upper()])

        r_assert = lambda s: assert_equal(s.upper(), s)
        rapply(outputs, r_assert)
Example #12
0
def update_draft_registration(auth, node, draft, *args, **kwargs):
    """Update an existing draft registration

    :return: serialized draft registration
    :rtype: dict
    :raises: HTTPError
    """
    check_draft_state(draft)
    data = request.get_json()

    schema_data = data.get('schema_data', {})
    schema_data = rapply(schema_data, strip_html)

    schema_name = data.get('schema_name')
    schema_version = data.get('schema_version', 1)
    if schema_name:
        meta_schema = get_schema_or_fail(Q(name=schema_name, schema_version=schema_version))
        existing_schema = draft.registration_schema
        if (existing_schema.name, existing_schema.schema_version) != (meta_schema.name, meta_schema.schema_version):
            draft.registration_schema = meta_schema

    draft.update_metadata(schema_data)
    draft.save()
    return serialize_draft_registration(draft, auth), http.OK
Example #13
0
 def test_rapply_on_list(self):
     inputs = range(5)
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_equal(outputs[i], i + 1)
Example #14
0
 def test_rapply_on_list(self):
     inputs = range(5)
     add_one = lambda n: n + 1
     outputs = rapply(inputs, add_one)
     for i in inputs:
         assert_equal(outputs[i], i + 1)
Example #15
0
from osf.models import AbstractNode, Collection, Guid, PrivateLink, Contributor, Node, NodeRelation
from osf.models.contributor import get_contributor_permissions
from osf.models.licenses import serialize_node_license_record
from osf.utils.sanitize import strip_html
from osf.utils.permissions import ADMIN, READ, WRITE, CREATOR_PERMISSIONS
from website import settings
from website.views import find_bookmark_collection, validate_page_num
from website.views import serialize_node_summary
from website.profile import utils
from addons.mendeley.provider import MendeleyCitationsProvider
from addons.zotero.provider import ZoteroCitationsProvider
from addons.wiki.utils import serialize_wiki_widget
from addons.dataverse.utils import serialize_dataverse_widget
from addons.forward.utils import serialize_forward_widget

r_strip_html = lambda collection: rapply(collection, strip_html)
logger = logging.getLogger(__name__)


@must_be_valid_project
@must_have_permission(WRITE)
@must_not_be_registration
def edit_node(auth, node, **kwargs):
    post_data = request.json
    edited_field = post_data.get('name')
    value = post_data.get('value', '')

    new_val = None
    if edited_field == 'title':
        try:
            node.set_title(value, auth=auth)
Example #16
0
from osf.models import AbstractNode, PrivateLink, Contributor, Node, NodeRelation
from osf.models.contributor import get_contributor_permissions
from osf.models.licenses import serialize_node_license_record
from osf.utils.sanitize import strip_html
from osf.utils.permissions import ADMIN, READ, WRITE, CREATOR_PERMISSIONS
from website import settings
from website.views import find_bookmark_collection, validate_page_num
from website.views import serialize_node_summary
from website.profile import utils
from addons.mendeley.provider import MendeleyCitationsProvider
from addons.zotero.provider import ZoteroCitationsProvider
from addons.wiki.utils import serialize_wiki_widget
from addons.dataverse.utils import serialize_dataverse_widget
from addons.forward.utils import serialize_forward_widget

r_strip_html = lambda collection: rapply(collection, strip_html)
logger = logging.getLogger(__name__)

@must_be_valid_project
@must_have_permission(WRITE)
@must_not_be_registration
def edit_node(auth, node, **kwargs):
    post_data = request.json
    edited_field = post_data.get('name')
    value = post_data.get('value', '')

    new_val = None
    if edited_field == 'title':
        try:
            node.set_title(value, auth=auth)
        except ValidationError as e: