Skip to content

Commit

Permalink
provide unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
amaltaro committed Apr 14, 2023
1 parent f66884a commit 4ff83a2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import unittest

# WMCore modules
from WMCore.MicroService.MSPileup.MSPileupData import MSPileupData, stripKeys
from WMCore.MicroService.MSPileup.MSPileupData import MSPileupData, stripKeys, getNewTimestamp
from WMCore.MicroService.MSPileup.MSPileupError import MSPILEUP_SCHEMA_ERROR
from Utils.Timers import encodeTimestamp, decodeTimestamp
from Utils.Timers import encodeTimestamp, decodeTimestamp, gmtimeSeconds


class MSPileupTest(unittest.TestCase):
Expand Down Expand Up @@ -150,6 +150,29 @@ def testMSPileupQuery(self):
res = self.mgr.getPileup(spec)
self.assertEqual(len(res), 0)

def testGetNewTimestamp(self):
"""Test the getNewTimestamp function"""
timeNow = gmtimeSeconds()
resp = getNewTimestamp({})
self.assertEqual(len(resp), 1)
self.assertTrue(resp['lastUpdateTime'] >= timeNow)

resp = getNewTimestamp({'lastUpdateTime': 1})
self.assertEqual(len(resp), 1)
self.assertTrue(resp['lastUpdateTime'] >= timeNow)

resp = getNewTimestamp({'active': True})
self.assertEqual(len(resp), 2)
self.assertTrue(resp['lastUpdateTime'] >= timeNow)
self.assertTrue(resp['activatedOn'] >= timeNow)
self.assertFalse('deactivatedOn' in resp)

resp = getNewTimestamp({'active': False})
self.assertEqual(len(resp), 2)
self.assertTrue(resp['lastUpdateTime'] >= timeNow)
self.assertTrue(resp['deactivatedOn'] >= timeNow)
self.assertFalse('activatedOn' in resp)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4ff83a2

Please sign in to comment.