コード例 #1
0
    def test_create_new_collection_from_tiids(self):
        tiids = ['234', '345']
        (coll_doc, collection_object) = collection.create_new_collection_from_tiids(
            cid=None,
            title="mah collection",
            tiids=tiids,
            ip_address=None,
            refset_metadata=None)

        assert_equals(coll_doc["title"], "mah collection")
        assert_equals(coll_doc["alias_tiids"].keys(), tiids)

        assert_equals(collection_object.title, "mah collection")
        assert_equals(collection_object.added_items, [])
        assert_equals(collection_object.tiids, tiids)
        found_collection_object = collection.Collection.query.filter_by(cid=collection_object.cid).first()
        assert_equals(found_collection_object.tiids, collection_object.tiids)
コード例 #2
0
    def test_create_new_collection_from_tiids(self):
        tiids = ['234', '345']
        (coll_doc, collection_object) = collection.create_new_collection_from_tiids(
            cid=None,
            title="mah collection",
            tiids=tiids,
            ip_address=None,
            refset_metadata=None)

        assert_equals(coll_doc["title"], "mah collection")
        assert_equals(coll_doc["alias_tiids"].keys(), tiids)

        assert_equals(collection_object.title, "mah collection")
        assert_equals(collection_object.added_items, [])
        assert_equals(collection_object.tiids, tiids)
        found_collection_object = collection.Collection.query.filter_by(cid=collection_object.cid).first()
        assert_equals(found_collection_object.tiids, collection_object.tiids)
コード例 #3
0
def collection_create():
    """
    POST /collection
    creates new collection
    """
    response_code = None
    try:
        cid = request.args.get("collection_id", collection._make_id())
        if "tiids" in request.json:
            (coll_doc,
             collection_object) = collection.create_new_collection_from_tiids(
                 cid=cid,
                 title=request.json.get("title", "my collection"),
                 tiids=request.json.get("tiids"),
                 ip_address=request.remote_addr,
                 refset_metadata=request.json.get("refset_metadata", None))
        else:
            # to be depricated
            (coll_doc, collection_object) = collection.create_new_collection(
                cid=cid,
                title=request.json.get("title", "my collection"),
                aliases=request.json["aliases"],
                ip_address=request.remote_addr,
                refset_metadata=request.json.get("refset_metadata", None),
                myredis=myredis,
                mydao=mydao)
    except (AttributeError, TypeError):
        # we got missing or improperly formated data.
        logger.error(
            u"we got missing or improperly formated data: '{cid}' with {json}."
            .format(cid=cid, json=str(request.json)))
        abort_custom(404, "Missing arguments.")

    response_code = 201  # Created
    resp = make_response(
        json.dumps({"collection": coll_doc}, sort_keys=True, indent=4),
        response_code)
    return resp
コード例 #4
0
ファイル: views.py プロジェクト: dbeucke/total-impact-core
def collection_create():
    """
    POST /collection
    creates new collection
    """
    response_code = None
    try:
        cid = request.args.get("collection_id", collection._make_id())
        if "tiids" in request.json:
            (coll_doc, collection_object) = collection.create_new_collection_from_tiids(
                cid=cid, 
                title=request.json.get("title", "my collection"), 
                tiids=request.json.get("tiids"), 
                ip_address=request.remote_addr, 
                refset_metadata=request.json.get("refset_metadata", None))
        else:
            # to be depricated
            (coll_doc, collection_object) = collection.create_new_collection(
                cid=cid, 
                title=request.json.get("title", "my collection"), 
                aliases=request.json["aliases"], 
                ip_address=request.remote_addr, 
                refset_metadata=request.json.get("refset_metadata", None), 
                myredis=myredis, 
                mydao=mydao)
    except (AttributeError, TypeError):
        # we got missing or improperly formated data.
        logger.error(u"we got missing or improperly formated data: '{cid}' with {json}.".format(
                cid=cid,
                json=str(request.json)))
        abort_custom(404, "Missing arguments.")

    response_code = 201 # Created
    resp = make_response(json.dumps({"collection":coll_doc},
            sort_keys=True, indent=4), response_code)
    return resp