File: test_Transaction.py

package info (click to toggle)
mobyle 1.5.5%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,288 kB
  • sloc: python: 22,709; makefile: 35; sh: 33; ansic: 10; xml: 6
file content (610 lines) | stat: -rw-r--r-- 28,196 bytes parent folder | download | duplicates (3)
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
########################################################################################
#                                                                                      #
#   Author: Bertrand Neron,                                                            #
#   Organization:'Biological Software and Databases' Group, Institut Pasteur, Paris.   #
#   Distributed under GPLv2 Licence. Please refer to the COPYING.LIB document.         #
#                                                                                      #
########################################################################################

import unittest2 as unittest
import os
import sys
import shutil

MOBYLEHOME = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "../../../" ) )
os.environ['MOBYLEHOME'] = MOBYLEHOME

if ( MOBYLEHOME ) not in sys.path:
    sys.path.append( MOBYLEHOME )
if ( os.path.join( MOBYLEHOME , 'Src' ) ) not in sys.path:
    sys.path.append( os.path.join( MOBYLEHOME , 'Src' ) )

import Mobyle.Test.MobyleTest

from Mobyle.Transaction import Transaction
from Mobyle.MobyleError import MobyleError, SessionError
from Mobyle.Classes.DataType import DataTypeFactory
from Mobyle.Service import MobyleType
from Mobyle.Session import Session
#import Mobyle.Utils

DATADIR = os.path.dirname( __file__ )

