Skip to content

Commit

Permalink
Provide unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Dec 16, 2024
1 parent 1e87be3 commit f8c5ed9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Unit tests for MSTransferorError.py module
Author: Valentin Kuznetsov <vkuznet [AT] gmail [DOT] com>
"""

# system modules
import unittest

# WMCore modules
from WMCore.MicroService.MSTransferor.MSTransferorError import MSTransferorStorageError, MSPILEUP_STORAGE_ERROR


class TransferorErrorTest(unittest.TestCase):
"Unit test for TransferorError module"

def testError(self):
"""Test MSTransferorError"""
rec = {'workflow': 'testWorkflow'}

# test custom emessage
msg = 'test error'
err = MSTransferorStorageError(msg, **rec)
edict = err.error()
self.assertEqual(edict['message'], msg)
self.assertEqual(edict['code'], MSPILEUP_STORAGE_ERROR)
self.assertEqual(edict['data'], rec)

# test default assigned message
err = MSTransferorStorageError('', **rec)
edict = err.error()
self.assertEqual(edict['message'], 'storage error')
self.assertEqual(edict['code'], MSPILEUP_STORAGE_ERROR)
self.assertEqual(edict['data'], rec)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from Utils.PythonVersion import PY3
from WMCore.MicroService.MSTransferor.MSTransferor import MSTransferor
from WMQuality.Emulators.EmulatedUnitTestCase import EmulatedUnitTestCase
from WMCore.MicroService.MSTransferor.MSTransferorError import MSTransferorStorageError
from WMCore.MicroService.MSTransferor.DataStructs.Workflow import Workflow


def getTestFile(partialPath):
Expand Down Expand Up @@ -141,6 +143,34 @@ def notestRequestRecord(self):
for idx in range(len(resp)):
self.assertItemsEqual(resp[idx], expectedRes[idx])

def testUpdateStorage(self):
"""
Test updateStorage method. We should be able to save and read
JSON objects to persistent storage of MSTransferor.
"""
# use default storage and check save/read operations
wflow = 'testWorkflow'
status = self.msTransferor.updateStorage(wflow)
self.assertEqual(status, 'ok')
wflowObject = Workflow(wflow, {'DbsUrl': 'https://cmsweb-testbed.cern.ch', 'RequestType': 'StoreResults'})
self.msTransferor.checkDataReplacement(wflowObject)
self.assertEqual(wflowObject.dataReplacement, True)

def testUpdateSites(self):
"""
Test the updateSites method.
"""
rec = {'workflow': 'testWorkflow'}
res = self.msTransferor.updateSites(rec)
self.assertEqual(res, [])

# now let's test transferor error
self.msTransferor.storage = '/bla'
res = self.msTransferor.updateSites(rec)
err = MSTransferorStorageError("[Errno 2] No such file or directory: '/bla/testWorkflow'", **rec)
self.assertEqual(res, [err.error()])
self.assertEqual(err.code, 2)


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

0 comments on commit f8c5ed9

Please sign in to comment.