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
|
#!/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
class TestUUID(TestCase):
def setUp(self):
self.t = Task()
self.t.config("dateformat", "m/d/Y")
self.t("import -", input="""[
{"description":"one", "entry":"1315260230", "status":"pending", "uuid":"9deed7ca-843d-4259-b2c4-40ce73e8e4f3"},
{"description":"two", "entry":"1315260230", "status":"pending", "uuid":"0f4c83d2-552f-4108-ae3f-ccc7959f84a3"},
{"description":"three", "entry":"1315260230", "status":"pending", "uuid":"aa4abef1-1dc5-4a43-b6a0-7872df3094bb"},
{"description":"four", "end":"1315260230", "entry":"1315260230", "status":"completed", "uuid":"ea3b4822-574c-464b-8025-7f7be9f3cc57"},
{"description":"ssttaarrtt", "entry":"1315335826", "start":"1315338535", "status":"pending", "uuid":"d71d3566-7a6b-4c32-8f0b-6de75bb9397b"},
{"description":"five", "end":"1315260230", "entry":"1315260230", "status":"completed", "uuid":"0f38b97e-3081-4e75-a1be-65ed3712ea4d"},
{"description":"six", "end":"1315338826", "entry":"1315338726", "status":"completed", "uuid":"12345678-1234-1234-1234-123456789012"},
{"description":"seven", "end":"1315338826", "entry":"1315338726", "status":"completed", "uuid":"abcdefab-abcd-abcd-abcd-abcdefabcdef"},
{"description":"eenndd", "end":"1315335841", "entry":"1315335841", "start":"1315338516", "status":"completed", "uuid":"727baa6c-65b8-485e-a810-e133e3cd83dc"},
{"description":"UUNNDDOO", "end":"1315338626", "entry":"1315338626", "status":"completed", "uuid":"c1361003-948e-43e8-85c8-15d28dc3c71c"}
]""")
def _config_unittest_report(self):
self.t.config("report.unittest.columns", "id,entry,start,description")
self.t.config("report.unittest.filter", "status:pending")
self.t.config("report.unittest.sort", "id")
def test_uuid_modify_pending(self):
"""Modify with UUID + report pending"""
self.t("9deed7ca-843d-4259-b2c4-40ce73e8e4f3 modify ONE")
self.t("2 modify TWO")
code, out, err = self.t("list")
self.assertIn("ONE", out)
self.assertIn("TWO", out)
self.assertIn("three", out)
self.assertIn("ssttaarrtt", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
self.assertNotIn("eenndd", out)
self.assertNotIn("UUNNDDOO", out)
def test_uuid_modify_completed(self):
"""Modify with UUID + report completed"""
self.t("ea3b4822-574c-464b-8025-7f7be9f3cc57 modify FOUR")
code, out, err = self.t("completed")
self.assertNotIn("ONE", out)
self.assertNotIn("TWO", out)
self.assertNotIn("three", out)
self.assertNotIn("ssttaarrtt", out)
self.assertIn("FOUR", out)
self.assertIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
self.assertIn("eenndd", out)
self.assertIn("UUNNDDOO", out)
def test_uuid_modify_status(self):
"""Modify status: with UUID"""
self.t("c1361003-948e-43e8-85c8-15d28dc3c71c modify status:pending")
code, out, err = self.t("list")
self.assertIn("UUNNDDOO", out)
code, out, err = self.t("completed")
self.assertNotIn("UUNNDDOO", out)
def test_uuid_modify_start(self):
"""Modify start: with UUID"""
self._config_unittest_report()
self.t("d71d3566-7a6b-4c32-8f0b-6de75bb9397b modify start:12/31/2010")
code, out, err = self.t("unittest")
self.assertIn("12/31/2010", out)
def test_uuid_modify_end(self):
"""Modify end: with UUID"""
self.t("727baa6c-65b8-485e-a810-e133e3cd83dc modify end:12/31/2010")
code, out, err = self.t("completed")
self.assertIn("12/31/2010", out)
def test_uuid_modify_start_end(self):
"""Modify start: and end: with UUID"""
self._config_unittest_report()
self.t("aa4abef1-1dc5-4a43-b6a0-7872df3094bb modify entry:12/30/2010")
self.t("aa4abef1-1dc5-4a43-b6a0-7872df3094bb modify start:1/1/2011")
code, out, err = self.t("unittest")
self.assertIn("12/30/2010", out)
self.assertIn("1/1/2011", out)
def test_numerical_uuid(self):
"""Using numerical UUID"""
# NOTE: Reported on TW-1636
self.t("12345678-1234-1234-1234-123456789012 modify status:completed")
code, out, err = self.t("_get 12345678-1234-1234-1234-123456789012.status")
self.assertIn("completed\n", out)
code, out, err = self.t("12345678-1234-1234-1234-123456789012 export")
self.assertIn('"description":"six"', out)
def test_numerical_short_uuid(self):
"""Using numerical UUID in the short form"""
# NOTE: Reported on TW-1636
self.t("12345678 modify status:pending")
code, out, err = self.t("_get 12345678.status")
self.assertIn("pending\n", out)
code, out, err = self.t("12345678 export")
self.assertIn('"description":"six"', out)
def test_alpha_uuid(self):
"""Using alphabetic UUID"""
# NOTE: complement numerical only reported on TW-1636
self.t("abcdefab-abcd-abcd-abcd-abcdefabcdef modify status:completed")
code, out, err = self.t("_get abcdefab-abcd-abcd-abcd-abcdefabcdef.status")
self.assertIn("completed\n", out)
code, out, err = self.t("abcdefab-abcd-abcd-abcd-abcdefabcdef export")
self.assertIn('"description":"seven"', out)
def test_alpha_short_uuid(self):
"""Using alphabetic UUID in the short form"""
# NOTE: complement numerical only reported on TW-1636
self.t("abcdefab modify status:pending")
code, out, err = self.t("_get abcdefab.status")
self.assertIn("pending\n", out)
code, out, err = self.t("abcdefab export")
self.assertIn('"description":"seven"', out)
class TestUUIDuplicates(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_uuid_duplicates(self):
"""Verify that duplicating tasks, and recurring tasks do no create duplicates UUIDs"""
self.t("add simple")
self.t("1 duplicate")
self.t("add periodic recur:daily due:yesterday")
self.t("list") # GC/handleRecurrence
uuids = list()
for id in range(1,7):
code, out, err = self.t("_get %d.uuid" % id)
uuids.append(out.strip())
self.assertEqual(len(uuids), len(set(uuids)))
code, out, err = self.t("diag")
self.assertIn("No duplicates found", out)
class TestBug954(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
self.t("add foo")
def test_deletion_by_uuid(self):
"""954: Verify deletion using extant UUID"""
code, out, err = self.t("_get 1.uuid")
code, out, err = self.t(out.strip() + " delete", input="y\n")
self.assertIn("Deleting task 1 'foo'", out)
def test_deletion_by_missing_uuid(self):
"""954: Verify deletion using missing UUID"""
code, out, err = self.t.runError("874e146d-07a2-2d2c-7808-a76e74b1a332 delete")
self.assertIn("No tasks specified.", err)
class TestFeature891(TestCase):
@classmethod
def setUp(self):
self.t = Task()
self.t("add one")
self.t("add two")
# Sometimes this test fails because the 1.uuid starts with N hex digits
# such that those digits are all in the range [0-9], and therefore the
# UUID looks like an integer.
#
# The only solution that comes to mind is to repeat self.t("add one")
# until 1.uuid contains at least one [a-f] in the first N digits.
code, self.uuid, err = self.t("_get 1.uuid")
self.uuid = self.uuid.strip()
def test_uuid_filter(self):
"""891: Test that a task is addressable using UUIDs of length 7 - 36"""
for i in range(35,7,-1):
code, out, err = self.t(self.uuid[0:i] + " list")
self.assertIn("one", out)
self.assertNotIn("two", out)
# TODO This should fail because a 7-character UUID is not a UUID, but
# instead it blindly does nothing, and succeeds. Voodoo.
#code, out, err = self.t(self.uuid[0:6] + " list")
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4 ft=python
|