def test_09_by_query_handler_only(self):
     query = {
         "query" : {
             "bool" : {
                 "must" : [
                     {"term" : {"license.type.exact" : "cc-by"}},
                     {"term" : {"license.provenance.handler.exact" : "plugin_a"}},
                     {"term" : {"license.provenance.handler_version.exact" : "1.0"}}
                 ]
             }
         }
     }
     
     # invalidate all cc-by from plugin_1 1.0
     invalidate.invalidate_license_by_query(query, handler="plugin_a")
     
     # 0, 6, 18, 22, 23 should have no licence
     compare(["000", "666", "181818", "222222", "232323"], 0)
     
     # 1 - 5, 7 - 14 should have 1 licence
     compare(["111", "222", "333", "444", "555", "777", "888", "999", "101010", "111111", "121212", "131313", "141414"], 1)
     
     # 15 - 17, 19 - 21, 24, 25 should still have two licences
     compare(["151515", "161616", "171717", "191919", "202020", "212121", "242424", "252525"], 2)
     
     # we should also find that the cache is empty for 6, 14, 18, 22, 23
     # and still there for 0 - 5, 7 - 13, 15 - 17, 19 - 21, 24 - 25
     cache_is_empty([6, 14, 18, 22, 23], [0,1,2,3,4,5,7,8,9,10,11,12,13,15,16,17,19,20,21,24,25])
Esempio n. 2
0
def invalidate():
    qy = request.values.get("source")
    j = json.loads(qy)
    
    # extract only the "query" from the source - we're not interested in the users facet, size, sort parameters, etc
    query = j.get("query")
    
    # we also need the "license_type", "handler" and "handler_version" from a query which looks something like:
    # {"query":{"bool":{"must":[{"term":{"license.type.exact":"failed-to-obtain-license"}},{"term":{"license.provenance.handler.exact":"ubiquitous"}}]}},"size":25}
    terms = [t.get("term") for t in query.get("bool", {}).get("must", []) if t.get("term") is not None]
    
    fields = {
        "license.type.exact" : "license_type", 
        "license.provenance.handler.exact" : "handler", 
        "license.provenance.handler_version.exact" : "handler_version"
    }
    
    args = {}
    for term in terms:
        k = term.keys()[0]
        v = term.values()[0]
        args[fields.get(k)] = v
    
    # use the query the user specified to get the records to invalidate
    # and pass the parameters of the licences to remove
    query = {"query" : query}
    inval.invalidate_license_by_query(query, **args)
    
    resp = make_response(json.dumps(args))
    resp.mimetype = "application/json"
    return resp
 def test_07_by_query_all(self):
     query = {
         "query" : {
             "match_all" : {}
         }
     }
     
     # invalidate all cc-by from plugin_b 2.0
     invalidate.invalidate_license_by_query(query, license_type="cc-by", handler="plugin_b", handler_version="2.0")
     
     # 0, 9 should have no licence
     compare(["000", "999"], 0)
     
     # 1 - 8, 10 - 13, 17, 20, 24 should have 1 licence
     compare(["111", "222", "333", "444", "555", "666", "777", "888", "101010", "111111", "121212", "131313", "171717", "202020", "242424"], 1)
     
     # 14 - 16, 18, 19, 21 - 23, 25 should still have two licences
     compare(["141414", "151515", "161616", "181818", "191919", "212121", "222222", "232323", "252525"], 2)
     
     # we should also find that the cache is empty for 9, 17, 20, 24
     # and still there for 0 - 8, 10 - 16, 18, 19, 21 - 23, 25
     cache_is_empty([9,17,20,24], [0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,18,19,21,22,23,25])