Skip to content

Commit d7c48ee

Browse files
committed
[822] add zone times to model
Add zone creation time and zone modification time to the zone model.
1 parent 01c4794 commit d7c48ee

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎irods/models.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Zone(Model):
4747
type = Column(String, "ZONE_TYPE", 103)
4848
connection = Column(String, "ZONE_CONNECTION", 104)
4949
comment = Column(String, "ZONE_COMMENT", 105)
50+
create_time = Column(DateTime, "ZONE_CREATE_TIME", 106)
51+
modify_time = Column(DateTime, "ZONE_MODIFY_TIME", 107)
5052

5153

5254
class User(Model):

‎irods/test/zone_test.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import time
56
import unittest
67
from datetime import datetime as _datetime
78

@@ -106,6 +107,37 @@ def test_create_remote_zone_and_update_properties__issue_816(self):
106107
if newzone:
107108
newzone.remove()
108109

110+
def test_zone_create_and_modify_times__issue_822(self):
111+
newzone = None
112+
try:
113+
# Create new zone
114+
newzonename = "otherzone"
115+
newzone = self.sess.zones.create(newzonename, "remote")
116+
query_zone = self.sess.query(Zone).filter(Zone.name == newzonename).one()
117+
create_time = query_zone[Zone.create_time]
118+
old_modify_time = query_zone[Zone.modify_time]
119+
120+
# Confirm that creation/modification are datetimes
121+
self.assertIsInstance(create_time, _datetime)
122+
self.assertIsInstance(old_modify_time, _datetime)
123+
124+
# Confirm we get the same result via query vs. iRODSZone object attribute
125+
self.assertEqual(create_time, self.sess.zones.get(newzonename).create_time)
126+
self.assertEqual(old_modify_time, self.sess.zones.get(newzonename).modify_time)
127+
128+
# Confirm modify time is updated after comment change after more than one second,
129+
# but create time is not changed.
130+
time.sleep(1.5)
131+
newzone.modify("comment", "some comment")
132+
query_zone = self.sess.query(Zone).filter(Zone.name == newzonename).one()
133+
self.assertEqual(query_zone[Zone.create_time], create_time)
134+
self.assertGreater(query_zone[Zone.modify_time], old_modify_time)
135+
self.assertGreater(self.sess.zones.get(newzonename).modify_time, old_modify_time)
136+
137+
finally:
138+
if newzone:
139+
newzone.remove()
140+
109141

110142
if __name__ == "__main__":
111143
# let the tests find the parent irods lib

‎irods/zone.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def __init__(self, manager, result=None):
1111
self.type = result[Zone.type]
1212
self.connection = result[Zone.connection]
1313
self.comment = result[Zone.comment]
14+
self.create_time = result[Zone.create_time]
15+
self.modify_time = result[Zone.modify_time]
1416

1517
def remove(self):
1618
self.manager.remove(self.name)

0 commit comments

Comments
 (0)