Coverage for tests/tests_unit/test_geo_connector.py: 46%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.2, created at 2024-10-10 03:02 +0300

1import pytest 

2import pytest_asyncio 

3import pytest_cases 

4from exceptions import GeoAPINoResults, GeoAPIStatusException 

5from logging_config import logger 

6from services.location_connector import LocationAPIConnector 

7from sotrans_models.models.orders.order import StopAddress 

8 

9 

10@pytest_asyncio.fixture(scope="function") 

11async def geo_connector(): 

12 loc_con = LocationAPIConnector() 

13 yield loc_con 

14 await loc_con.session.close() 

15 

16 

17def case_empty(): 

18 return "" 

19 

20 

21def case_short(): 

22 return "Санкт-Петербург" 

23 

24 

25def case_midrange(): 

26 return "Москва, Театральный проезд, д. 3" 

27 

28 

29def case_trash(): 

30 return "asdiufhpawiuehfpa8sf982yh34r98h2h3" * 3 

31 

32 

33@pytest.mark.asyncio 

34@pytest_cases.parametrize_with_cases("address", cases=".") 

35@pytest.mark.xfail # Auth added 

36async def test_geo_api_request(address, geo_connector: LocationAPIConnector): 

37 if not address: 

38 with pytest.raises(GeoAPINoResults): 

39 await geo_connector.request_line_address_with_yapi(address) 

40 elif "asd" in address: 

41 with pytest.raises(GeoAPINoResults): 

42 await geo_connector.request_line_address_with_yapi(address) 

43 else: 

44 res = await geo_connector.request_line_address_with_yapi(address) 

45 logger.info(res) 

46 assert isinstance(res, StopAddress)