Skip to content

Commit

Permalink
Sort tags in get_note / update_note
Browse files Browse the repository at this point in the history
Had this as a TODO in simplenote.vim:

https://github.com/mrtazz/simplenote.vim/blob/29d52cc5a15af2b3dd357ab5610148af0e350152/autoload/SimplenoteUtilities.py#L728

I.e. Needed to move the sorting to simplenote.py

I don't think there is a problem in sorting in update as well as get.
Added a test, but since the update is also getting sorted the test is
pretty much checking both at the same time.
  • Loading branch information
atomicules committed Mar 24, 2018
1 parent 2e1e030 commit a625189
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion simplenote/simplenote.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,16 @@ def __encode(self, note):
else:
note["content"] = html.unescape(note["content"])

# Sort tags
# For early versions of notes, tags not always available
if "tags" in note:
note["tags"] = sorted(note["tags"])

if sys.version_info < (3, 0):
if "content" in note:
# use UTF-8 encoding
note["content"] = note["content"].encode('utf-8')
# For early versions of notes, tags not always available
# For early versions of notes, tags not always available
if "tags" in note:
note["tags"] = [t.encode('utf-8') for t in note["tags"]]
return note
Expand Down
7 changes: 7 additions & 0 deletions tests/test_simplenote.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def test_simplenote_add_note_object(self):
if status == 0:
self.assertEqual("new note", note["content"])

def test_simplenote_tags_sorted(self):
res, status = self.simplenote_instance.add_note({"content": "A note with tags in any order.", "tags": ["cat", "dog", "ant"]})
if status == 0:
note, status = self.simplenote_instance.get_note(res["key"])
if status == 0:
self.assertEqual(["ant", "cat", "dog"], note["tags"])

def test_simplenote_add_note_content(self):
res, status = self.simplenote_instance.add_note("new note")
if status == 0:
Expand Down

0 comments on commit a625189

Please sign in to comment.