def test_create(self): jobs = priorityjobs.Priorityjobs(config=self.config) #...................................................................... # Test 1: a new job params = {"uuid": "b1"} res = jobs.create(**params) res_expected = True self.assertEqual(res, res_expected) # Verify that job has been created in the DB res = jobs.get(**params) res_expected = {"hits": [{"uuid": "b1"}], "total": 1} self.assertEqual(res, res_expected) #...................................................................... # Test 2: an already existing job params = {"uuid": "a2"} res = jobs.create(**params) res_expected = False self.assertEqual(res, res_expected) #...................................................................... # Test 3: missing argument params = {} self.assertRaises(priorityjobs.MissingArgumentError, jobs.create, **params)
def get(self, **kwargs): """Return JSON data of a crash report, given its uuid. """ filters = [ ('uuid', None, 'str'), ('datatype', None, 'str') ] params = external_common.parse_arguments(filters, kwargs) if not params.uuid: raise MissingArgumentError('uuid') if not params.datatype: raise MissingArgumentError('datatype') store = self.config.filesystem.filesystem_class(self.config.filesystem) datatype_method_mapping = { 'raw': 'get_raw_dump', 'meta': 'get_raw_crash', 'processed': 'get_processed' } get = store.__getattribute__(datatype_method_mapping[params.datatype]) try: if params.datatype == 'raw': return (get(params.uuid), 'application/octet-stream') else: return get(params.uuid) except CrashIDNotFound: if params.datatype == 'processed': self.get(datatype='raw', uuid=params.uuid) j = priorityjobs.Priorityjobs(config=self.config) j.create(uuid=params.uuid) raise ResourceUnavailable(params.uuid) raise ResourceNotFound(params.uuid)
def get(self, **kwargs): """Return JSON data of a crash report, given its uuid. """ filters = [ ("uuid", None, "str"), ("datatype", None, "str") ] params = external_common.parse_arguments(filters, kwargs) if not params.uuid: raise MissingOrBadArgumentError( "Mandatory parameter 'uuid' is missing or empty") if not params.datatype: raise MissingOrBadArgumentError( "Mandatory parameter 'datatype' is missing or empty") if hasattr(self.config, 'hbase'): config = self.config.hbase store = crashstorage.HBaseCrashStorage(config) datatype_method_mapping = { "raw": "get_raw_dump", "meta": "get_raw_crash", "processed": "get_processed" } else: # old middleware config = self.config import socorro.storage.crashstorage as cs store = cs.CrashStoragePool( config, storageClass=config.hbaseStorageClass ).crashStorage() datatype_method_mapping = { "raw": "get_raw_dump", "meta": "get_meta", "processed": "get_processed" } get = store.__getattribute__(datatype_method_mapping[params.datatype]) try: if params.datatype == 'raw': return (get(params.uuid), 'application/octet-stream') else: return get(params.uuid) except (CrashIDNotFound, OoidNotFoundException): if params.datatype == 'processed': self.get(datatype='raw', uuid=params.uuid) j = priorityjobs.Priorityjobs(config=self.config) j.create(uuid=params.uuid) raise ResourceUnavailable(params.uuid) raise ResourceNotFound(params.uuid)
def test_get(self): jobs = priorityjobs.Priorityjobs(config=self.config) #...................................................................... # Test 1: a valid job params = { "uuid": "a1" } res = jobs.get(**params) res_expected = { "hits": [ { "uuid": "a1" } ], "total": 1 } self.assertEqual(res, res_expected) #...................................................................... # Test 2: an invalid job params = { "uuid": "b2" } res = jobs.get(**params) res_expected = { "hits": [], "total": 0 } self.assertEqual(res, res_expected) #...................................................................... # Test 3: missing argument params = {} self.assertRaises(priorityjobs.MissingOrBadArgumentError, jobs.get, **params)