예제 #1
0
 def test_store_remote_cached_resource(self):
     test_uri = "http://nl.dbpedia.org/resource/Ton_Smits"
     resource = CacheResource.get_remote_lod_resource(test_uri)
     store = rdfstore._rdfstore_test
     assert len(resource) > 0
     store._clear_all()
     graph_store = store.get_graph_store
     cache_graph = "http://{}/resource/cache#graph".format(RDFRecord.get_rdf_base_url())
     self.assertFalse(
         store.ask(
             query="where {{<{}> ?p ?o}}".format(test_uri)
         ))
     response = CacheResource.store_remote_cached_resource(resource, graph_store, cache_graph)
     assert response is not None
     assert response
     self.assertTrue(
         store.ask(
             query="where {{<{}> ?p ?o}}".format(test_uri)
         )
     )
     #  cacheUrl is no longer being added
     self.assertFalse(
         store.ask(
             query="where {{<{}> <http://schemas.delving.org/nave/terms/cacheUrl> ?o}}".format(
                 test_uri)
         )
     )
예제 #2
0
 def test_get_remote_lod_resource(self):
     test_uri = "http://sws.geonames.org/2759794"
     resource = CacheResource.get_remote_lod_resource(test_uri)
     assert resource is not None
     assert isinstance(resource, Graph)
     assert len(list(resource.predicates())) != 0
     assert len(list(resource.objects(predicate=RDF.type))) == 2
예제 #3
0
 def test_save_cached_resource(self):
     store = rdfstore._rdfstore_test
     store._clear_all()
     graph = load_nquad_fixtures()
     assert len(graph) > 0
     graph_store = store.get_graph_store
     resource = CacheResource()
     resource.source_uri = "http://nl.dbpedia.org/resource/Ton_Smits"
     resource.save()
     assert CacheResource.objects.count() == 1
     #  from ..tasks import store_cache_resource
     response = resource.update_cached_resource(graph_store)
     assert response
     resource_object = CacheResource.objects.first()
     assert resource_object.get_spec_name() == "cache"
     assert resource_object.named_graph == resource_object.document_uri + "#graph"
     assert resource_object.stored
     assert len(resource_object.get_graph()) > 0
     assert len(resource_object.source_rdf) > 0
예제 #4
0
 def test_save_cached_resource(self):
     from search import get_es_client
     client = get_es_client()
     s = Search(client).index("test")
     del_response = client.delete_by_query(index='test', q="*:*")
     es_response = s.execute()
     self.assertEquals(
         es_response.hits.total,
         0
     )
     assert CacheResource.objects.count() == 0
     store = rdfstore._rdfstore_test
     store._clear_all()
     graph = load_nquad_fixtures()
     assert len(graph) > 0
     resource = CacheResource()
     resource.source_uri = "http://nl.dbpedia.org/resource/Ton_Smits"
     resource.save()
     response = tasks.store_cache_resource.delay(obj=resource, store=store)
     assert response.status
     assert response.result
     response = tasks.update_rdf_in_index.delay(obj=resource, store=store, index='test')
     time.sleep(1)
     assert response.status
     assert response.result
     assert CacheResource.objects.count() == 1
     es_response = s.execute()
     self.assertEquals(
         es_response.hits.total,
         1
     )
     record = es_response.hits[0]
     # assert len(list(record['_source'].keys())) > 2
     resource = CacheResource.objects.first()
     es_action =  resource.create_es_action(index="test", store=store, record_type="cached")
     assert es_action is not None
예제 #5
0
 def test_bad_get_remote_lod_resource(self):
     bad_uri = "http://sws.geonames.org/2759794/about2.rdf"
     resource = CacheResource.get_remote_lod_resource(bad_uri)
     assert resource is None