import random import logging from httpx._exceptions import ReadTimeout, ConnectTimeout from aggregator import Aggregator from aggregator.rapidapisource import RapidapiSource from aggregator.schemas import CountryInfo from aggregator.githubsource import GithubSource from aggregator.stopcoronasource import StopcoronaSource from aggregator.schemas import RegionInfo from tests.mocks import mock_load from exceptions import CountryNotFound @pytest.fixture @patch.object(RapidapiSource, 'load_data', mock_load('RapidapiSource')) @patch.object(GithubSource, 'load_data', mock_load('GithubSource')) @patch.object(StopcoronaSource, 'load_data', mock_load('StopcoronaSource')) async def aggr(): aggr = Aggregator() await aggr.load_sources() return aggr @pytest.mark.asyncio @patch.object(logging, 'error', Mock()) @patch.object(logging, 'exception', Mock()) @patch.object(RapidapiSource, 'update', AsyncMock()) @patch.object(GithubSource, 'update', AsyncMock()) @patch.object(StopcoronaSource, 'update', AsyncMock()) async def test_update():
import pytest from unittest.mock import patch, Mock, AsyncMock import httpx from datetime import datetime from pathlib import Path import pandas as pd from tests.mocks import mock_load from aggregator.githubsource import GithubSource from aggregator.githubsource.datapreparer import GithibDataPreparer from aggregator.githubsource.graph import GithubGraph from aggregator.matcher import CountryNameMatcher from exceptions import CountryNotFound mock_load_github = mock_load('GithubSource') @pytest.fixture @patch.object(GithubSource, 'load_data', mock_load_github) async def github(): github = GithubSource() await github.update() return github @pytest.mark.asyncio @patch('httpx.AsyncClient.get', AsyncMock()) async def test_load_github_data(): github = GithubSource() data = await github.load_data()
import pytest from typing import List from typeguard import check_type import re from bs4 import BeautifulSoup import json import pandas as pd from tests.mocks import mock_load from aggregator.stopcoronasource.datapreparer import StopcoronaDataPreparer from aggregator.schemas import RegionInfo, StopcoronaResponseItems mock_load_stopcorona = mock_load('StopcoronaSource') @pytest.mark.asyncio async def test_stopcorona_load_data_structure(): response: str = await mock_load_stopcorona() assert type(response) == str soup = BeautifulSoup(response, 'html.parser') region_table = soup.find_all('cv-spread-overview') assert len(region_table) == 1 region_table = region_table[0] assert ':spread-data' in region_table.attrs json_data: str = region_table.attrs[':spread-data'] json_data: dict = json.loads(json_data)
import pytest from unittest.mock import patch, AsyncMock from typing import List from typeguard import check_type import random import httpx from tests.mocks import mock_load from aggregator.rapidapisource import RapidapiSource from aggregator.schemas import CountryInfo from exceptions import NoRapidapiKey, CountryNotFound mock_load_rapidapi = mock_load('RapidapiSource') @pytest.fixture @patch.object(RapidapiSource, 'load_data', mock_load_rapidapi) async def rapidapi(): rapidapi = RapidapiSource() await rapidapi.update() return rapidapi @pytest.mark.asyncio async def test_no_key_error(): rapidapi = RapidapiSource() with pytest.raises(NoRapidapiKey): await rapidapi.update()