Repository: pimutils/todoman
Pull request #271 (2017-08-31 20:49:45)

Location fixes
Well, that wasn't particularly hard...


Patch:
diff --git a/contrib/completion/bash/_todo b/contrib/completion/bash/_todo
index c6e5f5e..df3ca7c 100644
--- a/contrib/completion/bash/_todo
+++ b/contrib/completion/bash/_todo
@@ -12,7 +12,7 @@ _todo_get_lists()
 
 _todo_get_locations()
 {
-	local pattern='^\s*"location": \([0-9]\)\+,'
+	local pattern='^\s*"location": \(.*\)\+,'
 	todo --porcelain list | grep -o "${pattern}" | sed -e "s/${pattern}/\1/" | sort | uniq
 }
 
diff --git a/todoman/formatters.py b/todoman/formatters.py
index 980baa9..2cef306 100644
--- a/todoman/formatters.py
+++ b/todoman/formatters.py
@@ -213,6 +213,7 @@ class PorcelainFormatter(DefaultFormatter):
             percent=todo.percent_complete,
             summary=todo.summary,
             priority=todo.priority,
+            location=todo.location,
         )
 
     def compact(self, todo):
diff --git a/todoman/model.py b/todoman/model.py
index 45729e1..0819e2a 100644
--- a/todoman/model.py
+++ b/todoman/model.py
@@ -7,7 +7,6 @@ from os.path import normpath, split
 from uuid import uuid4
 
 import icalendar
-import pytz
 from atomicwrites import AtomicWriter
 from dateutil.rrule import rrulestr
 from dateutil.tz import tzlocal
@@ -277,11 +276,6 @@ class VtodoWritter:
 
         - Convert everything to datetime
         - Add missing timezones
-        - Cast to UTC
-
-        Datetimes are cast to UTC because icalendar doesn't include the
-        VTIMEZONE information upon serialization, and some clients have issues
-        dealing with that.
         '''
         if isinstance(dt, date) and not isinstance(dt, datetime):
             dt = datetime(dt.year, dt.month, dt.day)
@@ -289,7 +283,7 @@ class VtodoWritter:
         if not dt.tzinfo:
             dt = dt.replace(tzinfo=LOCAL_TIMEZONE)
 
-        return dt.astimezone(pytz.UTC)
+        return dt
 
     def serialize_field(self, name, value):
         if name in Todo.RRULE_FIELDS:


Test patch:
diff --git a/tests/test_backend.py b/tests/test_backend.py
index 02c2009..19e0f1b 100644
--- a/tests/test_backend.py
+++ b/tests/test_backend.py
@@ -9,14 +9,6 @@ from freezegun import freeze_time
 from todoman.model import Todo, VtodoWritter
 
 
-def test_datetime_serialization(todo_factory, tmpdir):
-    now = datetime(2017, 8, 31, 23, 49, 53, tzinfo=pytz.UTC)
-    todo = todo_factory(created_at=now)
-    filename = tmpdir.join('default').join(todo.filename)
-    with open(str(filename)) as f:
-        assert 'CREATED;VALUE=DATE-TIME:20170831T234953Z\n' in f.readlines()
-
-
 def test_serialize_created_at(todo_factory):
     now = datetime.now(tz=pytz.UTC)
     todo = todo_factory(created_at=now)
diff --git a/tests/test_model.py b/tests/test_model.py
index 5d82048..5516f24 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -8,7 +8,7 @@ from dateutil.tz.tz import tzoffset
 from freezegun import freeze_time
 
 from todoman.exceptions import AlreadyExists
-from todoman.model import cached_property, Database, List, Todo
+from todoman.model import Database, List, Todo
 
 
 def test_querying(create, tmpdir):
@@ -420,47 +420,3 @@ def test_unreadable_ics(todo_factory, todos, tmpdir):
 
     assert len(todos) == 1
     assert mocked_exception.call_count == 1
-
-
-def test_cached_property_caching():
-    class TestClass:
-        i = 0
-
-        @cached_property
-        def a(self):
-            TestClass.i += 1
-            return TestClass.i
-
-    obj = TestClass()
-    assert obj.a == 1
-    assert obj.a == 1
-    assert obj.a == 1
-
-
-def test_cached_property_overwriting():
-    class TestClass:
-        i = 0
-
-        @cached_property
-        def a(self):
-            TestClass.i += 1
-            return TestClass.i
-
-    obj = TestClass()
-
-    # Overriting will overwrite the cached_property:
-    obj.a = 12
-    assert obj.a == 12
-    assert obj.a == 12
-
-    obj.a += 1
-    assert obj.a == 13
-
-
-def test_cached_property_property():
-    class TestClass:
-        @cached_property
-        def a(self):
-            return 0
-
-    assert TestClass.a.__class__ == cached_property
diff --git a/tests/test_porcelain.py b/tests/test_porcelain.py
index 8a3e210..0bbf1ec 100644
--- a/tests/test_porcelain.py
+++ b/tests/test_porcelain.py
@@ -14,6 +14,7 @@ def test_list_all(tmpdir, runner, create):
         'STATUS:COMPLETED\n'
         'DUE;VALUE=DATE-TIME;TZID=CET:20160102T000000\n'
         'PERCENT-COMPLETE:26\n'
+        'LOCATION:Wherever\n'
     )
     result = runner.invoke(cli, ['--porcelain', 'list', '--status', 'ANY'])
 
@@ -22,6 +23,7 @@ def test_list_all(tmpdir, runner, create):
         'due': 1451689200,
         'id': 1,
         'list': 'default',
+        'location': 'Wherever',
         'percent': 26,
         'priority': 0,
         'summary': 'Do stuff',
@@ -46,6 +48,7 @@ def test_list_nodue(tmpdir, runner, create):
         'due': None,
         'id': 1,
         'list': 'default',
+        'location': '',
         'percent': 12,
         'priority': 4,
         'summary': 'Do stuff',
@@ -132,6 +135,7 @@ def test_show(tmpdir, runner, create):
         'due': None,
         'id': 1,
         'list': 'default',
+        'location': '',
         'percent': 0,
         'priority': 5,
         'summary': 'harhar',
@@ -151,6 +155,7 @@ def test_simple_action(todo_factory):
         "due": None,
         "id": 7,
         "list": "default",
+        "location": "Downtown",
         "percent": 0,
         "priority": 0,
         "summary": "YARR!"