def test_get_name(get_mock_boto): fake_conn = FakeConn() fake_queue = FakeQueue() fake_conn.set_queue(fake_queue) mock_obj = get_mock_boto mock_obj.return_value = fake_conn sqs = SQSWrapper("some-queue") assert sqs.get_queue_name() == "some-queue"
def et_scanner_main(args): """ Create an instance of ETScanner and run it once. """ setup_config(args, 'ETScanner') sqs_scanner_queue = SQSWrapper(read_string("sqs.et_scanner_queue_name")) sqs_worker_queue = SQSWrapper(read_string("sqs.et_queue_name")) scanner = ETScanner(TableConnection.get_connection('ScheduledJobs'), sqs_scanner_queue, sqs_worker_queue, Mailer(args.run_local)) scanner.run()
def test_clear(get_mock_boto): fake_conn = FakeConn() fake_queue = FakeQueue() fake_queue.set_messages([object()]) fake_conn.set_queue(fake_queue) mock_obj = get_mock_boto mock_obj.return_value = fake_conn sqs = SQSWrapper("some-queue") sqs.clear() assert fake_queue.msgs is None
def test_get_messages_exception_thrown_out(get_mock_boto): fake_conn = FakeConn() fake_queue = FakeQueue() fake_conn.set_queue(fake_queue) fake_queue.exception = True # set it to throw boto error mock_obj = get_mock_boto mock_obj.return_value = fake_conn sqs = SQSWrapper("some-queue", None) with pytest.raises(BotoServerError): sqs.get_messages_from_queue() mock_obj.assert_called_once_with('us-west-2', **get_test_creds())
def test_delete_msg_batch(get_mock_boto): fake_conn = FakeConn() fake_queue = FakeQueue() fake_conn.set_queue(fake_queue) mock_obj = get_mock_boto mock_obj.return_value = fake_conn sqs = SQSWrapper("some-queue") test_msgs = [object()] sqs.delete_message_batch_from_queue(test_msgs) mock_obj.assert_called_once_with('us-west-2', **get_test_creds()) assert fake_queue.deleted_msgs == test_msgs
def test_get_messages_successful_case_no_errors(get_mock_boto): fake_conn = FakeConn() fake_queue = FakeQueue() fake_conn.set_queue(fake_queue) fake_queue.set_messages([object()]) mock_obj = get_mock_boto mock_obj.return_value = fake_conn sqs = SQSWrapper("some-queue", None) ret = sqs.get_messages_from_queue() assert len(ret) == 1, "Expected 1 message from sqs queue" mock_obj.assert_called_once_with('us-west-2', **get_test_creds())
def test_constructor_throws_on_queue_being_none(get_mock_boto): mock_obj = get_mock_boto fake_conn = FakeConn() mock_obj.return_value = fake_conn with pytest.raises(ValueError): SQSWrapper("test") mock_obj.assert_called_once_with('us-west-2', **get_test_creds())
def test_set_class_type_works_fine(get_mock_boto): mock_obj = get_mock_boto fake_conn = FakeConn() fake_conn.queue = FakeQueue() mock_obj.return_value = fake_conn SQSWrapper("test", object) mock_obj.assert_called_once_with('us-west-2', **get_test_creds()) assert fake_conn.queue.class_type == object
def get_scanner_queue(etl_type): """ Return the scanner sqs for jobs to send a message when post a job to wake up the scanner :param etl_type: et or load :type etl_type: string in ['et', 'load'] """ return SQSWrapper( read_string("sqs.{0}_scanner_queue_name".format(etl_type)))
def test_init_variables_initialized_from_config_correctly(get_mock_boto): mock_obj = get_mock_boto fake_conn = FakeConn() fake_queue = FakeQueue() fake_conn.set_queue(fake_queue) mock_obj.return_value = fake_conn sqs = SQSWrapper("testq", None) assert sqs._num_messages_to_fetch == 2, "expected num_msgs_per_fetch to \ be 2 from config" assert sqs._wait_time_secs == 20, "expected wait_time_secs to be 20 from \ config" assert sqs._queue is not None, "queue should not be None at \ end of constructor" mock_obj.assert_called_once_with('us-west-2', **get_test_creds())
def _get_sqs_wrapper(self, queue_name, class_type): return SQSWrapper(queue_name, class_type)