def test_claim_collection_fails_if_key_hash_not_set(self): coll, key = collection.make("socrates") assert_equals(coll["owner"], "socrates") del coll["key_hash"] coll = collection.claim_collection(coll, "plato", key) assert_equals(coll["owner"], "plato")
def collection_create(): """ POST /collection creates new collection """ response_code = None coll, key = collection.make(request.json.get("owner", None)) refset_metadata = request.json.get("refset_metadata", None) if refset_metadata: coll["refset_metadata"] = refset_metadata coll["ip_address"] = request.remote_addr try: coll["title"] = request.json["title"] aliases = request.json["aliases"] (tiids, new_items) = item_module.create_or_update_items_from_aliases(aliases, myredis, mydao) for item in new_items: namespaces = item["aliases"].keys() mixpanel.track("Create:Item", {"Namespace":namespaces[0], "Source":"collection"}, request) if not tiids: abort(404, "POST /collection requires a list of [namespace, id] pairs.") except (AttributeError, TypeError): # we got missing or improperly formated data. logger.error( "we got missing or improperly formated data: '{id}' with {json}.".format( id=coll["_id"], json=str(request.json))) abort(404, "Missing arguments.") aliases_strings = [namespace+":"+nid for (namespace, nid) in aliases] # save dict of alias:tiid coll["alias_tiids"] = dict(zip(aliases_strings, tiids)) logger.info(json.dumps(coll, sort_keys=True, indent=4)) mydao.save(coll) response_code = 201 # Created logger.info( "saved new collection '{id}' with {num_items} items.".format( id=coll["_id"], num_items=len(coll["alias_tiids"]) )) mixpanel.track("Create:Report", {"Report Id":coll["_id"]}, request) resp = make_response(json.dumps({"collection":coll, "key":key}, sort_keys=True, indent=4), response_code) resp.mimetype = "application/json" return resp
def collection_create(): """ POST /collection creates new collection """ response_code = None coll, key = collection.make(request.json.get("owner", None)) refset_metadata = request.json.get("refset_metadata", None) if refset_metadata: coll["refset_metadata"] = refset_metadata coll["ip_address"] = request.remote_addr try: coll["title"] = request.json["title"] aliases = request.json["aliases"] tiids = prep_collection_items(aliases) aliases_strings = [namespace + ":" + nid for (namespace, nid) in aliases] except (AttributeError, TypeError): # we got missing or improperly formated data. logger.error( "we got missing or improperly formated data: '{id}' with {json}.".format( id=coll["_id"], json=str(request.json) ) ) abort(404, "Missing arguments.") # save dict of alias:tiid coll["alias_tiids"] = dict(zip(aliases_strings, tiids)) logger.info(json.dumps(coll, sort_keys=True, indent=4)) mydao.save(coll) response_code = 201 # Created logger.info( "saved new collection '{id}' with {num_items} items.".format(id=coll["_id"], num_items=len(coll["alias_tiids"])) ) resp = make_response(json.dumps({"collection": coll, "key": key}, sort_keys=True, indent=4), response_code) resp.mimetype = "application/json" return resp
def test_claim_collection_fails_with_wrong_key(self): coll, key = collection.make("socrates") assert_equals(coll["owner"], "socrates") coll = collection.claim_collection(coll, "plato", "wrong key") assert_equals(coll["owner"], "plato")
def test_claim_collection(self): coll, key = collection.make("socrates") assert_equals(coll["owner"], "socrates") coll = collection.claim_collection(coll, "plato", key) assert_equals(coll["owner"], "plato")
def test_create_returns_collection_and_update_key(self): coll, key = collection.make() assert collection.check_password_hash(coll["key_hash"], key)
def test_make_sets_owner(self): coll, key = collection.make() assert_equals(coll["owner"], None) coll, key = collection.make("socrates") assert_equals(coll["owner"], "socrates")
def test_make_creates_identifier(self): coll, key = collection.make() assert_equals(len(coll["_id"]), 6)