"""Tests for orders (encoding_queue) logic.""" import pytest from src.constants import fields from src.constants import maxwell from src.logic import orders @pytest.mark.parametrize( 'records, update_called, call_args', ( ({maxwell.TYPE_UPDATE: [ {fields.ENCODING_ORDER_TYPE: 't1', fields.ENCODING_ORDER_ID: 100, fields.PRIORITY: 2}, {fields.ENCODING_ORDER_TYPE: 't2', fields.ENCODING_ORDER_ID: 200, fields.PRIORITY: 1} ]}, 2, [(100, 2), (200, 1)]), ({maxwell.TYPE_UPDATE: [ {fields.ENCODING_ORDER_TYPE: 't', fields.ENCODING_ORDER_ID: 100, fields.PRIORITY: 2}, {fields.ENCODING_ORDER_TYPE: 'ignore', fields.ENCODING_ORDER_ID: 200, fields.PRIORITY: 1} ]}, 1, [(100, 2)]), ({maxwell.TYPE_INSERT: [{}]}, 0, []), ) ) def test_process_encoding_queue(records, update_called, call_args, mocker): """Test process_encoding_queue function.""" mocked_config = mocker.patch('src.logic.orders.config') mocked_config.IGNORE_ORDER_TYPES = ('ignore',) mocked_jobs = mocker.patch('src.logic.orders.jobs') mocked_update = mocked_jobs.update_priority orders.process_encoding_queue(records) assert mocked_update.call_count == update_called if call_args: assert call_args == [a[0] for a in mocked_update.call_args_list]