|
@@ -316,40 +316,40 @@ class TestSave(ComponentTestCase):
|
316
|
316
|
time.sleep(2) # We have to sleep 2 secs here, so the update_date will be at least 2 secs more than newval['date_update']
|
317
|
317
|
|
318
|
318
|
#name change
|
319
|
|
- with self.subTest("Save after name change"):
|
320
|
|
- newval['name'] = test_comp.name = 'newname'
|
321
|
|
- test_comp.save()
|
322
|
|
- self._savecheck(test_comp, newval)
|
|
319
|
+ newval['name'] = test_comp.name = 'newname'
|
|
320
|
+ test_comp.save()
|
|
321
|
+ self._savecheck(test_comp, newval)
|
|
322
|
+ self.assertTrue(True)
|
323
|
323
|
|
324
|
324
|
#help change
|
325
|
|
- with self.subTest("Save after help change"):
|
326
|
|
- newval['help'] = '{"fr": "help fr", "en":"help en", "es":"help es"}'
|
327
|
|
- test_comp.help = MlString.load(newval['help'])
|
328
|
|
- test_comp.save()
|
329
|
|
- self._savecheck(test_comp, newval)
|
330
|
|
-
|
|
325
|
+ newval['help'] = '{"fr": "help fr", "en":"help en", "es":"help es"}'
|
|
326
|
+ test_comp.help = MlString.load(newval['help'])
|
|
327
|
+ test_comp.save()
|
|
328
|
+ self._savecheck(test_comp, newval)
|
|
329
|
+ self.assertTrue(True)
|
|
330
|
+
|
331
|
331
|
#string change
|
332
|
|
- with self.subTest("Save after string change"):
|
333
|
|
- newval['string'] = '{"fr": "string fr", "en":"string en", "es":"string es"}'
|
334
|
|
- test_comp.string = MlString.load(newval['string'])
|
335
|
|
- test_comp.save()
|
336
|
|
- self._savecheck(test_comp, newval)
|
|
332
|
+ newval['string'] = '{"fr": "string fr", "en":"string en", "es":"string es"}'
|
|
333
|
+ test_comp.string = MlString.load(newval['string'])
|
|
334
|
+ test_comp.save()
|
|
335
|
+ self._savecheck(test_comp, newval)
|
|
336
|
+ self.assertTrue(True)
|
337
|
337
|
|
338
|
338
|
#no change
|
339
|
|
- with self.subTest("Save without any change"):
|
340
|
|
- test_comp.save()
|
341
|
|
- self._savecheck(test_comp, newval)
|
|
339
|
+ test_comp.save()
|
|
340
|
+ self._savecheck(test_comp, newval)
|
|
341
|
+ self.assertTrue(True)
|
342
|
342
|
|
343
|
343
|
#change all
|
344
|
|
- with self.subTest("Save after name, help and string change"):
|
345
|
|
- test_comp.name = newval['name'] = test_comp.name = 'newnewname'
|
346
|
|
- newval['help'] = '{"fr": "help fra", "en":"help eng", "es":"help esp"}'
|
347
|
|
- test_comp.help = MlString.load(newval['help'])
|
348
|
|
- newval['string'] = '{"fr": "string FR", "en":"string EN", "es":"string ES", "foolang":"foofoobar"}'
|
349
|
|
- test_comp.string = MlString.load(newval['string'])
|
|
344
|
+ test_comp.name = newval['name'] = test_comp.name = 'newnewname'
|
|
345
|
+ newval['help'] = '{"fr": "help fra", "en":"help eng", "es":"help esp"}'
|
|
346
|
+ test_comp.help = MlString.load(newval['help'])
|
|
347
|
+ newval['string'] = '{"fr": "string FR", "en":"string EN", "es":"string ES", "foolang":"foofoobar"}'
|
|
348
|
+ test_comp.string = MlString.load(newval['string'])
|
350
|
349
|
|
351
|
|
- test_comp.save()
|
352
|
|
- self._savecheck(test_comp, newval)
|
|
350
|
+ test_comp.save()
|
|
351
|
+ self._savecheck(test_comp, newval)
|
|
352
|
+ self.assertTrue(True)
|
353
|
353
|
|
354
|
354
|
pass
|
355
|
355
|
|
|
@@ -360,37 +360,24 @@ class TestSave(ComponentTestCase):
|
360
|
360
|
changes = { 'date_create': datetime.datetime(1982,4,2,13,37), 'date_update': datetime.datetime(1982,4,2,22,43), 'rank': 42 }
|
361
|
361
|
|
362
|
362
|
for prop in changes:
|
363
|
|
- with self.subTest("Illegal change of "+prop):
|
364
|
|
- test_comp = EmTestComp(val['name'])
|
365
|
|
- self.check_equals(val, test_comp, False)
|
366
|
|
-
|
367
|
|
- with self.assertRaises(TypeError):
|
368
|
|
- setattr(test_comp, prop, changes[prop])
|
369
|
|
- test_comp.save()
|
370
|
|
-
|
371
|
|
- test_comp2 = EmTestComp(val['name'])
|
372
|
|
-
|
373
|
|
- if prop == 'date_create':
|
374
|
|
- assertion = self.assertEqualDatetime
|
375
|
|
- elif prop == 'date_update':
|
376
|
|
- continue
|
377
|
|
- else: #rank
|
378
|
|
- assertion = self.assertEqual
|
379
|
|
-
|
380
|
|
- assertion(getattr(test_comp,prop), val[prop], "When using setattr the "+prop+" of a component is set : ")
|
381
|
|
- assertion(getattr(test_comp2, prop), val[prop], "When using setattr and save the "+prop+" of a loaded component is set : ")
|
382
|
|
-
|
383
|
|
- # The code block commented bellow uses the values argument of the save method.
|
384
|
|
- # soon this argument will not being used anymore
|
385
|
|
- """
|
386
|
|
- test_comp = EmTestComp(val['name'])
|
387
|
|
- self.check_equals(val, test_comp)
|
388
|
|
- test_comp.save({ prop: changes['prop'] })
|
389
|
|
-
|
390
|
|
- test_comp2 = EmTestComp(val['name'])
|
391
|
|
- self.assertEqualDatetime(test_comp.date_create, val[prop], "The "+prop+" of the component instance has been changed")
|
392
|
|
- self.assertEqualDatetime(test_comp2.date_create, val[prop], "When loaded the "+prop+" has been changed")
|
393
|
|
- """
|
|
363
|
+ test_comp = EmTestComp(val['name'])
|
|
364
|
+ self.check_equals(val, test_comp, False)
|
|
365
|
+
|
|
366
|
+ with self.assertRaises(TypeError):
|
|
367
|
+ setattr(test_comp, prop, changes[prop])
|
|
368
|
+ test_comp.save()
|
|
369
|
+
|
|
370
|
+ test_comp2 = EmTestComp(val['name'])
|
|
371
|
+
|
|
372
|
+ if prop == 'date_create':
|
|
373
|
+ assertion = self.assertEqualDatetime
|
|
374
|
+ elif prop == 'date_update':
|
|
375
|
+ continue
|
|
376
|
+ else: #rank
|
|
377
|
+ assertion = self.assertEqual
|
|
378
|
+
|
|
379
|
+ assertion(getattr(test_comp,prop), val[prop], "When using setattr the "+prop+" of a component is set : ")
|
|
380
|
+ assertion(getattr(test_comp2, prop), val[prop], "When using setattr and save the "+prop+" of a loaded component is set : ")
|
394
|
381
|
pass
|
395
|
382
|
|
396
|
383
|
#====================#
|
|
@@ -399,40 +386,35 @@ class TestSave(ComponentTestCase):
|
399
|
386
|
class TestCreate(ComponentTestCase):
|
400
|
387
|
|
401
|
388
|
def test_create(self):
|
402
|
|
-
|
403
|
|
- with self.subTest("Create with all infos"):
|
404
|
|
- vals = {'name': 'created1', 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en":"help test", "fr":"test help"}'}
|
405
|
|
- tc = EmTestComp.create(**vals)
|
406
|
|
- self.check_equals(vals, tc, "The created EmTestComp hasn't the good properties values")
|
407
|
|
- tcdb = EmTestComp('created1')
|
408
|
|
- self.check_equals(vals, tc, "When fetched from Db the created EmTestComp hasn't the good properties values")
|
409
|
|
-
|
|
389
|
+ """Testing EmComponent.create()"""
|
|
390
|
+ vals = {'name': 'created1', 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en":"help test", "fr":"test help"}'}
|
|
391
|
+ tc = EmTestComp.create(**vals)
|
|
392
|
+ self.check_equals(vals, tc, "The created EmTestComp hasn't the good properties values")
|
|
393
|
+ tcdb = EmTestComp('created1')
|
|
394
|
+ self.check_equals(vals, tc, "When fetched from Db the created EmTestComp hasn't the good properties values")
|
|
395
|
+
|
410
|
396
|
# This test assume that string and help has default values
|
411
|
|
- with self.subTest("Create with minimal infos"):
|
412
|
|
- vals = { 'name': 'created2', 'rank_fam': 'f' }
|
413
|
|
- tc = EmTestComp.create(**vals)
|
414
|
|
- self.check_equals(vals, tc, "The created EmTestComp hasn't the good properties values")
|
415
|
|
- tcdb = EmTestComp('created1')
|
416
|
|
- self.check_equals(vals, tc, "When fetched from Db the created EmTestComp hasn't the good properties values")
|
|
397
|
+ vals = { 'name': 'created2', 'rank_fam': 'f' }
|
|
398
|
+ tc = EmTestComp.create(**vals)
|
|
399
|
+ self.check_equals(vals, tc, "The created EmTestComp hasn't the good properties values")
|
|
400
|
+ tcdb = EmTestComp('created1')
|
|
401
|
+ self.check_equals(vals, tc, "When fetched from Db the created EmTestComp hasn't the good properties values")
|
417
|
402
|
pass
|
418
|
403
|
|
419
|
404
|
def test_create_badargs(self):
|
420
|
|
-
|
421
|
|
- with self.subTest("Create with illegal arguments"):
|
422
|
|
- with self.assertRaises(TypeError, msg="But given a function as argument"):
|
423
|
|
- tc = EmTestComp.create(print)
|
424
|
|
- with self.assertRaises(TypeError, msg="But values contains date_create and date_update"):
|
425
|
|
- vals = { 'name': 'created1', 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
426
|
|
- tc = EmTestComp.create(**vals)
|
427
|
|
-
|
428
|
|
- with self.subTest("Create without mandatory arguments"):
|
429
|
|
- with self.assertRaises(TypeError, msg="But no name was given"):
|
430
|
|
- vals = { 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
431
|
|
- tc = EmTestComp.create(**vals)
|
432
|
|
- with self.assertRaises(TypeError, msg="But no rank_fam was given"):
|
433
|
|
- vals = { 'name': 'created1', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
434
|
|
- tc = EmTestComp.create(**vals)
|
|
405
|
+ """Testing EmComponent.create() with bad arguments"""
|
|
406
|
+ with self.assertRaises(TypeError, msg="But given a function as argument"):
|
|
407
|
+ tc = EmTestComp.create(print)
|
|
408
|
+ with self.assertRaises(TypeError, msg="But values contains date_create and date_update"):
|
|
409
|
+ vals = { 'name': 'created1', 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
|
410
|
+ tc = EmTestComp.create(**vals)
|
435
|
411
|
|
|
412
|
+ with self.assertRaises(TypeError, msg="But no name was given"):
|
|
413
|
+ vals = { 'rank_fam': 'f', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
|
414
|
+ tc = EmTestComp.create(**vals)
|
|
415
|
+ with self.assertRaises(TypeError, msg="But no rank_fam was given"):
|
|
416
|
+ vals = { 'name': 'created1', 'string': '{"fr":"testcomp"}', 'help': '{"en" :"help test", "fr":"test help"}', 'rank': 6, 'date_create': 0 , 'date_update': 0 }
|
|
417
|
+ tc = EmTestComp.create(**vals)
|
436
|
418
|
pass
|
437
|
419
|
|
438
|
420
|
#====================#
|
|
@@ -476,6 +458,7 @@ class TestDelete(ComponentTestCase):
|
476
|
458
|
tc = EmTestComp(vals[j]['name'])
|
477
|
459
|
except EmComponentNotExistError:
|
478
|
460
|
self.fail('EmComponent should not be deleted')
|
|
461
|
+ self.assertTrue(True)
|
479
|
462
|
pass
|
480
|
463
|
|
481
|
464
|
|
|
@@ -559,20 +542,6 @@ class TestModifyRank(ComponentTestCase):
|
559
|
542
|
for j in range(i+1,nmax+1):
|
560
|
543
|
test_comp = EmTestComp(names[j])
|
561
|
544
|
self.assertEqual(test_comp.rank, j)
|
562
|
|
-
|
563
|
|
- #Not inverting the list (makes swap but at the end we are in reverse state again)
|
564
|
|
- #--------------------------------------------------------------------------------
|
565
|
|
- for i in range(nmax,-1,-1):
|
566
|
|
- test_comp = EmTestComp(names[i])
|
567
|
|
- test_comp.modify_rank(nmax,'=')
|
568
|
|
- self.assertEqual(test_comp.rank, nmax)
|
569
|
|
- for j in range(i,nmax+1):
|
570
|
|
- test_comp = EmTestComp(names[j])
|
571
|
|
- self.assertEqual(test_comp.rank, nmax-(j-i), "Excepted rank was '"+str(nmax-(j-i))+"' but got '"+str(test_comp.rank)+"'). Ranks dump : "+self.dump_ranks())
|
572
|
|
- for j in range(0,i):
|
573
|
|
- test_comp = EmTestComp(names[j])
|
574
|
|
- self.assertEqual(test_comp.rank, i-j-1)
|
575
|
|
-
|
576
|
545
|
pass
|
577
|
546
|
|
578
|
547
|
def test_modify_rank_relative(self):
|