33
44"""Module documentation goes here."""
55
6+ import contextlib
7+ import io
68import os
79import unittest
810
@@ -71,6 +73,26 @@ def test_inbox(self):
7173 tasks = things .inbox ()
7274 self .assertEqual (2 , len (tasks ))
7375
76+ def test_trashed (self ):
77+ """Test getting trashed tasks."""
78+ tasks = things .trash ()
79+ self .assertEqual (5 , len (tasks ))
80+ todos = things .todos (trashed = True )
81+ self .assertEqual (2 , len (todos ))
82+ projects = things .projects (trashed = True )
83+ self .assertEqual (1 , len (projects ))
84+ projects = things .projects (trashed = None )
85+ self .assertEqual (4 , len (projects ))
86+ projects = things .trash (type = "project" )
87+ self .assertEqual (1 , len (projects ))
88+ projects = things .trash (type = "project" , include_items = True )
89+ # TOOD: doesn't inlucde items
90+ # self.assertEqual(1, len(projects[0]["items"]))
91+ # tasks = list(
92+ # filter(lambda _: "in Deleted Project" in _["title"], projects[0]["items"])
93+ # )
94+ # self.assertEqual(1, len(tasks))
95+
7496 def test_upcoming (self ):
7597 """Test upcoming."""
7698 tasks = things .upcoming ()
@@ -84,7 +106,7 @@ def test_deadlines(self):
84106 def test_today (self ):
85107 """Test today."""
86108 tasks = things .today ()
87- self .assertEqual (2 , len (tasks ))
109+ self .assertEqual (3 , len (tasks ))
88110
89111 def test_checklist (self ):
90112 """Test checklist."""
@@ -96,7 +118,7 @@ def test_checklist(self):
96118 def test_anytime (self ):
97119 """Test anytime."""
98120 tasks = things .anytime ()
99- self .assertEqual (11 , len (tasks ))
121+ self .assertEqual (12 , len (tasks ))
100122 self .assertTrue (any (task .get ("area_title" ) == "Area 1" for task in tasks ))
101123
102124 def test_logbook (self ):
@@ -138,6 +160,8 @@ def test_todos(self):
138160 self .assertEqual (10 , len (todos ))
139161 todos = things .todos (include_items = True )
140162 self .assertEqual (12 , len (todos ))
163+ tasks = things .tasks (include_items = True )
164+ self .assertEqual (16 , len (tasks ))
141165 with self .assertRaises (ValueError ):
142166 things .todos (status = "wrong_value" )
143167 todo = things .todos ("A2oPvtt4dXoypeoLc8uYzY" )
@@ -147,18 +171,36 @@ def test_tags(self):
147171 """Test all tags."""
148172 tags = things .tags ()
149173 self .assertEqual (5 , len (tags ))
150- tasks = things .tasks (tag = "Errand" )
151- self .assertEqual (1 , len (tasks ))
174+ tags = things .tags (include_items = True )
175+ self .assertEqual (5 , len (tags ))
176+ tags = things .tasks (tag = "Errand" )
177+ self .assertEqual (1 , len (tags ))
178+ tag = things .tags (title = "Errand" )
179+ self .assertEqual ("Errand" , tag ["title" ])
180+
181+ def test_get_link (self ):
182+ link = things .link ("uuid" )
183+ self .assertEqual ("things:///show?id=uuid" , link )
152184
153185 def test_projects (self ):
154186 """Test all projects."""
155187 projects = things .projects ()
156- self .assertEqual (2 , len (projects ))
188+ self .assertEqual (3 , len (projects ))
189+ projects = things .projects (include_items = True )
190+ self .assertEqual (2 , len (projects [0 ]["items" ]))
157191
158192 def test_areas (self ):
159193 """Test all test_areas."""
160194 areas = things .areas ()
161195 self .assertEqual (3 , len (areas ))
196+ areas = things .areas (include_items = True )
197+ self .assertEqual (3 , len (areas ))
198+ count = things .areas (count_only = True )
199+ self .assertEqual (3 , count )
200+ with self .assertRaises (ValueError ):
201+ things .areas ("wrong-uuid" )
202+ area = things .areas ("Y3JC4XeyGWxzDocQL4aobo" )
203+ self .assertEqual ("Area 3" , area ["title" ])
162204
163205 def test_database_version (self ):
164206 """Test database version."""
@@ -167,18 +209,21 @@ def test_database_version(self):
167209
168210 def test_last (self ):
169211 """Test last parameter"""
170- last_tasks = things .last ("1d " )
212+ last_tasks = things .last ("0d " )
171213 self .assertEqual (len (last_tasks ), 0 )
172214
173215 last_tasks = things .last ("10000w" )
174- self .assertEqual (len (last_tasks ), 15 )
216+ self .assertEqual (len (last_tasks ), 16 )
175217
176218 last_tasks = things .last ("100y" , status = "completed" )
177219 self .assertEqual (len (last_tasks ), 10 )
178220
179221 with self .assertRaises (ValueError ):
180222 things .last (None )
181223
224+ with self .assertRaises (ValueError ):
225+ things .last ([])
226+
182227 with self .assertRaises (ValueError ):
183228 things .last ("XYZ" )
184229
@@ -192,7 +237,6 @@ def test_tasks(self):
192237 """Test tasks"""
193238 count = things .tasks (status = "completed" , last = "100y" , count_only = True )
194239 self .assertEqual (count , 10 )
195-
196240 # special characters
197241 tasks = things .tasks (area = '"' )
198242 self .assertEqual (len (tasks ), 0 )
@@ -203,6 +247,20 @@ def test_tasks(self):
203247 with self .assertRaises (ValueError ):
204248 things .tasks (area = "\0 " )
205249
250+ def test_database (self ):
251+ """Test some database details"""
252+ output = io .StringIO ()
253+ with contextlib .redirect_stdout (output ):
254+ db = things .api .pop_database ({})
255+ db .debug = True
256+ db .get_tags ()
257+ self .assertTrue ("H96sVJwE7VJveAnv7itmux" in output .getvalue ())
258+ with contextlib .redirect_stdout (output ):
259+ things .areas (print_sql = True )
260+ self .assertTrue ("ORDER BY" in output .getvalue ())
261+ with self .assertRaises (SystemExit ): # noqa TODO: should actually NOT crash
262+ db .execute_query ('"' )
263+
206264
207265if __name__ == "__main__" :
208266 unittest .main ()
0 commit comments