diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 15dfb68e..0e626846 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -531,6 +531,7 @@ jobs: ./occ config:system:set loglevel --value=0 --type=integer ./occ config:system:set debug --value=true --type=boolean ./occ app:enable notifications + ./occ app:enable notes php -S localhost:8080 & - name: Checkout NcPyApi diff --git a/nc_py_api/notes.py b/nc_py_api/notes.py index f39f3ab0..a5621f8c 100644 --- a/nc_py_api/notes.py +++ b/nc_py_api/notes.py @@ -133,7 +133,7 @@ def get_list( } clear_from_params_empty(list(params.keys()), params) headers = {"If-None-Match": self.last_etag} if self.last_etag and etag else {} - r = self._session.request_json("GET", self._ep_base + "/notes", json=params, headers=headers) + r = self._session.request_json("GET", self._ep_base + "/notes", params=params, headers=headers) self.last_etag = self._session.response_headers["ETag"] return [Note(i) for i in r] @@ -141,7 +141,7 @@ def by_id(self, note: Note) -> Note: """Get updated information about :py:class:`~nc_py_api.notes.Note`.""" require_capabilities("notes", self._session.capabilities) r = self._session.request_json( - "GET", self._ep_base + f"/notes/{note.note_id}", headers={"If-None-Match": note.etag} + "GET", self._ep_base + f"/notes/{note.note_id}", headers={"If-None-Match": f'"{note.etag}"'} ) return Note(r) if r else note @@ -179,7 +179,7 @@ def update( ``overwrite`` specifies should be or not the Note updated even if it was changed on server(has different ETag). """ require_capabilities("notes", self._session.capabilities) - headers = {"If-None-Match": note.etag} if overwrite else {} + headers = {"If-Match": f'"{note.etag}"'} if not overwrite else {} params = { "title": title, "content": content, diff --git a/tests/actual_tests/notes_test.py b/tests/actual_tests/notes_test.py index 5bf8f923..5770c5a0 100644 --- a/tests/actual_tests/notes_test.py +++ b/tests/actual_tests/notes_test.py @@ -1,5 +1,9 @@ +from datetime import datetime + import pytest +from nc_py_api import NextcloudException + # Currently we test only with the client mode, waiting this to be resolved to use it in Application mode: # https://github.com/cloud-py-api/app_api/issues/80 @@ -18,3 +22,53 @@ def test_settings(nc_client): nc_client.notes.set_settings(file_suffix=original_settings["file_suffix"]) modified_settings = nc_client.notes.get_settings() assert modified_settings["file_suffix"] == original_settings["file_suffix"] + + +def test_create_delete(nc_client): + if nc_client.notes.available is False: + pytest.skip("Notes is not installed") + unix_timestamp = (datetime.utcnow() - datetime(1970, 1, 1)).total_seconds() + new_note = nc_client.notes.create(str(unix_timestamp)) + nc_client.notes.delete(new_note) + assert isinstance(new_note.note_id, int) + assert isinstance(new_note.etag, str) + assert isinstance(new_note.title, str) + assert isinstance(new_note.content, str) + assert isinstance(new_note.category, str) + assert new_note.readonly is False + assert new_note.favorite is False + assert isinstance(new_note.last_modified, datetime) + + +def test_get_update_note(nc_client): + if nc_client.notes.available is False: + pytest.skip("Notes is not installed") + + for i in nc_client.notes.get_list(): + nc_client.notes.delete(i) + + assert not nc_client.notes.get_list() + unix_timestamp = (datetime.utcnow() - datetime(1970, 1, 1)).total_seconds() + new_note = nc_client.notes.create(str(unix_timestamp)) + try: + all_notes = nc_client.notes.get_list() + assert all_notes[0] == new_note + assert not nc_client.notes.get_list(etag=True) + assert nc_client.notes.get_list()[0] == new_note + assert nc_client.notes.by_id(new_note) == new_note + updated_note = nc_client.notes.update(new_note, content="content") + assert updated_note.content == "content" + all_notes = nc_client.notes.get_list() + assert all_notes[0].content == "content" + all_notes_no_content = nc_client.notes.get_list(no_content=True) + assert all_notes_no_content[0].content == "" + assert nc_client.notes.by_id(new_note).content == "content" + with pytest.raises(NextcloudException): + assert nc_client.notes.update(new_note, content="should be rejected") + new_note = nc_client.notes.update(new_note, content="should not be rejected", overwrite=True) + nc_client.notes.update(new_note, category="test_category", favorite=True) + new_note = nc_client.notes.by_id(new_note) + assert new_note.favorite is True + assert new_note.category == "test_category" + finally: + nc_client.notes.delete(new_note)