예제 #1
0
def test_list():
    c1 = Concept('_666')
    c2 = Concept('_999')
    l1 = Label('foo', 'en')
    l2 = Label('bar', 'de')

    lines = txt.list_concepts([c1, c2])
    lines = ''.join(lines)
    assert lines == '_666\n_999\n'

    c1.pref_labels.append(l1)

    lines = txt.list_concepts([c1, c2])
    lines = ''.join(lines)
    assert lines == 'foo\n_999\n'

    c1.alt_labels.append(l2)

    lines = txt.list_concepts([c1, c2])
    lines = ''.join(lines)
    assert lines == 'foo\n_999\n'

    c2.alt_labels.append(l1)

    lines = txt.list_concepts([c1, c2])
    lines = ''.join(lines)
    assert lines == 'foo\n_999\n'
예제 #2
0
파일: concept.py 프로젝트: FND/sivoc
    def from_document(self, doc):
        """
        internalizes values from a dictionary (structure as per as_document)
        """
        from model.label import Label # XXX: coupling!

        self._id = doc.get('_id')
        for _type in ('pref', 'alt'):
            labels = doc.get('labels', {}).get(_type, [])
            setattr(self, "%s_labels" % _type, [Label('').from_document(label)
                    for label in labels])
        return self
예제 #3
0
def test_show():
    c0 = Concept('_666')
    l1 = Label('foo', 'en')
    l2 = Label('bar', 'de')

    lines = txt.show_concept(c0)
    lines = ''.join(lines)
    assert lines == '_666\n\nPREFERRED LABELS\n\nALTERNATIVE LABELS\n'

    c0.pref_labels.append(l1)

    lines = txt.show_concept(c0)
    lines = ''.join(lines)
    assert lines == ('_666\n\n'
                     'PREFERRED LABELS\n    [en] foo\n\n'
                     'ALTERNATIVE LABELS\n')

    c0.pref_labels.append(l2)

    lines = txt.show_concept(c0)
    lines = ''.join(lines)
    assert lines == ('_666\n\n'
                     'PREFERRED LABELS\n    [en] foo\n    [de] bar\n\n'
                     'ALTERNATIVE LABELS\n')

    c0.alt_labels.append(l2)

    lines = txt.show_concept(c0)
    lines = ''.join(lines)
    assert lines == ('_666\n\n'
                     'PREFERRED LABELS\n    [en] foo\n    [de] bar\n\n'
                     'ALTERNATIVE LABELS\n    [de] bar\n')

    c0.alt_labels.append(l1)

    lines = txt.show_concept(c0)
    lines = ''.join(lines)
    assert lines == ('_666\n\nPREFERRED LABELS\n    [en] foo\n    [de] bar\n\n'
                     'ALTERNATIVE LABELS\n    [de] bar\n    [en] foo\n')
예제 #4
0
파일: conceptcreator.py 프로젝트: FND/sivoc
def post_creator(environ, start_response):
    content_type = environ.get('CONTENT_TYPE', '')
    if not content_type == 'application/x-www-form-urlencoded':  # XXX: TiddlyWeb uses startswith here!?
        raise HTTP415

    # TODO: this might be encapsulated in middleware (cf. tiddlyweb.web.query)
    content_length = int(environ['CONTENT_LENGTH'] or 0)
    content = environ['wsgi.input'].read(content_length)
    data = parse_qs(content, keep_blank_values=True)

    concept = Concept()
    # TODO: label language (input/selection currently missing from HTML template)
    for label_type in ['pref', 'alt']:
        key = '%s_labels' % label_type
        for name in data[key]:
            if name:
                label = Label(name, lang=None)
                getattr(concept, key).append(label)

    _id = STORE.add(concept)

    response_headers = [('Location', '/concepts/%s' % concept._id)]
    start_response(HTTP['302'], response_headers)
    return ['']
def test_setup_label():
    my_label = Label("Music")
    assert (my_label.name == "Music")
예제 #6
0
파일: label.py 프로젝트: zanachka/quickpin
    def post(self):
        """
        Create a label.

        **Example Request**

        .. sourcecode:: json

            {
                "labels": [
                    {"name": "gender"},
                    {"name": "age"},
                    ...
                ]
            }

        **Example Response**

        .. sourcecode:: json

            {
                "message": "2 new labels created."
            }

        :<header Content-Type: application/json
        :<header X-Auth: the client's auth token
        :>json list labels: a list of labels to create
        :>json str labels[n].name: name of label to create

        :>header Content-Type: application/json
        :>json str message: api response message

        :status 202: created
        :status 400: invalid request body
        :status 401: authentication required
        """

        request_json = request.get_json()
        redis = worker.get_redis()
        labels = list()

        # Validate input and create labels
        for t in request_json['labels']:
            if t['name'].strip() == '':
                raise BadRequest('Label name is required')
            else:
                try:
                    label = Label(name=t['name'].lower().strip())
                    g.db.add(label)
                    g.db.flush()
                    redis.publish('label', json.dumps(label.as_dict()))
                    labels.append(label.as_dict())
                except IntegrityError:
                    g.db.rollback()
                    raise BadRequest(
                        'Label "{}" already exists'.format(label.name)
                    )
                except AssertionError:
                    g.db.rollback()
                    raise BadRequest(
                        '"{}" contains non-alphanumeric character'
                        .format(t['name'])
                    )

        # Save labels
        g.db.commit()

        message = '{} new labels created'.format(len(request_json['labels']))
        labels = labels
        response = jsonify(
            message=message,
            labels=labels
        )
        response.status_code = 202

        return response
예제 #7
0
def test_create_record_label(app):
    app.label.create_recording_artist(Label(name="rl_#1", asap="WB86-8RH31.50UTS-J",
                                            note="Mens autem qui est in festinabat non facere bonum, voluntas in malo reperit."))