"""Functional tests around meta update queue.""" import json from unittest.mock import MagicMock from oto import response from oto import status as http_status import pytest from product_workflow.logic import meta_update_queue from tests.testutils import db @pytest.fixture def meta_update_payload(): """Valid payload for product submit.""" return { 'description': 'Scheduled update', 'delivery_store_ids': [1, 2, 3] } @db.test_schema def test_create_metadata_queue_success( client, product_id, meta_update_payload, monkeypatch): """Test result when creating a new meta update queue.""" success_response = 'Meta Update Queue created' response_body = response.Response(message='Meta Update Queue created') monkeypatch.setattr( meta_update_queue, 'create_meta_update_queue', MagicMock(return_value=response_body)) result = client.post( '/product/{}/metadata_queue'.format(product_id), headers={ 'Orchard-Identity-Id': '123', 'Content-Type': 'application/json' }, data=json.dumps(meta_update_payload)) response_json = result.data.decode() assert result.status_code == http_status.OK assert response_json == success_response @db.test_schema def test_create_metadata_queue_failure(client, product_id, meta_update_payload): """Test meta update queue creation for failure.""" result = client.post( '/product/{}/metadata_queue'.format(product_id), headers={ 'Content-Type': 'application/json' }, data=json.dumps(meta_update_payload)) assert result.status_code == http_status.BAD_REQUEST