"""Test features util.""" from unittest.mock import call from flask import g from oto import response import pytest from pythonfeatures import pythonfeatures from project_manager.models import ows_account from project_manager.util import features @pytest.mark.parametrize(( 'test_description', 'vendor_owner', 'get_vendor_response', 'get_vendor_company_brand_response', 'expected_single_feature_by_attributes_attributes', 'get_single_feature_by_attributes_response', 'expected_result', ), [ ( 'on, company brand and vendor found', 'odd', { 'owner': 'odd', 'assigned_to': 'Artist/Label Relations', 'assigned_reviewer': 101 }, 'awal', { 'vendor_id': str(1232), 'company_brand_name': 'awal', 'distribution_format_id': '1', 'owner': 'odd', 'assigned_to': 'Artist/Label Relations', 'assigned_reviewer': '101' }, response.Response('enabled'), True, ), ( 'on, no company brand found', 'odd', { 'owner': 'odd', 'assigned_to': 'Artist/Label Relations', 'assigned_reviewer': 101 }, None, { 'vendor_id': str(1232), 'company_brand_name': None, 'distribution_format_id': '1', 'owner': 'odd', 'assigned_to': 'Artist/Label Relations', 'assigned_reviewer': '101' }, response.Response('enabled'), True, ), ( 'off', None, None, None, { 'vendor_id': str(1232), 'company_brand_name': None, 'distribution_format_id': '1', 'owner': None, 'assigned_to': None, 'assigned_reviewer': None }, response.Response('disabled'), False, ), ]) def test_get_rejections_from_cr_ff_status( mocker, test_request_context, test_description, vendor_owner, get_vendor_response, get_vendor_company_brand_response, expected_single_feature_by_attributes_attributes, get_single_feature_by_attributes_response, expected_result, ): """Test get_rejections_from_cr_ff_status.""" mocker.patch.object( ows_account, 'get_vendor', autospec=True, return_value=get_vendor_response, ) mocker.patch.object( ows_account, 'get_vendor_company_brand', autospec=True, return_value=get_vendor_company_brand_response, ) mocker.patch.object( pythonfeatures, 'get_single_feature_by_attributes', autospec=True, return_value=get_single_feature_by_attributes_response ) mocker.patch.object( g.log, 'info' ) result = features.get_rejections_from_cr_ff_status(1232, 1) assert ows_account.get_vendor_company_brand.mock_calls == [call(1232)] assert pythonfeatures.get_single_feature_by_attributes.mock_calls == [ call( 'content_get_rejections_for_workstation', expected_single_feature_by_attributes_attributes, )] assert result == expected_result