1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
#
###############################################################################
import sys
import os
import unittest
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase, Taskd, ServerTestCase
class TestDefaultProject(TestCase):
"""Bug 1023: rc.default.project gets applied during modify, and should not
"""
def setUp(self):
self.t = Task()
def set_default_project(self):
self.default_project = "HOMEPROJ"
self.t.config("default.project", self.default_project)
def test_with_project(self):
"""default.project not applied when specified nor on attribute removal
"""
self.set_default_project()
self.t("add foobar project:garden")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
expected = "Project\s+garden"
self.assertRegexpMatches(out, expected)
self.t("1 modify project:")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
self.assertNotRegexpMatches(out, expected)
notexpected = "Project\s+" + self.default_project
self.assertNotRegexpMatches(out, notexpected)
def test_without_project(self):
"""default.project applied when no project is specified"""
self.set_default_project()
self.t("add foobar")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
expected = "Project\s+" + self.default_project
self.assertRegexpMatches(out, expected)
def test_default_project_inline_override(self):
"""no project applied when default.project is overridden"""
self.set_default_project()
self.t("add foobar rc.default.project=")
code, out, err = self.t("1", "info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
def test_without_default_project(self):
"""no project applied when default.project is blank"""
self.t("add foobar")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
def test_modify_default_project(self):
"""default.project is not applied when modifying a task"""
self.t("add foobar")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
self.set_default_project()
self.t("1 modify +tag")
code, out, err = self.t("1", "info")
self.assertNotIn("Project", out)
def test_annotate_default_project(self):
"""default.project is not applied when annotating a task"""
self.t("add foobar")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
self.set_default_project()
self.t("1 annotate Hello")
code, out, err = self.t("1 info")
expected = "Description\s+foobar\n[0-9-: ]+ Hello"
self.assertRegexpMatches(out, expected)
self.assertNotIn("Project", out)
def test_time_default_project(self):
"""default.project is not applied when start/stop'ing a task"""
# Allow keeping track of time spent on task
self.t.config("journal.time", "yes")
self.t("add foobar")
code, out, err = self.t("1 info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
self.set_default_project()
self.t("1 start")
self.t("1 stop")
code, out, err = self.t("1", "info")
self.assertIn("foobar", out)
self.assertNotIn("Project", out)
def test_recurring_parent_default_project(self):
"""default.project is applied on recurring parent tasks"""
self.set_default_project()
DESC = "foobar"
self.t(('add', 'recur:daily', 'due:today', DESC))
self.t() # Ensure creation of recurring children
code, out, err = self.t("1 info")
self.assertIn(DESC, out)
self.assertRegexpMatches(out, "Status\s+Recurring") # is a parent task
self.assertIn(self.default_project, out)
self.t.faketime("+1d")
self.t() # Ensure creation of recurring children
# Try to figure out the ID of last created task
code, out, err = self.t("count")
# Will fail if some other message is printed as part of "count"
id = out.split()[-1]
try:
id = int(id)
except ValueError:
raise ValueError("Unexpected output when running 'task count', "
"expected int, got '{0}'".format(id))
else:
# parent task is not considered when counting
id = str(id + 1)
code, out, err = self.t(id, "info")
self.assertIn(DESC, out)
self.assertIn("Parent task", out) # is a child task
self.assertIn(self.default_project, out)
def test_recurring_default_project(self):
"""no project is applied on recurring tasks"""
# NOTE - reported on TW-1279
DESC = "foobar"
self.t(('add', 'recur:daily', 'due:today', DESC))
code, out, err = self.t()
self.assertIn(DESC, out)
self.assertNotIn("Project", out)
self.set_default_project()
self.t.faketime("+1d")
code, out, err = self.t()
self.assertIn(DESC, out)
self.assertNotIn("Project", out)
def test_recurring_with_project_and_default_project(self):
"""default.project is not applied to children if parent has a project
"""
# NOTE - reported on TW-1279
self.set_default_project()
DESC = "foobar"
self.t(('add', 'recur:daily', 'due:today', 'project:HELLO', DESC))
code, out, err = self.t()
self.assertIn(DESC, out)
self.assertIn("HELLO", out)
self.t.faketime("+1d")
code, out, err = self.t()
self.assertIn("foobar", out)
self.assertIn("HELLO", out)
self.assertNotIn(self.default_project, out)
class ServerTestDefaultProject(ServerTestCase):
@classmethod
def setUpClass(cls):
cls.taskd = Taskd()
# This takes a while...
cls.taskd.start()
def setUp(self):
self.t1 = Task(taskd=self.taskd)
self.t2 = Task(taskd=self.taskd)
self.t3 = Task(taskd=self.taskd)
def test_default_project_sync(self):
"""default.project is not applied to projectless tasks during sync"""
# NOTE - reported on TW-1287
desc = "Testing task"
self.t1(("add", desc))
self.t1("sync")
code, out, err = self.t1()
self.assertIn(desc, out)
# Testing scenario - default.project is applied on task arrival
proj2 = "Client2"
self.t2.config("default.project", proj2)
self.t2("sync")
code, out, err = self.t2()
self.assertIn(desc, out)
self.assertNotIn(proj2, out)
self.t2("sync")
# Testing scenario - default.project is applied on task delivery
proj3 = "Client3"
self.t3.config("default.project", proj3)
self.t3("sync")
code, out, err = self.t3()
self.assertIn(desc, out)
self.assertNotIn(proj2, out)
self.assertNotIn(proj3, out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4 ft=python
|