Skip to content

Commit

Permalink
fixed errors found during tests writing
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 committed Sep 30, 2023
1 parent 0cbee1a commit b9882ad
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions nc_py_api/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ 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]

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

Expand Down Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions tests/actual_tests/notes_test.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)

0 comments on commit b9882ad

Please sign in to comment.