Example #1
0
class TestAlveolocalLoad(unittest.TestCase):

    def setUp(self):
        
        self.api = API()
        
        
    def test_attach_directory(self):
        """we can attach a directory containing RDF files"""
        
        # check the number of triples loaded
        self.assertEqual(7628, self.api.attach_directory(TEST_DATA))


    def test_version(self):
        """we return the right version string"""
        
        
        self.assertEqual("V2.0", self.api.version())
Example #2
0
    name = request.POST.get("file").raw_filename
    output = alveo.add_annotation(filename=name,
                                  collection_uri=collection_uri,
                                  data=data)
    if 'Accept' in request.headers and request.headers[
            'Accept'] == "application/json":
        response.content_type = 'application/json'
        output = json.dumps(output)
    return output


@application.get('/sparql/<collection_id>')
@view('sparql_search')
def search_metadata_sparql(collection_id):
    collection_uri = "%scatalog/%s" % (alveo.base_url, collection_id)
    sparql_query = request.query["query"]
    output = alveo.search_sparql(collection_uri, sparql_query)
    if 'Accept' in request.headers and request.headers[
            'Accept'] == "application/json":
        response.content_type = 'application/json'
        output = json.dumps(output)
    return output


if __name__ == '__main__':

    #alveo = API()
    alveo.attach_directory(TEST_DATA)

    application.run(host='localhost', port=3000,
                    reloader=True)  # This starts the HTTP server
Example #3
0
class TestAlveolocal(unittest.TestCase):

    def setUp(self):
        
        self.api = API()
        self.api.attach_directory(TEST_DATA)


    def test_item_base_url(self):
        """generating the right url for an item"""
        
        itemuri = "http://*****:*****@context', ann)
        
        self.assertEqual(2, len(ann['alveo:annotations']))
        
        self.assertEqual('dada:TextAnnotation', ann['alveo:annotations'][0]['@type'])
        
        self.assertEqual(docurl, ann['commonProperties']['alveo:annotates'])
        
        ann = self.api.get_annotations(itemuri, {"user":"******"})
        ann = self.api.get_annotations(itemuri, {"priorTo":datetime.strptime("2013-12-20T12:20:00", '%Y-%m-%dT%I:%M:%S')})
        
        pass

    def test_search(self):
        """we can search for items"""
        
        query = (('dc:created', '1788'), )
        
        items = self.api.search(query)
        
        self.assertEqual(5, len(items))
        self.assertIn('http://localhost:3000/catalog/cooee/items/1-011', items)

        query = (('dc:created', '1788'), ('cooee:texttype', 'Private Correspondence'))
        items = self.api.search(query)
        
        self.assertEqual(4, len(items))
        self.assertNotIn('http://localhost:3000/catalog/cooee/items/1-013', items)
        self.assertIn('http://localhost:3000/catalog/cooee/items/1-011', items)
        
    def test_search_sparql(self):
        
        query = "select * where {?s <http://purl.org/dc/terms/isPartOf> ?o}"
        collection_name = "cooee"
        result = self.api.search_sparql(collection_name, query)
        
        self.assertIsInstance(result, dict, "Expected dict, got %s" % type(result))
        for key in result.keys():
            self.assertIn(key, ["head", "results"], "Expected %s to be one of the items in the list" % key)
        self.assertIn("vars", result["head"], "Expected to include vars")
        self.assertIn("bindings", result["results"], "Expected to include bindings")
        for binding in result["results"]["bindings"]:
            for var in result["head"]["vars"]:
                self.assertIn(var, binding, "Expected all bindings to include items in vars")
        
    def tearDown(self):
        pass
Example #4
0
def upload_annotation(collection_id, item_id):
    url = request.url
    collection_uri = url.replace("/%s/annotations" % item_id, "")
    uploadedfile = request.POST.get("file").file
    text = uploadedfile.read()
    data = json.loads(text)
    name = request.POST.get("file").raw_filename
    output = alveo.add_annotation(filename=name, collection_uri=collection_uri, data=data)
    if 'Accept' in request.headers and request.headers['Accept'] == "application/json":
        response.content_type = 'application/json'
        output = json.dumps(output)
    return output

@application.get('/sparql/<collection_id>')
@view('sparql_search')
def search_metadata_sparql(collection_id):
    collection_uri = "%scatalog/%s" %(alveo.base_url, collection_id)
    sparql_query = request.query["query"]
    output = alveo.search_sparql(collection_uri, sparql_query)
    if 'Accept' in request.headers and request.headers['Accept'] == "application/json":
        response.content_type = 'application/json'
        output = json.dumps(output)
    return output

if __name__=='__main__':
    
    
    #alveo = API()
    alveo.attach_directory(TEST_DATA)
    
    application.run(host='localhost', port=3000, reloader=True) # This starts the HTTP server