def test_get(self): """Test the get method raises an exception, since RabbitMQ doesn't implement a way to examine what's in a queue.""" # test with old style config jobs = priorityjobs.Priorityjobs(config=self.old_config) self.assertRaises(NotImplementedError, jobs.get) # test with new style config jobs = priorityjobs.Priorityjobs(config=self.new_config) self.assertRaises(NotImplementedError, jobs.get)
def test_create(self): """Test that the create() method properly creates the job, and errors when not given the proper arguments.""" # with old config with patch('socorro.external.rabbitmq.priorityjobs.ConnectionContext' ) as mocked_connection: mocked_connection.return_value = MagicMock jobs = priorityjobs.Priorityjobs(config=self.old_config) self.assertEqual(mocked_connection.call_count, 1) self.assertEqual(jobs.config.host, 'localhost') self.assertEqual(jobs.config.port, 5672) self.assertEqual(jobs.config.virtual_host, '/') self.assertEqual(jobs.config.rabbitmq_user, 'guest') self.assertEqual(jobs.config.rabbitmq_password, 'guest') self.assertEqual(jobs.config.standard_queue_name, 'socorro.normal') self.assertEqual(jobs.config.priority_queue_name, 'socorro.priority') self.assertEqual(jobs.create(uuid='b1'), True) # with new config with patch( 'socorro.external.rabbitmq.priorityjobs.pika') as mocked_pika: jobs = priorityjobs.Priorityjobs(config=self.new_config) mocked_connection = self.new_config.rabbitmq.rabbitmq_class mocked_connection.return_value.return_value = MagicMock() self.assertEqual(mocked_connection.call_count, 1) self.assertEqual(jobs.config.host, 'localhost') self.assertEqual(jobs.config.port, 5672) self.assertEqual(jobs.config.virtual_host, '/') self.assertEqual(jobs.config.rabbitmq_user, 'guest') self.assertEqual(jobs.config.rabbitmq_password, 'guest') self.assertEqual(jobs.config.standard_queue_name, 'socorro.normal') self.assertEqual(jobs.config.priority_queue_name, 'socorro.priority') self.assertEqual(jobs.create(uuid='b1'), True) #.................................................................. self.assertRaises(priorityjobs.MissingArgumentError, jobs.create) self.assertTrue( mocked_connection.return_value.channel. \ basic_publish.called_once_with( '', 'socorro.priority', 'b1', mocked_pika.BasicProperties.return_value ) )
def test_create(self): """Test that the create() method properly creates the job, and errors when not given the proper arguments.""" jobs = priorityjobs.Priorityjobs(config=self.config) jobs.context = Mock() self.assertEqual(jobs.create(uuid='b1'), True) #...................................................................... self.assertRaises(priorityjobs.MissingArgumentError, jobs.create)
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') 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)