Skip to content

Commit c9d9291

Browse files
committed
Merge pull request pandas-dev#144 from manahl/read_autit_log_by_message
Read audit messages by log message and symbol
2 parents 839c090 + 11f8da8 commit c9d9291

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

arctic/store/version_store.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def has_symbol(self, symbol, as_of=None):
196196
except NoDataFoundException:
197197
return False
198198

199-
def read_audit_log(self, symbol):
199+
def read_audit_log(self, symbol=None, message=None):
200200
"""
201201
Return the audit log associated with a given symbol
202202
@@ -205,7 +205,16 @@ def read_audit_log(self, symbol):
205205
symbol : `str`
206206
symbol name for the item
207207
"""
208-
query = {'symbol': symbol}
208+
query = {}
209+
if symbol:
210+
if isinstance(symbol, six.string_types):
211+
query['symbol'] = {'$regex': symbol}
212+
else:
213+
query['symbol'] = {'$in': list(symbol)}
214+
215+
if message is not None:
216+
query['message'] = message
217+
209218
return list(self._audit.find(query, sort=[('_id', -1)],
210219
projection={'_id': False}))
211220

tests/integration/store/test_version_store_audit.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
2012-11-09 17:06:11.040 | 3.0""")
4141

4242
symbol = 'TS1'
43+
symbol2 = 'TS2'
44+
symbol3 = 'TS3'
4345

4446

4547
def test_ArcticTransaction_can_do_first_writes(library):
@@ -118,6 +120,46 @@ def test_metadata_changes_writes(library):
118120
assert library.read(symbol, audit_log[0]['new_v']).metadata == {'some': 'data', 'original': 'data'}
119121

120122

123+
124+
def test_audit_read(library):
125+
with ArcticTransaction(library, symbol3, 'u3', 'foo') as mt:
126+
mt.write(symbol3, ts1)
127+
128+
with ArcticTransaction(library, symbol, 'u1', 'l1') as mt:
129+
mt.write(symbol, ts1)
130+
131+
with ArcticTransaction(library, symbol, 'u2', 'l2') as mt:
132+
mt.write(symbol, ts2)
133+
134+
with ArcticTransaction(library, symbol2, 'u2', 'l2') as mt:
135+
mt.write(symbol2, ts2)
136+
137+
138+
l2_audit_log = library.read_audit_log(message='l2')
139+
140+
assert l2_audit_log == [{u'new_v': 1, u'symbol': u'TS2', u'message': u'l2', u'user': u'u2', u'orig_v': 0},
141+
{u'new_v': 2, u'symbol': u'TS1', u'message': u'l2', u'user': u'u2', u'orig_v': 1},
142+
]
143+
144+
symbol_audit_log = library.read_audit_log(symbol=symbol)
145+
146+
assert symbol_audit_log == [{u'new_v': 2, u'symbol': u'TS1', u'message': u'l2', u'user': u'u2', u'orig_v': 1},
147+
{u'new_v': 1, u'symbol': u'TS1', u'message': u'l1', u'user': u'u1', u'orig_v': 0}]
148+
149+
150+
symbols_audit_log = library.read_audit_log(symbol=[symbol, symbol2])
151+
152+
assert symbols_audit_log == [{u'new_v': 1, u'symbol': u'TS2', u'message': u'l2', u'user': u'u2', u'orig_v': 0},
153+
{u'new_v': 2, u'symbol': u'TS1', u'message': u'l2', u'user': u'u2', u'orig_v': 1},
154+
{u'new_v': 1, u'symbol': u'TS1', u'message': u'l1', u'user': u'u1', u'orig_v': 0}]
155+
156+
157+
symbol_message_audit_log = library.read_audit_log(symbol=symbol, message='l2')
158+
159+
assert symbol_message_audit_log == [{u'new_v': 2, u'symbol': u'TS1', u'message': u'l2', u'user': u'u2', u'orig_v': 1}, ]
160+
161+
162+
121163
def test_cleanup_orphaned_versions_integration(library):
122164
_id = ObjectId.from_datetime(dt(2013, 1, 1))
123165
with patch('bson.ObjectId', return_value=_id):

0 commit comments

Comments
 (0)