"""Tests for ows-territories Model.""" from owsrequest import request from owsrequest import test_utils from pricing.constants import service_name from pricing.models import ows_territories def test_convert_to_orchard_territories(monkeypatch): """Test converting to Orch_1_2016 territories.""" mock_json_response = { 'items': ['US', 'CS'] } path = '/conversion/ISO_3166_1_2016/Orch_1_2016?territory_code_a2=US,RS' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) territories = ['US', 'RS'] response = ows_territories.convert_to_orchard_territories(territories) assert response.message == mock_json_response def test_convert_to_iso_territories(monkeypatch): """Test converting to ISO territories.""" mock_json_response = { 'items': ['US', 'CS'] } path = '/conversion/Orch_1_2016/ISO_3166_1_2016?territory_code_a2=US,RS' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) territories = ['US', 'RS'] response = ows_territories.convert_to_iso_territories(territories) assert response.message == mock_json_response def test_complement_orchard_territories(monkeypatch): """Test complementing Orch_1_2016 territories.""" mock_json_response = { 'items': ['FR'] } path = '/complement/Orch_1_2016?territory_code_a2=US,CA' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) territories = ['US', 'CA'] response = ows_territories.complement_orchard_territories(territories) assert response.message == mock_json_response def test_complement_iso_territories(monkeypatch): """Test complementing ISO_3166_1_2016 territories.""" mock_json_response = { 'items': ['FR'] } path = '/complement/ISO_3166_1_2016?territory_code_a2=US,CA' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) territories = ['US', 'CA'] response = ows_territories.complement_iso_territories(territories) assert response.message == mock_json_response def test_all_orchard_territories(monkeypatch): """Test getting all Orch_1_2016 territories.""" mock_json_response = { 'items': ['FR'] } path = '/territory/Orch_1_2016' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_territories.get_all_orchard_territories() assert response.message == mock_json_response def test_get_all_iso_territories(monkeypatch): """Test getting all iso territories.""" mock_json_response = { 'items': ['FR'] } path = '/territory/ISO_3166_1_2016' call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_territories.get_all_iso_territories() assert response.message == mock_json_response def test_get_all_iso_territories_with_not_found_response(monkeypatch): """Test getting all iso territories.""" mock_json_response = {'items': []} path = '/territory/ISO_3166_1_2016' call_specs = [{ 'service': service_name.OWS_TERRITORIES, 'path': path, 'status': 404, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_territories.get_all_iso_territories() assert response.status == 404