class TransactionTest(unittest.TestCase):
    """Tests the functionalities of Transaction"""

    def setUp(self):
        """
        setting up the configuration for the test, including:
        - test configuration that does not check dns or try to send confirmation emails
        - test session email
        """
        self.cfg = Mobyle.ConfigManager.Config()
        shutil.rmtree(self.cfg.test_dir, ignore_errors=True)
        os.makedirs(self.cfg.test_dir)

        self.sessionKey = "Q12345678901234"
        self.sessionDir = os.path.join( self.cfg.test_dir , self.sessionKey )
        os.makedirs( self.sessionDir )

        self.email  = 'dummy@domain.fr'
        self.passwd = 'dummypass'
        self.actkey = 'dummykey'

        self.xmlSourcePath = os.path.join( DATADIR , 'session_test.xml')
        self.sessionPath = os.path.join( self.sessionDir , Session.FILENAME )
        self.dataID = [ "f835ddf28cb6aa776a41d7c71ec9cb5a.out" , "16bd6f89e732eb7cb0bbc13c65d202d3.aln" ]

        dtf = DataTypeFactory()
        dataType1   = dtf.newDataType( 'Sequence' )
        mobyleType1 = MobyleType( dataType1 , bioTypes = [ 'Protein' , 'Nucleic' ] , dataFormat =  'SWISSPROT' )
        dataType2   = dtf.newDataType( 'Alignment' )
        mobyleType2 = MobyleType( dataType2 , dataFormat = 'PHYLIPI' )
        self.datas  = [ {'dataName'   : 'f835ddf28cb6aa776a41d7c71ec9cb5a.out' ,
                        'userName'   : 'golden.out' ,
                        'size'       :   4410 ,
                        'Type'       :  mobyleType1 ,
                        'dataBegin'    :  'ID   104K_THEPA              Reviewed;         924' ,
                        'inputModes' : [ 'result' ] ,
                        'producedBy' : [ 'file://tmp/mobyle/results/dnadist/G25406684175968' ] ,
                        'usedBy'     : []
                        } ,
                        {'dataName'  : '16bd6f89e732eb7cb0bbc13c65d202d3.aln' ,
                         'userName'   : 'clustal.aln' ,
                         'size'       :    90044 ,
                         'Type'       :  mobyleType2 ,
                         'dataBegin'    :  '    47  1618\nF_75      ---------------------------' ,
                         'inputModes' : [ 'upload' , 'paste' ] ,
                         'producedBy' : [] ,
                         'usedBy'     : [ 'file://tmp/mobyle/results/dnadist/G25406684175968' ,
                                         'file://tmp/mobyle/results/dnadist/X25423048243999' ]
                         }
                        ]

        self.jobID = [ "file://tmp/mobyle/results/dnadist/X25423048243999" ,
                       "file://tmp/mobyle/results/dnadist/G25406684175968" ]
        self.jobs  = [ {'jobID'       : 'file://tmp/mobyle/results/dnadist/X25423048243999' ,
                      'userName'    : 'mon programme a moi' ,
                      'programName' : 'prog 1' ,
                      'status'      :  Mobyle.Status.Status( code = 6 ) , #killed
                      'date'        :  (2008, 11, 20, 12, 0, 0, 3, 325, -1) ,
                      'dataProduced': [] ,
                      'dataUsed'    : ['16bd6f89e732eb7cb0bbc13c65d202d3.aln'] ,
                      } ,
                      {'jobID'       : 'file://tmp/mobyle/results/dnadist/G25406684175968' ,
                       'userName'    : 'file://tmp/mobyle/results/dnadist/G25406684175968' ,
                       'programName' : 'dnadist' ,
                       'status'      :  Mobyle.Status.Status( code = 3 ) , #running
                       'date'        :  (2008, 11, 19, 10, 50, 33, 2, 324, -1) ,
                       'dataProduced': ['f835ddf28cb6aa776a41d7c71ec9cb5a.out'] ,
                       'dataUsed'    : ['16bd6f89e732eb7cb0bbc13c65d202d3.aln'] ,
                       }
                      ]

    def tearDown(self):
        shutil.rmtree( self.cfg.test_dir , ignore_errors= True )

    def testTransaction(self):
        Transaction.create( self.sessionPath , False , False )
        # Check locks types
        transaction = Transaction( self.sessionPath, Transaction.WRITE )
        transaction.rollback()
        transaction = Transaction( self.sessionPath, Transaction.READ )
        transaction.rollback()
        self.assertRaises(MobyleError, Transaction, self.sessionPath, None )
        # Invalid file
        self.assertRaises(SessionError, Transaction, str(None), Transaction.READ)

    def testCreation(self):
        #create( filename , authenticated , activated , activatingKey = None , email = None , passwd = None)

        #test anonymous session without email
        Transaction.create( self.sessionPath , False , False )
        os.unlink( self.sessionPath )

        #test anonymous session with passwd
        self.assertRaises( SessionError , Transaction.create , self.sessionPath , False , False , passwd = self.passwd )

        #test anonymous session with email
        Transaction.create( self.sessionPath , False , False , userEmail = self.email )
        os.unlink( self.sessionPath )

        #test authenticated session without passwd -> SessionError
        self.assertRaises( SessionError , Transaction.create , self.sessionPath , True , False , userEmail = self.email )

        #test authenticated session without email -> SessionError
        self.assertRaises( SessionError , Transaction.create , self.sessionPath , True , False , passwd = self.passwd )

        #test authenticated session with email and passwd
        Transaction.create( self.sessionPath , True , False , userEmail = self.email , passwd = self.passwd )
        os.unlink( self.sessionPath )

        #test authenticated session with activatingKey
        Transaction.create( self.sessionPath , True , False , activatingKey = self.actkey , userEmail = self.email , passwd = self.passwd )
        os.unlink( self.sessionPath )

        #test that session creation fails if already exists
        Transaction.create( self.sessionPath , False , False )
        self.assertRaises( SessionError , Transaction.create , self.sessionPath , False , False )
        os.unlink( self.sessionPath )

    def testCommit(self):
        Transaction.create( self.sessionPath , False , False )

        # Ensure that transaction with modification update the file
        bef = os.stat( self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction._setModified( True )
        transaction.commit()
        aft = os.stat( self.sessionPath )
        self.assertFalse( bef.st_ino == aft.st_ino and bef.st_mtime == aft.st_mtime )

        # Ensure that transaction without modification does not update the file
        bef = os.stat( self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction._setModified( False )
        transaction.commit()
        aft = os.stat( self.sessionPath )
        self.assertTrue( bef.st_ino == aft.st_ino and bef.st_mtime == aft.st_mtime )

        # By default, an empty transaction should have no effect on the file
        bef = os.stat( self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.commit()
        aft = os.stat( self.sessionPath )
        self.assertTrue( bef.st_ino == aft.st_ino and bef.st_mtime == aft.st_mtime )

    def testRollback(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.removeData( self.dataID[0] )
        self. assertFalse( transaction.hasData(self.dataID[0] ) )
        transaction.rollback()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        self.assertTrue( transaction.hasData( self.dataID[0] ) )
        transaction.commit()

    def testConcurency(self):
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        ## sub-process start
        childPid = os.fork()
        if childPid: #father
            pid , status = os.wait()
            self.assertFalse( status )
        else: #child
            cmd = [ sys.executable, 'openTransaction.py' , self.sessionPath , str( Transaction.READ ) ]
            os.execv( cmd[0] , cmd )
        ## sub-process end
        transaction.commit()

        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        ## sub-process start
        childPid = os.fork()
        if childPid: #father
            pid , status = os.wait()
            self.assertTrue( status )
        else: #child
            cmd = [ sys.executable, 'openTransaction.py' , self.sessionPath , str( Transaction.READ ) ]
            os.execv( cmd[0] , cmd )
        ## sub-process end
        transaction.commit()

    def testgetID(self):
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedID = transaction.getID()
        transaction.commit()
        self.assertEqual( receivedID , self.sessionKey )

    def testEmail(self):
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setEmail( self.email )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedEmail = transaction.getEmail()
        transaction.commit()
        self.assertTrue( receivedEmail == self.email )

    def testisActivated(self):
	# Test unactivated session
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        active = transaction.isActivated()
        transaction.commit()
        self.assertFalse( active )
        os.unlink( self.sessionPath )

	# Test already activated session
        Transaction.create( self.sessionPath , False , True )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        active = transaction.isActivated()
        transaction.commit()
        self.assertTrue( active )
        os.unlink( self.sessionPath )

	# Test session after activation
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.activate()
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        active = transaction.isActivated()
        transaction.commit()
        self.assertTrue( active )
        os.unlink( self.sessionPath )

     # Test session after inactivation
        Transaction.create( self.sessionPath , False , True )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        active = transaction.isActivated()
        self.assertTrue( active )
        transaction.inactivate()
        transaction.commit()
        active = transaction.isActivated()
        self.assertFalse( active )
        os.unlink( self.sessionPath )


    def testActivatingKey(self):
        Transaction.create( self.sessionPath , False , True , activatingKey = self.actkey , userEmail = None)
        transaction = Transaction( self.sessionPath , Transaction.READ )
        actKey = transaction.getActivatingKey()
        transaction.commit()
        self.assertTrue( actKey == self.actkey )


    def testAuthenticated(self):
        Transaction.create( self.sessionPath , True , True , activatingKey = self.actkey , userEmail = self.email , passwd = self.passwd )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        auth = transaction.isAuthenticated()
        transaction.commit()
        self.assertTrue( auth )


    def testPasswd(self):
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        sendPasswd = "monBeauMotDePasse"
        transaction.setPasswd( sendPasswd )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedPasswd =  transaction.getPasswd()
        transaction.commit()
        self.assertTrue( sendPasswd == receivedPasswd )


    def testCaptchaSolution( self ):
        sendSoluce = 'solution'
        Transaction.create( self.sessionPath , False , False )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setCaptchaSolution( sendSoluce )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedSoluce = transaction.getCaptchaSolution()
        transaction.commit()
        self.assertTrue( sendSoluce == receivedSoluce )
        transaction2 = Transaction( self.sessionPath , Transaction.READ )
        receivedSoluce = transaction2.getCaptchaSolution()
        self.assertTrue( sendSoluce == receivedSoluce )
        transaction2.commit()

    ################################
    #
    #  operations on Data
    #
    #################################

    def testHasData(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath)
        transaction = Transaction( self.sessionPath , Transaction.READ )
        self.assertTrue( transaction.hasData( self.dataID[1] ) )
        transaction.commit()

    def testRenameData( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath)
        newUserName = '__new_user_name_for_the_data__'
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.renameData( self.dataID[0] , newUserName )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        data = transaction.getData( self.dataID[0] )
        transaction.commit()
        self.assertTrue( newUserName == data[ 'userName' ] )

    def testGetAllData(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath)
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedData = transaction.getAllData()
        transaction.commit()
        self.assertTrue( len( receivedData ) == 2 )
        for data in receivedData:
            self.assertTrue( data in self.datas )

    def testRemoveData( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.removeData( self.dataID[0] )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        self.assertFalse( transaction.hasData( self.dataID[0] ) )
        transaction.commit()

    def testLinkJobInput2Data( self ):
        Transaction.create( self.sessionPath , False , True )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        sendData = self.datas[0]
        transaction.createData( sendData[ 'dataName' ] ,
                                sendData[ 'userName' ] ,
                                sendData[ 'size' ] ,
                                sendData[ 'Type' ] ,
                                sendData[ 'dataBegin' ] ,
                                sendData[ 'inputModes' ] ,
                                producedBy = [] ,
                                usedBy = []
                                )
        sendJob = self.jobs[ 0 ]
        transaction.createJob( sendJob['jobID'] ,
                                sendJob['userName'] ,
                                sendJob['programName'] ,
                                sendJob['status'] ,
                                sendJob['date'] ,
                                [] ,
                                []
                                )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.linkJobInput2Data( [ sendData[ 'dataName' ] ] , [ sendJob['jobID'] ])
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        data = transaction.getData( sendData[ 'dataName' ] )
        job = transaction.getJob( sendJob['jobID'])
        transaction.commit()
        self.assertEqual( data[ 'usedBy' ][0] , sendJob[ 'jobID' ] )
        self.assertEqual( job[ 'dataUsed' ][0] , sendData[ 'dataName' ] )

    def testLinkJobOutput2Data( self ):
        Transaction.create( self.sessionPath , False , True )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        sendData = self.datas[0]
        transaction.createData( sendData[ 'dataName' ] ,
                                sendData[ 'userName' ] ,
                                sendData[ 'size' ] ,
                                sendData[ 'Type' ] ,
                                sendData[ 'dataBegin' ] ,
                                sendData[ 'inputModes' ] ,
                                producedBy = [] ,
                                usedBy = []
                                )
        sendJob = self.jobs[ 0 ]
        transaction.createJob( sendJob['jobID'] ,
                                sendJob['userName'] ,
                                sendJob['programName'] ,
                                sendJob['status'] ,
                                sendJob['date'] ,
                                [] ,
                                []
                                )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.linkJobOutput2Data( [ sendData[ 'dataName' ] ] , [ sendJob['jobID'] ])
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        data = transaction.getData( sendData[ 'dataName' ] )
        job = transaction.getJob( sendJob['jobID'])
        transaction.commit()
        self.assertEqual( data[ 'producedBy' ][0] , sendJob[ 'jobID' ] )
        self.assertEqual( job[ 'dataProduced' ][0] , sendData[ 'dataName' ] )


    def testAddInputModes(self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.addInputModes( self.dataID[0] , [ 'paste' , 'db' ] )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        data = transaction.getData( self.dataID[0] )
        transaction.commit()
        result = ['paste' , 'db' , 'result']
        result.sort()
        data[ 'inputModes' ].sort()
        self.assertEqual( data[ 'inputModes' ] , result )
        #an inputMode must not be twice in the xml
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.addInputModes( self.dataID[0] , [ 'paste' ] )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        data = transaction.getData( self.dataID[0] )
        transaction.commit()
        data[ 'inputModes' ].sort()
        self.assertEqual( data[ 'inputModes' ] , result )

    def testCreateAndGetData( self ):
        Transaction.create( self.sessionPath , True , True , activatingKey = 'uneJolieCle' , userEmail = self.email , passwd = self.passwd )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        sendData = self.datas[0]
        transaction.createData( sendData[ 'dataName' ] ,
                                sendData[ 'userName' ] ,
                                sendData[ 'size' ] ,
                                sendData[ 'Type' ] ,
                                sendData[ 'dataBegin' ] ,
                                sendData[ 'inputModes' ] ,
                                producedBy = sendData[ 'producedBy' ] ,
                                usedBy = sendData[ 'usedBy' ]
                                )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedData = transaction.getData( sendData[ 'dataName' ] )
        transaction.commit()
        self.assertTrue( receivedData == sendData )

    ####################
    #
    #   jobs methods
    #
    ####################

    def testHasJob( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        jobid = "file://tmp/mobyle/results/dnadist/G25406684175968"
        transaction = Transaction( self.sessionPath , Transaction.READ )
        self.assertTrue( transaction.hasJob( jobid ) )
        self.assertFalse( transaction.hasJob( jobid.replace('G','Z') ) )
        transaction.commit()

    def testGetAllJobs( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath)
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedJobs = transaction.getAllJobs()
        transaction.commit()
        self.assertTrue( len( receivedJobs ) == 2 )

        for job in receivedJobs:
            self.assertTrue( job in self.jobs )

    def testCreateAndGetJob( self ):
        Transaction.create( self.sessionPath , False , True )
        sendJob = self.jobs[ 1 ]
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.createJob( sendJob['jobID'] ,
                                sendJob['userName'] ,
                                sendJob['programName'] ,
                                sendJob['status'] ,
                                sendJob['date'] ,
                                sendJob['dataUsed'] ,
                                sendJob['dataProduced']
                                )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        receivedJob = transaction.getJob( sendJob[ 'jobID' ] )
        transaction.commit()
        self.assertEqual( sendJob , receivedJob )


    def testRemoveJob( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.removeJob( self.jobID[1] )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        self.assertFalse( transaction.hasJob( self.jobID[1] ) )
        transaction.commit()

    def testRenameJob( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        newUserName = "mon beau job"
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.renameJob( self.jobID[1] , newUserName )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        job = transaction.getJob( self.jobID[1] )
        transaction.commit()
        self.assertEqual( newUserName , job[ 'userName' ] )

    def testUpdateJobStatus( self ):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        sendStatus = Mobyle.Status.Status( code = 7 ) #hold
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.updateJobStatus( self.jobID[0] , sendStatus )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        job = transaction.getJob( self.jobID[0] )
        transaction.commit()
        self.assertEqual( sendStatus , job[ 'status' ] )
        
    def testSetAndGetJobLabel(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        #there is not labels yet in jobs
        transaction = Transaction( self.sessionPath , Transaction.READ )
        label_recieved = transaction.getJobLabels(self.jobID[0])
        transaction.commit()
        self.assertEqual( label_recieved , [] )
        #add one label
        label_send = ['label_1']
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setJobLabels( self.jobID[0] , label_send )
        transaction.commit()
        #get one label
        transaction = Transaction( self.sessionPath , Transaction.READ )
        label_recieved = transaction.getJobLabels(self.jobID[0])
        transaction.commit()
        self.assertEqual( label_recieved , label_send )
        #add 2 labels
        label_send = ['label_2', 'label_2_bis']
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setJobLabels( self.jobID[1] , label_send )
        transaction.commit()
        #get 2 labels
        transaction = Transaction( self.sessionPath , Transaction.READ )
        label_recieved = transaction.getJobLabels(self.jobID[1])
        transaction.commit()
        self.assertEqual( label_recieved , label_send )
        #add label in job which have already labels
        new_label = [ 'label_3', 'label_3_bis' ]
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setJobLabels( self.jobID[1] , new_label )
        transaction.commit()
        #get 2 new labels
        transaction = Transaction( self.sessionPath , Transaction.READ )
        label_recieved = transaction.getJobLabels( self.jobID[1] )
        label_recieved = transaction.getJobLabels( self.jobID[1] )
        transaction.commit()
        self.assertEqual( label_recieved , new_label )
        
        
    def testgetAllUniqueLabels(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        label_1= [ 'label_1', 'label_1_bis' ]
        label_2=  label_1 + [ 'label_2' ]
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setJobLabels( self.jobID[0] , label_1 )
        transaction.setJobLabels( self.jobID[1] , label_2 )
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        label_recieved = transaction.getJobLabels( self.jobID[1] )
        transaction.commit()
        s = set( label_1 + label_2 )
        unique = list( s )
        unique.sort()
        label_recieved.sort()
        self.assertEqual( label_recieved , unique )
        
    def testSetAndGetJobDescription(self):
        shutil.copy( self.xmlSourcePath , self.sessionPath )
        job_description = "a new beautiful description for this job"
        transaction = Transaction( self.sessionPath , Transaction.WRITE )
        transaction.setJobDescription( self.jobID[0] , job_description)
        transaction.commit()
        transaction = Transaction( self.sessionPath , Transaction.READ )
        jobDescription_recieved = transaction.getJobDescription( self.jobID[0] )
        transaction.commit()
        self.assertEqual( jobDescription_recieved , job_description )
        transaction = Transaction( self.sessionPath , Transaction.READ )
        jobDescription_recieved = transaction.getJobDescription( self.jobID[1] )
        transaction.commit()
        self.assertEqual( None , jobDescription_recieved )
        
        
if __name__ == '__main__':
    unittest.main()