-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add graph store HTTP protocol #27
Conversation
aiosparql/client.py
Outdated
@@ -178,6 +185,37 @@ def _pretty_print_query(self, query: str) -> str: | |||
explanation=explanation) | |||
return await resp.json() | |||
|
|||
def _crud_request(self, method, graph=None, data=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is data
parameter for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks it it's never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP body.
The graph store protocol is basically a crud endpoint where you post/delete/get raw data in any format you want (RDF XML, Turtle, etc...).
Just realized now that there is no parameter to set the format. Maybe I should start adding integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. Yes integration test would be very useful at this point.
Codecov Report
@@ Coverage Diff @@
## master #27 +/- ##
==========================================
+ Coverage 96.14% 96.29% +0.15%
==========================================
Files 5 5
Lines 363 405 +42
==========================================
+ Hits 349 390 +41
- Misses 14 15 +1
Continue to review full report at Codecov.
|
aiosparql/client.py
Outdated
async with self._crud_request("PATCH", graph=graph, data=data, | ||
accept="application/json") as resp: | ||
resp.raise_for_status() | ||
return await resp.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this code. According to the specs, the PATCH method is like an endpoint for SPARQL 1.1 update:
SPARQL 1.1 Update can be used as a patch document.
I suppose that without being able to really test it I should simply remove the code for now or raise NotImplementedError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
If you are not sure about implementation -- just drop the method and wait for feature request with real use case.
aiosparql/client.py
Outdated
resp.raise_for_status() | ||
|
||
def head(self, *, format: str, graph: Optional[IRI] = None): | ||
return self._crud_request("HEAD", graph=graph, accept=format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this code. According to the specs, the HEAD method does the exact same thing than GET but does not return content. So I suppose the format should be supplied by the client...
the HTTP HEAD method is identical to GET except that the server MUST NOT return a message-body in the response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't follow
tests/integration/test_client.py
Outdated
text = await res.text() | ||
self.assertIn("@prefix", text) | ||
async with await self.client.head(format="text/turtle") as res: | ||
self.assertIn(res.status, (200, 501)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love doing integration test with a server that does not implement everything...
tests/integration/test_client.py
Outdated
self.assertIsInstance(res, dict) | ||
except aiohttp.ClientResponseError as exc: | ||
if exc.code != 501: | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATCH is apparently not implemented either by Virtuoso.
61d9c87
to
9bbe7e7
Compare
@asvetlov ready for your review :) I will probably release after this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead.
The only note: could you consider adding a fixture for running virtuoso
container by pytest fixture later?
It simplifies local tests run I guess.
aiosparql/client.py
Outdated
resp.raise_for_status() | ||
|
||
def head(self, *, format: str, graph: Optional[IRI] = None): | ||
return self._crud_request("HEAD", graph=graph, accept=format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't follow
aiosparql/client.py
Outdated
async with self._crud_request("PATCH", graph=graph, data=data, | ||
accept="application/json") as resp: | ||
resp.raise_for_status() | ||
return await resp.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
If you are not sure about implementation -- just drop the method and wait for feature request with real use case.
@asvetlov Yes I can spawn a container for virtuoso... would be simpler to use I suppose... but this doesn't look like it belongs to the test file itself. I guess I could make a "ci" directory with a start and stop script. Does that sound good/better/less good? |
9bbe7e7
to
c9208e5
Compare
I forgot you use It's up to you, you are the library author. After that you could add code like used by aiopg: https://github.com/aio-libs/aiopg/blob/master/tests/conftest.py#L105-L194 It tests DB client against several Postgres versions by providing a fixture for container start and other fixture for making client connected to started DB server. |
Maybe you'll find the trick useful for aiosparql too. |
@asvetlov I think I will keep the idea for later for a new PR. I don't mind much having py.test or unittest tests (even a mix of them) as long as the coverage is good and the code is well tested. It's never too late to change and besides this library is very very small because it's SPARQL: this lib only needs to respect the specifications of SPARQL and HTTP; the server it connects to doesn't really matter. I have worked with PostgreSQL too and I know for sure this is very very different. Overall, this library is some kind of helper to make HTTP requests (at least for Now the syntax helpers are more complicated: in SPARQL every value has a scheme for the type and maybe a language if it's a literal, plus depending on the server, the type you specify may not be the type you will get in the database itself... escaping SPARQL is a hell and that's the main purpose of One thing is missing (somehow deliberately) in this library: parsing the SPARQL result and make internal objects. Most of the libraries I know does it but, to be honest, when you use JSON, I just don't find that very useful. So right now I keep an open door for it for later if someone or myself wants to implement something at some point. It's just not my priority. |
Specifications at https://www.w3.org/TR/sparql11-http-rdf-update/#graph-management