@@ -1930,6 +1930,53 @@ def testInsertDataAndSelectFromNonEmptyGraph(self):
19301930 "p" : {'type' : 'uri' , 'value' : 'http://ex.org/b' },
19311931 "o" : {'type' : 'uri' , 'value' : 'http://ex.org/c' }})
19321932
1933+ def testInsertDataIntoRepositoryDontOverwriteLocalFile (self ):
1934+ """Test inserting data wile locally changing the graph file.
1935+
1936+ 1. Prepare a repository
1937+ 2. Start Quit
1938+ 3. execute INSERT DATA query
1939+ 4. change file in filesystem
1940+ """
1941+ # Prepate a git Repository
1942+ graphContent = '<http://ex.org/x> <http://ex.org/y> <http://ex.org/z> .\n '
1943+ with TemporaryRepositoryFactory ().withGraph ("http://example.org/" , graphContent ) as repo :
1944+
1945+ # Start Quit
1946+ args = quitApp .parseArgs (['-t' , repo .workdir ])
1947+ objects = quitApp .initialize (args )
1948+ config = objects ['config' ]
1949+ app = create_app (config ).test_client ()
1950+
1951+ with open (path .join (repo .workdir , "graph.nt" ), "w" ) as graphFile :
1952+ graphContent += '<http://ex.org/z> <http://ex.org/z> <http://ex.org/z> .\n '
1953+ graphFile .write (graphContent )
1954+
1955+ # execute INSERT DATA query
1956+ update = "INSERT DATA {graph <http://example.org/> {<http://ex.org/a> <http://ex.org/b> <http://ex.org/c> .}}"
1957+ app .post ('/sparql' , data = dict (update = update ))
1958+
1959+ # execute SELECT query
1960+ select = "SELECT * WHERE {graph <http://example.org/> {?s ?p ?o .}} ORDER BY ?s ?p ?o"
1961+ select_resp = app .post ('/sparql' , data = dict (query = select ), headers = dict (accept = "application/sparql-results+json" ))
1962+
1963+ obj = json .loads (select_resp .data .decode ("utf-8" ))
1964+
1965+ self .assertEqual (len (obj ["results" ]["bindings" ]), 2 )
1966+
1967+ self .assertDictEqual (obj ["results" ]["bindings" ][0 ], {
1968+ "s" : {'type' : 'uri' , 'value' : 'http://ex.org/a' },
1969+ "p" : {'type' : 'uri' , 'value' : 'http://ex.org/b' },
1970+ "o" : {'type' : 'uri' , 'value' : 'http://ex.org/c' }})
1971+
1972+ self .assertDictEqual (obj ["results" ]["bindings" ][1 ], {
1973+ "s" : {'type' : 'uri' , 'value' : 'http://ex.org/x' },
1974+ "p" : {'type' : 'uri' , 'value' : 'http://ex.org/y' },
1975+ "o" : {'type' : 'uri' , 'value' : 'http://ex.org/z' }})
1976+
1977+ with open (path .join (repo .workdir , "graph.nt" ), "r" ) as graphFile :
1978+ self .assertEqual (graphFile .read (), graphContent )
1979+
19331980 def testInsertDeleteFromEmptyGraph (self ):
19341981 """Test inserting and deleting data and selecting it, starting with an empty graph.
19351982
0 commit comments