1. Wayne Werner
  2. Boog Slayer

Source

Boog Slayer / tests.py

  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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
import os
import pdb
import time
import mock
import unittest
import contextlib

import slayer

from datetime import datetime

class TaskTest(unittest.TestCase):
    def test_whenTaskIsCreatedWithDescItShouldBeSet(self):
        task = slayer.Task(desc="Nothing happened...")
        self.assertEqual("Nothing happened...", task.desc)

    def test_whenTaskIsCreatedWithNoIdItShouldBeNone(self):
        task = slayer.Task()
        self.assertEqual(None, task.id)

    def test_whenTaskIsCreatedWithNoDescItShouldBeNone(self):
        task = slayer.Task()
        self.assertEqual(None, task.desc)

    def test_whenTaskIsCreatedAndIdAlreadyExistsItShouldValueError(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedAndIdDoesNotExistItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithoutProjectItShouldBeDefault(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithProjectThatDoesNotExistItShouldValueError(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithProjectThatExistsItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoTypeItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithTypeItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoStatusItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithStatusItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoAssignedToItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithAssignedToAndUserDoesNotExistItShouldValueError(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithAssignedToAdnUserExistsItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithContactItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoContactItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoPriorityItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithPriorityItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoDueDateItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithDueDateItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoOriginalEstimateItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithOriginalEstimateItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoCurrentEstimateItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithCurrentEstimateItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithCurrentEstimateAndNoOriginalOriginalShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoVersionItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithVersionItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoBacklogOrderItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithBacklogOrderItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoAreaItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithAreaItShouldBeSet(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithNoParentCaseItShouldBeNone(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithBadParentCaseItShouldValueError(self):
        self.skipTest("Write this test")

    def test_whenTaskIsCreatedWithGoodParentCaseItShouldBeSet(self):
        self.skipTest("Write this test")

class IntervalTests(unittest.TestCase):
    def test_whenIntervalIsCreatedWithNoStartItShouldBeNow(self):
        interval = slayer.Interval(1, 'uwwerne')
        self.assertAlmostEqual(datetime.now().toordinal(),
                               interval.start.toordinal(), places=0)

    def test_whenIntervalIsCreatedWithStartItShouldBeTheProvidedOne(self):
        expected_start = datetime.now()
        interval = slayer.Interval(1, 'uwwerne', start=expected_start)
        self.assertAlmostEqual(expected_start, interval.start, places=2)

    def test_whenIntervalIsCreatedWithNoEndItShouldBeNone(self):
        interval = slayer.Interval(1, 'wayne')
        self.assertEqual(None, interval.end)

    def test_whenIntervalIsCreatedWithEndItShouldBeTheProvidedOne(self):
        expected_end = time.time()-42
        interval = slayer.Interval(3, 'wayne', end=expected_end)
        self.assertEqual(expected_end, interval.end)

class SlayerTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        slayer.DB_PATH = os.path.join(slayer.BASE_DIR, 'test.sq3')
        slayer.make_db()

    @classmethod
    def tearDownClass(cls):
        os.remove(slayer.DB_PATH)

    def setUp(self):
        slayer.add_project(project_name='default')

    def tearDown(self):
        engine = slayer.make_engine()
        with contextlib.closing(engine.connect()) as con:
            trans = con.begin()
            for table in reversed(slayer.Base.metadata.sorted_tables):
                con.execute(table.delete())
            trans.commit()

    def test_whenParseIsCalledWithNoArgsItShouldRaiseSystemExit(self):
        with self.assertRaises(SystemExit):
            slayer._parse([])

    def test_whenParseIsCalledWithTaskStartAndNoDescShouldSystemExit(self):
        with self.assertRaises(SystemExit):
            slayer._parse(['task', 'start'])

    def test_whenParseIsCalledWithTaskStartAndDescShouldReturnResults(self):
        results = slayer._parse(['task', 'start', 'Rock me amadaeus'])
        expected_command = 'task'
        expected_action = 'start'
        expected_data = 'Rock me amadaeus'

        self.assertEqual(expected_command, results.command)
        self.assertEqual(expected_action, results.action)
        self.assertEqual(expected_data, results.data)

    ##################
    # Interval Tests #
    ##################
    def test_whenStartIntervalIsCalledTaskDoesNotExistItShouldRaiseValueError(self):
        with self.assertRaises(ValueError):
            slayer.start_interval(task_id=4, user_id='wango')

    def test_whenStartIntervalIsCalledAndUserDNEThenItShouldValueError(self):
        task_id = slayer.add_task(project='default').id
        with self.assertRaises(ValueError):
            slayer.start_interval(task_id=task_id, user_id='wango')

    def test_whenStartIntervalIsCalledAndTaskAndUserExistItShouldBeAddedToUser(self):
        user_id = slayer.add_user().id
        task_id = slayer.add_task(project='default').id
        session = slayer.make_session()
        interval = slayer.start_interval(task_id=task_id, user_id=user_id,
                                         session=session)
        user = slayer.get_user(user_id, session)
        self.assertEqual(interval, user.timesheet[0])

    def test_whenStartIntervalIsCalledOkItShouldReturnTheInterval(self):
        user_id = slayer.add_user().id
        task_id = slayer.add_task(project='default').id
        interval = slayer.start_interval(task_id=task_id, user_id=user_id)
        self.assertTrue(isinstance(interval, slayer.Interval))

    ##############
    # Task Tests #
    ##############
    def test_whenAddTaskIsCalledItShouldReturnTheTaskWithNewId(self):
        task = slayer.add_task(project='default')
        self.assertLess(0, task.id)

    def test_whenAddTaskIsCalledWithDescItShouldBeSet(self):
        expected_desc = 'No real project thing'
        id = slayer.add_task(desc=expected_desc, project='default').id
        task = slayer.get_task(id)
        self.assertEqual(expected_desc, task.desc)

    def test_whenAddTaskIsCalledWithProjectThatExistsItShouldBeSet(self):
        expected_proj = 'Boog Slayer'
        slayer.add_project(expected_proj)
        id = slayer.add_task(project=expected_proj).id
        task = slayer.get_task(id)
        self.assertEqual(expected_proj, task.project)

    def test_whenAddTaskIsCalledWithProjectAndProjectDoesNotExistShouldRaiseValueError(self):
        expected_proj = 'Boog Slayer'
        with self.assertRaises(ValueError):
            slayer.add_task(project=expected_proj)

    def test_whenAddTaskIsCalledWithUserAndUserDoesNotExistShouldRaiseValueError(self):
        imaginary_user = 'some super cool id'
        with self.assertRaises(ValueError):
            slayer.add_task(assigned_to=imaginary_user)

    def test_whenAddTaskIsCalledWithParentCaseThatDoesntExistItShouldRaiseValueError(self):
        imaginary_task_id = 42
        with self.assertRaises(ValueError):
            slayer.add_task(parent_id=imaginary_task_id)

    def test_whenGetTaskIsCalledWithIdItShouldReturnTask(self):
        task_id = slayer.add_task(project='default').id
        task = slayer.get_task(task_id=task_id)
        self.assertEqual(task_id, task.id)

    def test_whenEditTaskIsCalledWithInvalidIdItShouldRaiseValueError(self):
        with self.assertRaises(ValueError):
            slayer.edit_task(id=4)

    def test_whenEditTaskIsCalledWithDescItShouldBeSet(self):
        expected_desc = 'No real project thing'
        id = slayer.add_task(project='default').id
        slayer.edit_task(id, desc=expected_desc)
        task = slayer.get_task(id)
        self.assertEqual(expected_desc, task.desc)

    def test_whenEditTaskIsCalledWithProjectItShouldBeSet(self):
        expected_proj = 'XTF-1234'
        id = slayer.add_task(project='default').id
        slayer.edit_task(id, project=expected_proj)
        task = slayer.get_task(id)
        self.assertEqual(expected_proj, task.project)

    def test_whenEditTaskIsCalledWithTypeItShouldBeUpdated(self):
        expected_type = 'Fnord'
        id = slayer.add_task().id
        slayer.edit_task(id, type=expected_type)
        task = slayer.get_task(id)
        self.assertEqual(expected_type, task.type)

    def test_whenEditTaskIsCalledWithStatusItShouldBeUpdated(self):
        expected_status = 'Newed'
        id = slayer.add_task().id
        slayer.edit_task(id, status=expected_status)
        task = slayer.get_task(id)
        self.assertEqual(expected_status, task.status)

    def test_whenEditTaskIsCalledWithAssignedToItShouldBeUpdated(self):
        expected_assigned_to = 'Puff, the magic dragon'
        id = slayer.add_task().id
        slayer.edit_task(id, assigned_to=expected_assigned_to)
        task = slayer.get_task(id)
        self.assertEqual(expected_assigned_to, task.assigned_to)

    def test_whenEditTaskIsCalledWithContactItShouldBeUpdated(self):
        expected_contact = '3-2-1'
        id = slayer.add_task().id
        slayer.edit_task(id, contact=expected_contact)
        task = slayer.get_task(id)
        self.assertEqual(expected_contact, task.contact)

    def test_whenEditTaskIsCalledWithPriorityItShouldBeUpdated(self):
        expected_priority = 1
        id = slayer.add_task().id
        slayer.edit_task(id, priority=expected_priority)
        task = slayer.get_task(id)
        self.assertEqual(expected_priority, task.priority)

    def test_whenEditTaskIsCalledWithDueItShouldBeUpdated(self):
        expected_due = datetime(1984, 8, 26)
        id = slayer.add_task().id
        slayer.edit_task(id, due=expected_due)
        task = slayer.get_task(id)
        self.assertEqual(expected_due, task.due)

    def test_whenEditTaskIsCalledWithOriginalEstimateItShouldBeUpdated(self):
        expected_original_estimate = 13
        id = slayer.add_task().id
        slayer.edit_task(id, original_estimate=expected_original_estimate)
        task = slayer.get_task(id)
        self.assertEqual(expected_original_estimate, task.original_estimate)

    def test_whenEditTaskIsCalledWithCurrentEstimateItShouldBeUpdated(self):
        expected_current_estimate = 13
        id = slayer.add_task().id
        slayer.edit_task(id, current_estimate=expected_current_estimate)
        task = slayer.get_task(id)
        self.assertEqual(expected_current_estimate, task.current_estimate)

    def test_whenEditTaskIsCalledWithVersionItShouldBeUpdated(self):
        expected_version = '1.4'
        id = slayer.add_task().id
        slayer.edit_task(id, version=expected_version)
        task = slayer.get_task(id)
        self.assertEqual(expected_version, task.version)

    def test_whenEditTaskIsCalledWithBacklogOrderItShouldBeUpdated(self):
        expected_backlog_order = 42
        id = slayer.add_task().id
        slayer.edit_task(id, backlog_order=expected_backlog_order)
        task = slayer.get_task(id)
        self.assertEqual(expected_backlog_order, task.backlog_order)

    def test_whenEditTaskIsCalledWithAreaItShouldBeUpdated(self):
        expected_area = 'some area'
        id = slayer.add_task().id
        slayer.edit_task(id, area=expected_area)
        task = slayer.get_task(id)
        self.assertEqual(expected_area, task.area)

    def test_whenEditTaskIsCalledWithParentCaseItShouldBeUpdated(self):
        expected_parent_case = slayer.add_task().id
        id = slayer.add_task().id
        slayer.edit_task(id, parent_case=expected_parent_case)
        task = slayer.get_task(id)
        self.assertEqual(expected_parent_case, task.parent_case)

    def test_whenEditTaskIsCalledWithParentCaseItShouldExist(self):
        bad_parent_case = 70
        id = slayer.add_task().id
        with self.assertRaises(ValueError):
            slayer.edit_task(id, parent_case=bad_parent_case)

    ##############
    # User Tests #
    ##############
    def test_whenUserIsAddedWithoutProvidingIdItShouldDefaultToBlankString(self):
        user = slayer.add_user()
        self.assertEqual('', user.id)

    def test_whenUserIsAddedGetUserWithIdShouldReturnUser(self):
        user_id = slayer.add_user().id
        user = slayer.get_user(user_id)
        self.assertEqual(user_id, user.id)

    def test_whenUserIsAddedWithIdAndNameItShouldSetBoth(self):
        user = slayer.add_user(user_id="uwwerne", name="Wahoo Tango")
        got_user = slayer.get_user(user.id)
        self.assertEqual(user.id, got_user.id)
        self.assertEqual(user.name, got_user.name)

    def test_whenEditUserIsCalledWithWrongIdItShouldValueError(self):
        with self.assertRaises(ValueError):
            slayer.edit_user(user_id='4135')

    def test_usersShouldBeEqualWhenIdAndNameAreTheSame(self):
        user_a = slayer.User(id='wango', name='tango')
        user_b = slayer.User(id='wango', name='tango')
        self.assertEqual(user_a, user_b)

    def test_whenEditUserIsCalledAndUserExistsItShouldReturnUser(self):
        session = slayer.make_session()
        expected_user = slayer.add_user(user_id='roscivs',
                                        name='Ross Werner',
                                        session=session)
        actual_user = slayer.edit_user('roscivs', session=session)
        self.assertEqual(expected_user, actual_user)

    def test_whenEditUserIsCalledWithNoneNewIdAndNoneNameItShouldStaySame(self):
        user_id = slayer.add_user(user_id='waynerd', name="Wango Tango").id
        slayer.edit_user(user_id, new_id=None, new_name=None)
        user = slayer.get_user(user_id=user_id)
        self.assertEqual('waynerd', user.id)
        self.assertEqual('Wango Tango', user.name)

    def test_whenEditUserIsCalledWithNewIdThenOldIdShouldBeGone(self):
        old_id = slayer.add_user(user_id='bob').id
        slayer.edit_user(old_id, new_id='fnord')
        user = slayer.get_user(user_id=old_id)
        self.assertEqual(None, user)

    def test_whenEditUserIsCalledAndNewIdExistsThenShouldRaiseValueError(self):
        taken_id = 'wango'
        slayer.add_user(user_id=taken_id)
        good_id = slayer.add_user(user_id='good').id
        with self.assertRaises(ValueError):
            slayer.edit_user(good_id, new_id=taken_id)

    def test_whenEditUserIsCalledAndNewNameProvidedThenNameShouldBeNewOne(self):
        user_id = slayer.add_user(user_id='wango', name='').id
        new_name = 'Tango'
        slayer.edit_user(user_id, new_name=new_name)
        user = slayer.get_user(user_id)
        self.assertEqual(new_name, user.name)

    def test_whenDeleteUserIsCalledWithInvalidIdThenShouldRaiseValueError(self):
        with self.assertRaises(ValueError):
            slayer.delete_user(user_id='fnord')

    def test_whenDeleteUserIsCalledItShouldReallyDeleteUser(self):
        user_id = 'roscivs'
        slayer.add_user(user_id=user_id)
        slayer.delete_user(user_id)
        actual_user = slayer.get_user(user_id)
        self.assertEqual(None, actual_user)


    #################
    # Project Tests #
    #################
    def test_whenGetProjectIsCalledItShouldReturnTheRightOne(self):
        session = slayer.make_session()
        expected_project = slayer.Project(name='SRP-014')
        session.add(expected_project)
        session.commit()
        project = slayer.get_project(expected_project.name, session=session)
        self.assertEqual(expected_project, project)

    def test_whenAddProjectIsCalledWithNoArgumentsTheNameShouldBeEmptyString(self):
        project = slayer.add_project()
        self.assertEqual('', project.name)

    def test_whenDuplicateProjectNamesAreAddedValueErrorShouldBeRaised(self):
        slayer.add_project('whatever')
        with self.assertRaises(ValueError):
            slayer.add_project('whatever')


    def test_whenArchiveProjectIsCalledItShouldSetFlagOnProject(self):
        project_name = 'Boog Slayer'
        slayer.add_project(project_name=project_name)
        slayer.archive_project(project_name)
        project = slayer.get_project(project_name)

        self.assertTrue(project.archived)

    def test_whenEditProjectIsCalledWithNewNameThatExistsShouldRaiseValueError(self):
        taken_name = 'Boog Slayer'
        project_name = 'Boog Player'
        slayer.add_project(taken_name)
        slayer.add_project(project_name)
        with self.assertRaises(ValueError):
            slayer.edit_project(project_name, new_name=taken_name)

    def test_whenEditProjectIsCalledAndNoProjectHasThatNameShouldRaiseValueError(self):
        with self.assertRaises(ValueError):
            slayer.edit_project(project_name='whatever, not like you care')

    def test_whenEditProjectIsCalledWithGoodNewNameItShouldSucceed(self):
        new_name = 'F Cancer'
        project_name = 'Screw Cancer'
        slayer.add_project(project_name)
        slayer.edit_project(project_name, new_name=new_name)
        self.assertTrue(slayer.get_project(new_name) is not None)

    def test_whenEditProjectIsCalledWithNewDescItShouldSucceed(self):
        project_name = 'Symphony in C'
        desc = 'A Cake song'
        slayer.add_project(project_name)
        slayer.edit_project(project_name, new_desc=desc)
        project = slayer.get_project(project_name)

        self.assertEqual(desc, project.desc)

    def test_whenProjectIsRestoredItShouldSetArchivedToFalse(self):
        project_name = 'Model P Fnord'
        slayer.add_project(project_name)
        slayer.archive_project(project_name)
        slayer.restore_project(project_name)
        project = slayer.get_project(project_name)
        self.assertFalse(project.archived)

    def test_whenArchiveProjectIsCalledAndProjectDoesNotExistItShouldValueError(self): 
        with self.assertRaises(ValueError):
            slayer.archive_project('Doesn\'t matter really')

    def test_whenRestoreProjectIsCalledAndProjectDoesNotExistItShouldValueError(self): 
        with self.assertRaises(ValueError):
            slayer.restore_project('Doesn\'t matter really')

unittest.main()