Repository: pimutils/todoman
Pull request #138 (2017-02-24 17:34:27)

Increment sequence number upon edition
Increment sequence number upon edition.a variable y is taken and value of self.todo['SEQUENCE'] is taken in this variable . value of y is checked and if it is none then value of y is set to 0 and if not then value of sequence is incremented by one


untitaker: Looks good to me! Please add a testcase in `test_model.py`, a changelog entry and yourself to AUTHORS. Thanks!
Sakshisaraswat: ok i will make changes
Sakshisaraswat: Please tell me how to write test cases?
hobarrera: I took the liberty of fixing merge conflicts, but the prior review is still pending.

Patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index fdd7101..c133897 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -20,5 +20,6 @@ Authors are listed in alphabetical order.
 * Markus Unterwaditzer <markus@unterwaditzer.net>
 * Paweł Fertyk <pfertyk@openmailbox.org>
 * Rimsha Khan <rimshakhan.rk03@gmail.com>
+* Sakshi Saraswat <saraswatsakshi.121@gmail.com>
 * Swati Garg <swati4star@gmail.com>
 * Thomas Glanzmann <thomas@glanzmann.de>
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 36541b9..228fd0b 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -21,7 +21,7 @@ v3.0.0
 * Make the output of move, delete, copy and flush more consistent with
   everything else.
 * Porcelain now outputs proper JSON, rather than one-JSON-per-line.
-
+* Increment sequence number upon edits.
 
 v2.1.0
 ------
diff --git a/todoman/model.py b/todoman/model.py
index 0d31c72..b978952 100644
--- a/todoman/model.py
+++ b/todoman/model.py
@@ -322,7 +322,8 @@ class FileTodo(Todo):
         list_ = list_ or self.list
         path = os.path.join(list_.path, self.filename)
         assert path.startswith(list_.path)
-
+        sequence = self.todo.get('SEQUENCE', 0)
+        self.todo['SEQUENCE'] = sequence + 1
         if os.path.exists(path):
             # Update an existing entry:
             with open(path, 'rb') as f:


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index d67e01d..a8846a2 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -1,8 +1,12 @@
 from datetime import datetime
 
+import icalendar
+
 from dateutil.tz.tz import tzoffset
 
 from todoman.model import Database
+from todoman.model import FileTodo
+from todoman.model import List
 
 
 def test_querying(create, tmpdir):
@@ -66,3 +70,29 @@ def test_change_paths(tmpdir, create):
 
     assert len(list(db.lists())) == 1
     assert not list(db.todos())
+
+
+def test_sequence_increment(tmpdir):
+    default_dir = tmpdir.mkdir("default")
+
+    todo = FileTodo()
+    _list = List("default", str(default_dir))
+    todo.save(_list)
+
+    filename = default_dir.join(todo.filename)
+
+    cal = icalendar.Calendar.from_ical(filename.read())
+    sequence, = [component.get("SEQUENCE", 0)
+                 for component in cal.subcomponents
+                 if component.name == "VTODO"]
+
+    assert sequence == 1
+
+    todo.save(_list)
+
+    cal = icalendar.Calendar.from_ical(filename.read())
+    sequence, = [component.get("SEQUENCE", 0)
+                 for component in cal.subcomponents
+                 if component.name == "VTODO"]
+
+    assert sequence == 2