def test_worker_settings_simple(): ''' tests for simple worker settings ''' worker_config = { 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'description': 'Test worker', 'instances': 1, 'parameters': { 'param1': 'values1', 'param2': 'values2', }, 'inputs': 'input-queue', 'outputs': 'output-queue', } settings = Settings(**worker_config) assert settings.name == 'TestWorker' assert settings.type == 'eventsflow.workers.DummyWorker' assert settings.instances == 1 assert settings.parameters == { 'param1': 'values1', 'param2': 'values2', } assert settings.inputs == { 'default': { 'refs': 'input-queue', 'events': [], }, } assert settings.outputs == { 'default': { 'refs': 'output-queue', 'events': [], }, }
def test_worker_settings_no_name(): ''' test for worker settings without worker name ''' with pytest.raises(TypeError): Settings(**{ 'name': None, })
def test_worker_settings_simple_list_of_queues(): ''' test for simple worker settings with a list of queues ''' worker_config = { 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'description': 'Test worker', 'instances': 1, 'parameters': { 'param1': 'values1', 'param2': 'values2', }, 'inputs': [ { 'name': 'default', 'refs': 'input-queue', 'events': [], }, ], 'outputs': [ { 'name': 'default', 'refs': 'output-queue', }, { 'name': 'monitoring', 'refs': 'monitoring-queue', }, ], } settings = Settings(**worker_config) assert vars(settings) == { 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'instances': 1, 'parameters': { 'param1': 'values1', 'param2': 'values2', }, 'inputs': { 'default': { 'refs': 'input-queue', 'events': [], }, }, 'outputs': { 'default': { 'refs': 'output-queue', 'events': [], }, 'monitoring': { 'refs': 'monitoring-queue', 'events': [], }, }, }
def test_worker_settings_no_type(): ''' test for worker settings without worker type ''' with pytest.raises(TypeError): Settings(**{ 'name': 'TestWorker', 'type': None, })
def create_test_processing_worker(): ''' return Test Processing Worker instance ''' return ProcessingWorker( Settings( **{ 'name': 'TestProcessingWorker', 'type': 'eventsflow.workers.process.ProcessingWorker', }))
def test_worker_settings_incorrect_parameters(): ''' test for worker settings with incorrect parameters ''' with pytest.raises(TypeError): Settings( **{ 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'parameters': [], })
def test_process_worker_init(): ''' test for Processing Worker Initialization ''' settings = Settings(**{ 'name': 'TestProcessingWorker', 'type': 'eventsflow.workers.process.ProcessingWorker', 'inputs': 'default', }) worker = ProcessingWorker(settings) assert worker
def test_worker_settings_no_parameters(): ''' test for worker settings without paramters ''' with pytest.raises(TypeError): Settings( **{ 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'parameters': { 'batch_size': 100 }, 'instances': 0, })
def test_worker_settings_incorrect_queue_defs(): ''' test for worker settings with incorrect queue definition ''' with pytest.raises(TypeError): Settings( **{ 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'parameters': { 'batch_size': 100 }, 'instances': 1, 'inputs': [ 'input-queue', ], })
def test_worker_settings_none_queue(): ''' test for worker settings without queue ''' settings = Settings( **{ 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'parameters': { 'batch_size': 100 }, 'instances': 1, 'inputs': None, }) assert settings.inputs == { 'default': { 'refs': None, 'events': [], }, }
def test_worker_settings_simple_as_dict(): ''' test for simple worker settings specified as dict ''' worker_config = { 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'description': 'Test worker', 'instances': 1, 'parameters': { 'param1': 'values1', 'param2': 'values2', }, 'inputs': 'input-queue', 'outputs': 'output-queue', } settings = Settings(**worker_config) assert vars(settings) == { 'name': 'TestWorker', 'type': 'eventsflow.workers.DummyWorker', 'instances': 1, 'parameters': { 'param1': 'values1', 'param2': 'values2', }, 'inputs': { 'default': { 'refs': 'input-queue', 'events': [], }, }, 'outputs': { 'default': { 'refs': 'output-queue', 'events': [], }, }, }