11#! /usr/bin/env python
22
3+ import calendar
4+ import datetime
5+ import logging
36import os
47import sys
5- import unittest
68import time
7- import calendar
9+ import unittest
810
911import irods .test .helpers as helpers
1012import tempfile
1113from irods .session import iRODSSession
1214import irods .exception as ex
1315import irods .keywords as kw
14- from irods .ticket import Ticket
16+ from irods .ticket import list_tickets , Ticket
1517from irods .models import TicketQuery , DataObject , Collection
1618
1719
20+ logger = logging .getLogger (__name__ )
21+
22+
1823# As with most of the modules in this test suite, session objects created via
1924# make_session() are implicitly agents of a rodsadmin unless otherwise indicated.
2025# Counterexamples within this module shall be obvious as they are instantiated by
@@ -29,6 +34,17 @@ def gmtime_to_timestamp(gmt_struct):
2934 )
3035
3136
37+ def delete_tickets (session , dry_run = False ):
38+ for res in session .query (TicketQuery .Ticket ):
39+ t = Ticket (session , result = res )
40+ if dry_run in (False , None ):
41+ t .delete (** {kw .ADMIN_KW : "" })
42+ elif isinstance (dry_run , list ):
43+ dry_run .append (t )
44+ else :
45+ logger .info ('Found ticket: %s' ,t .string )
46+
47+
3248def delete_my_tickets (session ):
3349 my_userid = session .users .get (session .username ).id
3450 my_tickets = session .query (TicketQuery .Ticket ).filter (
@@ -358,6 +374,27 @@ def test_coll_read_ticket_between_rodsusers(self):
358374 os .unlink (file_ .name )
359375 alice .cleanup ()
360376
377+ def test_new_attributes_in_tickets__issue_801 (self ):
378+
379+ if (admin := helpers .make_session ()).server_version < (4 , 3 , 0 ):
380+ self .skipTest ('"create_time" and "modify_time" not supported for Ticket' )
381+
382+ try :
383+ with self .login (self .bob ) as bob :
384+ bobs_ticket = Ticket (bob )
385+ bobs_ticket .issue ('write' , helpers .home_collection (bob ))
386+ time .sleep (2 )
387+ bobs_ticket .modify ('add' , 'user' , admin .username )
388+ bobs_ticket = Ticket (bob , result = [], ticket = bobs_ticket .string )
389+ self .assertGreaterEqual (
390+ bobs_ticket .modify_time ,
391+ bobs_ticket .create_time + datetime .timedelta (seconds = 1 )
392+ )
393+
394+ admin_ticket_for_bob = Ticket (admin , result = [], ticket = bobs_ticket .string )
395+ self .assertEqual (admin_ticket_for_bob .id , bobs_ticket .id )
396+ finally :
397+ admin_ticket_for_bob .delete (** {kw .ADMIN_KW :'' })
361398
362399class TestTicketOps (unittest .TestCase ):
363400
@@ -456,6 +493,21 @@ def test_coll_ticket_write(self):
456493 self ._ticket_write_helper (obj_type = "coll" )
457494
458495
496+ def test_list_tickets__issue_120 (self ):
497+
498+ ses = self .sess
499+
500+ # t first assigned as a "utility" Ticket object
501+ t = Ticket (ses ).issue ('read' , helpers .home_collection (ses ))
502+ self .assertGreater (len (t .string ) , 5 )
503+
504+ # This time, t receives attributes from the GenQuery row result
505+ t = Ticket (ses , result = [], ticket = t .string )
506+
507+ # Check an id attribute is present and listed in the results from list_tickets
508+ self .assertIn (t .id , (_ .id for _ in list_tickets (ses )))
509+
510+
459511if __name__ == "__main__" :
460512 # let the tests find the parent irods lib
461513 sys .path .insert (0 , os .path .abspath ("../.." ))
0 commit comments