"""Functional tests for Reference Agreement Type.""" from unittest.mock import patch import pytest def test_get_reference_agreement_type(fixture_client): """Test that we can get an agreement type by reference_agreement_type_id.""" response = fixture_client.get('/reference-agreement-type/1') assert response.status_code == 200 assert response.json == { 'reference_agreement_type_id': 1, 'agreement_type': 'AWAL Core' } @patch('abacus_account.blueprints.reference_agreement_type.authorize_resource') def test_get_reference_agreement_type_with_invalid_profile( mock_authorize_resource, fixture_client): """Test GET /reference-agreement-type/:id with invalid profile.""" mock_authorize_resource.return_value = True response = fixture_client.get( '/reference-agreement-type/1', headers={ 'Content-Type': 'application/json', 'Orchard-Identity-Id': 'd5ca8ac3-7e51-4793-8775-50d11282504c', 'Orchard-Profile-Id': '35109', 'Orchard-Profile-Type': 'NotProfile', 'Orchard-Roles': "['administrator']", 'Orchard-Requestor-Service': 'graphql-abacus' } ) assert response.status_code == 200 assert response.json == { 'reference_agreement_type_id': 1, 'agreement_type': 'AWAL Core' } def test_get_reference_agreement_types(fixture_client): """Test that we can get an agreement types listing.""" response = fixture_client.get('/reference-agreement-types') assert response.status_code == 200 assert response.json == [ { 'reference_agreement_type_id': 1, 'agreement_type': 'AWAL Core' }, { 'reference_agreement_type_id': 2, 'agreement_type': 'AWAL +' }, { 'reference_agreement_type_id': 3, 'agreement_type': 'AWAL Recordings' }, { 'reference_agreement_type_id': 6, 'agreement_type': 'Courage' }, { 'reference_agreement_type_id': 7, 'agreement_type': 'Mass Appeal' }, { 'reference_agreement_type_id': 8, 'agreement_type': 'Relapse' }, { 'reference_agreement_type_id': 9, 'agreement_type': 'O&O' }, ] @pytest.mark.parametrize( 'authorize_return, expected_status', ( pytest.param(True, 200, id='authorized'), pytest.param(False, 403, id='not authorized'), ) ) @patch('abacus_account.blueprints.reference_agreement_type.authorize_resource') def test_get_reference_agreement_types_with_invalid_profile( mock_authorize_resource, authorize_return, expected_status, fixture_client ): """Test GET /reference-agreement-types with invalid profile.""" mock_authorize_resource.return_value = authorize_return response = fixture_client.get( '/reference-agreement-types', headers={ 'Content-Type': 'application/json', 'Orchard-Identity-Id': 'd5ca8ac3-7e51-4793-8775-50d11282504c', 'Orchard-Profile-Id': '35109', 'Orchard-Profile-Type': 'NotProfile', 'Orchard-Roles': "['administrator']", 'Orchard-Requestor-Service': 'graphql-abacus' } ) assert response.status_code == expected_status if expected_status == 200: assert response.json[0] == { 'reference_agreement_type_id': 1, 'agreement_type': 'AWAL Core' } else: assert response.json == { 'code': 'authorization_error', 'message': 'Unauthorized' }