"""Functional tests for Reference SAP Profit Center.""" from tests.utils.factories import ReferenceSapProfitCenterFactory def test_get_reference_sap_profit_center_by_id(fixture_client): """Test getting an SAP Profit Center by ID.""" sap_profit_center = ReferenceSapProfitCenterFactory.create() sap_profit_center_id = sap_profit_center.reference_sap_profit_center_id res = fixture_client.get(f'/reference-sap-profit-center/{sap_profit_center_id}') assert res.status_code == 200 assert res.json == { 'business_group': sap_profit_center.business_group, 'company_code': sap_profit_center.company_code, 'profit_center': sap_profit_center.profit_center, 'reference_sap_profit_center_id': sap_profit_center_id } def test_get_reference_sap_profit_center_list(fixture_client): """Test getting SAP Profit Centers list ordered alphabetically by profit_center.""" sap_profit_center_1 = ReferenceSapProfitCenterFactory.create(profit_center='US123') sap_profit_center_2 = ReferenceSapProfitCenterFactory.create(profit_center='UK456') res = fixture_client.get('/reference-sap-profit-center') assert res.status_code == 200 items = res.json.get('items') assert len(items) == res.json.get('total_count') assert items[0]['profit_center'] == sap_profit_center_2.profit_center assert items[1]['profit_center'] == sap_profit_center_1.profit_center