"""Tests for ows-notifications model.""" import pytest from flask.testing import FlaskClient from pytest_mock import MockerFixture from permissions.models import ows_notifications from permissions.types import AdminIdentity, ProfileInfo, Tenant, TenantType admin_identity = AdminIdentity( id='555df6b6-661b-4d5b-bc0f-df83cf46eb75', first_name='Test', last_name='Test', name='Test Test', email='test@foo.bar', auth0_user_id='auth0|test', active='Y', user_types=['label'], default_brand='awal', settings_profile=ProfileInfo( profile_id=1234, profile_type='SettingsProfile', roles=[], uuid='555df6b6-661b-4d5b-bc0f-df83cf46eb75', ), ) target_tenant = Tenant( tenant_type=TenantType.ACCOUNT, tenant_uuid='4e56e789-b12d-3a45-6a45-642661417400', ) @pytest.mark.parametrize( ('identity_id', 'tenant', 'brand', 'admin', 'status_code'), ( ( '123e4567-e89b-12d3-a456-426614174000', target_tenant, 'theorchard', admin_identity, 204, ), ( '123e4567-e89b-12d3-a456-426614174000', target_tenant, 'theorchard', admin_identity, 400, ), ), ) def test_user_permissions_updated( identity_id: str, tenant: Tenant, brand: str, admin: AdminIdentity, status_code: int, mocker: MockerFixture, app_context: FlaskClient, ): """Test a successful request to set primary vend_contact.""" mocker.patch('permissions.models.ows_notifications.g') request_mock = mocker.patch( 'permissions.models.ows_notifications.request', post=mocker.Mock(return_value=mocker.Mock(status_code=status_code)), ) result = ows_notifications.send_user_permissions_updated(identity_id, tenant, brand, admin) request_mock.post.assert_called_once_with( service_name='ows-notifications', path='/private/permissions/updated', json={ 'brand': brand, 'identity_id': identity_id, 'tenant_type': tenant.tenant_type.value, 'tenant_uuid': tenant.tenant_uuid, }, headers={ 'Content-Type': 'application/json', 'Orchard-Profile-Id': str(admin.settings_profile.profile_id), 'Orchard-Profile-Type': admin.settings_profile.profile_type, 'Orchard-Identity-Id': admin.id, }, ) assert result == (status_code == 204)