11#! /usr/bin/env python
22
3+ import calendar
4+ import datetime
35import os
46import sys
5- import unittest
67import time
7- import calendar
8+ import unittest
89
910import irods .test .helpers as helpers
1011import tempfile
1112from irods .session import iRODSSession
1213import irods .exception as ex
1314import irods .keywords as kw
14- from irods .ticket import Ticket
15+ from irods .ticket import ticket_iterator , Ticket
1516from irods .models import TicketQuery , DataObject , Collection
1617
1718
@@ -48,7 +49,6 @@ def login(self, user):
4849 user = user .name ,
4950 password = self .users [user .name ],
5051 )
51-
5252 @staticmethod
5353 def irods_homedir (sess , path_only = False ):
5454 path = f"/{ sess .zone } /home/{ sess .username } "
@@ -73,6 +73,8 @@ def setUp(self):
7373 u = ses .users .get (ses .username )
7474 if u .type != "rodsadmin" :
7575 self .skipTest ("""Test runnable only by rodsadmin.""" )
76+ self .rods_admin_name = ses .username
77+
7678 self .host = ses .host
7779 self .port = ses .port
7880 self .zone = ses .zone
@@ -358,6 +360,29 @@ def test_coll_read_ticket_between_rodsusers(self):
358360 os .unlink (file_ .name )
359361 alice .cleanup ()
360362
363+ def test_new_attributes_in_tickets__issue_801 (self ):
364+ # Specifically we are testing that 'modify_time' and 'create_time' attributes function as expected,
365+ # and that other attributes such as 'id' are also present.
366+
367+ bobs_ticket = None
368+
369+ try :
370+ with self .login (self .bob ) as bob :
371+ bobs_ticket = Ticket (bob ).issue ('write' , helpers .home_collection (bob ))
372+ time .sleep (2 )
373+ bobs_ticket .modify ('add' , 'user' , self .rods_admin_name )
374+
375+ # Reload the ticket, this time with the full complement of attributes present.
376+ bobs_ticket = next (ticket_iterator (bob , filter_args = [TicketQuery .Ticket .string == bobs_ticket .string ]))
377+
378+ self .assertGreaterEqual (
379+ bobs_ticket .modify_time ,
380+ bobs_ticket .create_time + datetime .timedelta (seconds = 1 )
381+ )
382+ finally :
383+ if bobs_ticket :
384+ bobs_ticket .delete ()
385+
361386
362387class TestTicketOps (unittest .TestCase ):
363388
@@ -456,6 +481,28 @@ def test_coll_ticket_write(self):
456481 self ._ticket_write_helper (obj_type = "coll" )
457482
458483
484+ def test_ticket_iterator__issue_120 (self ):
485+
486+ ses = self .sess
487+ t = None
488+
489+ try :
490+ # t first assigned as a "utility" Ticket object
491+ t = Ticket (ses ).issue ('read' , helpers .home_collection (ses ))
492+
493+ # This time, t receives attributes from a query result: notably the id, which we use for the next test.
494+ t = Ticket (
495+ ses ,
496+ result = ses .query (TicketQuery .Ticket ).filter (TicketQuery .Ticket .string == t .string ).one ()
497+ )
498+
499+ # Check an id attribute is present and listed in the results from list_tickets
500+ self .assertIn (t .id , (_ .id for _ in ticket_iterator (ses )))
501+ finally :
502+ if t :
503+ t .delete ()
504+
505+
459506if __name__ == "__main__" :
460507 # let the tests find the parent irods lib
461508 sys .path .insert (0 , os .path .abspath ("../.." ))
0 commit comments