コード例 #1
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_missing_fields():
    """Test missing fields."""
    overdo = dojson.Overdo()

    @overdo.over('247', '^247..')
    def match(self, key, value):
        return value

    assert '0247_' in overdo.missing({'0247_': '024', '247__': '247'})
コード例 #2
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_none_value():
    """Test none value."""
    overdo = dojson.Overdo()

    @overdo.over('024', '^024..')
    @ignore_value
    def match(self, key, value):
        return None

    data = overdo.do({'0247_': 'this should not be added'})
    assert "024" not in data, "key with None value should not be added"
コード例 #3
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_destination_with_dashes():
    """Test destination with dashes."""
    overdo = dojson.Overdo()

    @overdo.over('with-dashes', '^247..')
    def match_247(self, key, value):
        return key, value

    data = overdo.do({'0247_': '024', '247__': '247'})

    assert ('247__', '247') == data['with-dashes']
コード例 #4
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_no_none_value():
    """Test a valid value with the ignore_value decorator."""
    overdo = dojson.Overdo()
    from dojson.utils import ignore_value

    @overdo.over('024', '^024..')
    @ignore_value
    def match(self, key, value):
        return value

    data = overdo.do({'0247_': 'valid value'})
    assert data.get('024') == 'valid value'
コード例 #5
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_ignore_item_exception():
    """Test ignore item exception."""
    overdo = dojson.Overdo()

    @overdo.over('b', 'b')
    @for_each_value
    def match(self, key, value):
        if not value:
            raise IgnoreItem()
        return value

    source = {'b': ['', 0, 1, 2, 3, None]}
    result = {'b': [1, 2, 3]}

    assert overdo.do(source) == result
コード例 #6
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_index_creation():
    """Test index creation."""
    overdo = dojson.Overdo()

    @overdo.over('247', '^247..')
    def match_247(self, key, value):
        return key, value

    @overdo.over('024', '^024..')
    def match_024(self, key, value):
        return key, value

    data = overdo.do({'0247_': '024', '247__': '247'})

    assert ('0247_', '024') == data['024']
    assert ('247__', '247') == data['247']
コード例 #7
0
ファイル: test_core.py プロジェクト: topless/dojson
def test_flatten():
    """Test result flattening."""
    overdo = dojson.Overdo()

    @overdo.over('a', 'a')
    @flatten
    def times(self, key, value):
        for item in value:
            yield [item * 2]

    @overdo.over('b', 'b')
    @flatten
    @for_each_value
    def square(self, key, value):
        for item in value:
            yield item * item

    source = {'a': [0, 1], 'b': [[0, 1], [2, 3]]}
    result = {'a': [0, 2], 'b': [0, 1, 4, 9]}

    assert overdo.do(source) == result
コード例 #8
0
# In applying this license, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.

from __future__ import absolute_import, division, print_function

from HTMLParser import HTMLParser

import dojson

from flask import current_app

from inspire_utils.helpers import force_list
from inspirehep.utils.record import get_abstract, get_subtitle, get_title

orcid_overdo = dojson.Overdo()


class MLStripper(HTMLParser):
    def __init__(self):
        self.reset()
        self.fed = []

    def handle_data(self, d):
        self.fed.append(d)

    def get_data(self):
        return ''.join(self.fed)


def strip_tags(html):
コード例 #9
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, RERO does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
"""Invenio module for pre booking."""

import dojson

prebooking = dojson.Overdo()


@prebooking.over('recid', '^001')
def control_number(self, key, value):
    """Record Identifier."""
    return value


@prebooking.over('rero_id', '^035__')
def rero_id(self, key, value):
    """Language Code."""
    return "http://data.rero.ch/01-" + value.get('a')


@prebooking.over('title', '^245__')