def test_large_case(self): from testgraph import TestGraph p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674', u'action': u'REMOVE'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 8)
def test_not_found(self): from rdflib import Graph p = Pump("data/person_def.json") p.original_graph = Graph() # empty graph p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n12345678', u'action': u'Remove'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 0)
def test_summarize(self): from testgraph import TestGraph p = Pump("data/person_def.json") p.original_graph = TestGraph() print p.update_def p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'any1': u'1'}} print p.summarize() # No exception thrown by summarize
def test_single_uri_case(self): from testgraph import TestGraph p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2084211328', u'action': u'Remove'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 1)
def test_add_one_new_to_two(self): from testgraph import TestGraph p = Pump("data/grant_pi_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n45', u'pis': u'http://vivo.school.edu/individual/n1134'}} [add, sub] = p.update() self.assertTrue( len(add) == 3 and len(sub) == 6)
def test_none_to_empty(self): from testgraph import TestGraph p = Pump("data/grant_pi_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44', u'pis': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 0)
def test_inject_empty_original_graph(self): from rdflib import Graph, URIRef p = Pump() p.original_graph = Graph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n8984374104', u'abbreviation': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 1 and len(sub) == 0 and (None, URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), URIRef("http://vivoweb.org/ontology/core#Building")) in add)
def test_no_secondary_merge(self): from testgraph import TestGraph p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {3: {u'uri': u'http://vivo.school.edu/individual/n710', u'action': u''}, 4: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'action': u'a'}, 7: {u'uri': u'http://vivo.school.edu/individual/n711', u'action': u'a'}, } [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 0)
def test_unique_three_delete_not_found(self): from testgraph import TestGraph # Delete the zip code from an existing address that doesn't have a zip code. p = Pump("data/org_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n3535', u'zip': u'None'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 0)
def test_change_without_lang(self): from rdflib import URIRef, Literal from testgraph import TestGraph p = Pump("data/org_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2525', u'name': u'Ad ver tising'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue( len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n2525"), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Ad ver tising")) in add)
def test_add_without_datatype(self): from rdflib import URIRef, Literal from testgraph import TestGraph p = Pump("data/building_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'url': u'http://a'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue( len(add) == 4 and len(sub) == 0 and (None, URIRef("http://vivoweb.org/ontology/core#linkURI"), Literal("http://a")) in add)
def test_change_with_datatype(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph p = Pump("data/building_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'abbreviation': u'PH9'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue( len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n1001011525"), URIRef("http://vivoweb.org/ontology/core#abbreviation"), Literal("PH9", datatype=XSD.string)) in add)
def test_delete_unicode(self): from rdflib import URIRef, Literal from testgraph import TestGraph p = Pump("data/person_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n711', u'name': u'None'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n711"), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Ελληνικά")) in sub)
def test_uri_not_found(self): from testgraph import TestGraph # Use the URI when not found p = Pump("data/person_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097936', u'types': u'fac;person'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue(len(add) == 2 and len(sub) == 0)
def test_uri_is_blank(self): from testgraph import TestGraph # Use the URI when not found p = Pump("data/person_def.json") p.update_data = {1: {u'uri': u' ', u'types': u'fac;person'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue(len(add) == 2 and len(sub) == 0)
def test_multiple_one_delete(self): from testgraph import TestGraph # Empty the set of values p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674', u'research_areas': u'None'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 4)
def test_unique_one_delete(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph p = Pump() p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'abbreviation': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n1001011525"), URIRef("http://vivoweb.org/ontology/core#abbreviation"), Literal("JWRU", datatype=XSD.string)) in sub)
def test_multiple_one_change_nothing(self): from testgraph import TestGraph # Do nothing if the multiple values specified match those in VIVO p = Pump("data/person_def.json") p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'types': u'fac;person'}} p.original_graph = TestGraph() [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 0)
def test_unique_one_add(self): from rdflib import URIRef, Literal from testgraph import TestGraph p = Pump() p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2525', u'abbreviation': u'PH9'}} [add, sub] = p.update() self.assertTrue( len(add) == 1 and len(sub) == 0 and (URIRef("http://vivo.school.edu/individual/n2525"), URIRef("http://vivoweb.org/ontology/core#abbreviation"), Literal("PH9")) in add)
def test_add_two_to_empty(self): from rdflib import URIRef from testgraph import TestGraph p = Pump("data/grant_pi_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44', u'pis': u'http://vivo.school.edu/individual/n1133;http://vivo.school.edu/individual/n3413'}} [add, sub] = p.update() self.assertTrue( len(add) == 6 and len(sub) == 0 and (URIRef("http://vivo.school.edu/individual/n44"), URIRef("http://vivoweb.org/ontology/core#relates"), None) in add)
def test_unique_three_add_partial_path(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph p = Pump("data/grant_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n55', u'start_date': u'2006-03-01'}} [add, sub] = p.update() self.assertTrue( len(add) == 3 and len(sub) == 0 and (None, URIRef("http://vivoweb.org/ontology/core#dateTime"), Literal("2006-03-01", datatype=XSD.datetime)) in add)
def test_remove(self): from testgraph import TestGraph from rdflib import URIRef p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674', u'any1': u'n'}} [add, sub] = p.update() self.assertTrue(len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n25674"), URIRef("http://vivoweb.org/ontology/core#hasResearchArea"), URIRef("http://any1")) in sub)
def test_uri_is_invalid(self): from testgraph import TestGraph # Use the URI when not found p = Pump("data/person_def.json") p.update_data = {1: {u'uri': u'not a uri', u'types': u'fac;person'}} p.original_graph = TestGraph() with self.assertRaises(Exception): [add, sub] = p.update() print add, sub
def test_unique_three_add(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph # Add a start date to a grant. There is no date time interval, so a full path will need to be created p = Pump("data/grant_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44', u'start_date': u'2015-03-01'}} [add, sub] = p.update() self.assertTrue( len(add) == 5 and len(sub) == 0 and (None, URIRef("http://vivoweb.org/ontology/core#dateTime"), Literal("2015-03-01", datatype=XSD.datetime)) in add)
def test_unique_three_delete(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph # Delete the zip code on an existing address p = Pump("data/org_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n4545', u'zip': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 1 and (None, URIRef("http://www.w3.org/2006/vcard/ns#postalCode"), Literal("32604", datatype=XSD.string)) in sub)
def test_show_merge(self): from testgraph import TestGraph p = Pump("data/person_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674', u'action': u'b'}, 2: {u'uri': u'http://vivo.school.edu/individual/n709', u'action': u'a1'}, 3: {u'uri': u'http://vivo.school.edu/individual/n710', u'action': u''}, 4: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'action': u'a1'}, 5: {u'uri': u'http://vivo.school.edu/individual/n2084211328', u'action': u'a'}, 6: {u'uri': u'http://vivo.school.edu/individual/n708', u'action': u'b1'}, 7: {u'uri': u'http://vivo.school.edu/individual/n711', u'action': u'a1'}, } [add, sub] = p.update() self.assertTrue(len(add) == 2 and len(sub) == 6)
def test_unique_three_delete_datetime(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph # WARNING: Delete start date value from existing datetime interval. This may not be the desirable data # management action p = Pump("data/grant_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n125', u'start_date': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 1 and (None, URIRef("http://vivoweb.org/ontology/core#dateTime"), Literal("2010-04-01", datatype=XSD.datetime)) in sub)
def test_unique_three_add_to_existing(self): from rdflib import URIRef, Literal, XSD from testgraph import TestGraph # Add a zip code to an address already exists, the zip needs to be # added to the existing address p = Pump("data/org_def.json") p.original_graph = TestGraph() p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n3535', u'zip': u'32653'}} [add, sub] = p.update() self.assertTrue( len(add) == 1 and len(sub) == 0 and (None, URIRef("http://www.w3.org/2006/vcard/ns#postalCode"), Literal("32653", datatype=XSD.string)) in add)
def test_unique_two_delete(self): from rdflib import URIRef from testgraph import TestGraph p = Pump("data/grant_dates_def.json") p.original_graph = TestGraph() # In this example, dates are enumerated p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n125', u'end_date': u'None'}} [add, sub] = p.update() self.assertTrue( len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n126"), URIRef("http://vivoweb.org/ontology/core#end"), None) in sub)
def test_unique_two_add(self): from rdflib import URIRef from testgraph import TestGraph p = Pump("data/grant_dates_def.json") p.original_graph = TestGraph() # In this example, dates are enumerated p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44', u'start_date': u'2006'}} [add, sub] = p.update() self.assertTrue( len(add) == 3 and len(sub) == 0 and (URIRef("http://vivo.school.edu/individual/n44"), URIRef("http://vivoweb.org/ontology/core#dateTimeInterval"), None) in add)