Exemple #1
0
class TestCSVPopulation(unittest.TestCase):
    def setUp(self):
        self.infection_service = InfectionService()

    def tearDown(self):
        pass

    def testParseCSVFIle(self):

        with open('./data/population.csv') as csv_file:

            csv_reader = csv.reader(csv_file, delimiter=",")

            self.assertIsNotNone(csv_reader)

    def testParseCountriesFile(self):

        population_data = self.infection_service.get_population_data()

        self.assertIsNotNone(population_data)
        self.assertEqual(population_data["PRT"]["value"], 10324611)
        self.assertEqual(population_data["PRT"]["year"], 2016)

    def testGetListOfCountries(self):

        countries = self.infection_service.get_list_of_countries()

        self.assertIsNotNone(countries)
class Countries(Resource):
    ENDPOINT = "/countries"

    def __init__(self):
        self.infection_service = InfectionService()

    def get(self):
        return self.infection_service.get_list_of_countries()
class InfectionCountry(Resource):
    ENDPOINT = "/infection/chartdata"

    def __init__(self):
        self.infection_service = InfectionService()

        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument("countries", type=str)

    def get(self):
        args = self.reqparse.parse_args()
        countries = args["countries"].split(",")

        return self.infection_service.get_country_chart_data(countries)
class InfectionDailyRecovered(Resource):
    ENDPOINT = "/infection/recovered/daily"

    def __init__(self):
        self.infection_service = InfectionService()

        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument("countries", type=str)

    def get(self):
        args = self.reqparse.parse_args()

        countries = args["countries"].split(",")

        return self.infection_service.get_countries_chart_data(
            countries=countries, key_data=InfectionService.DAILY_RECOVERED)
class InfectionDataRaw(Resource):
    ENDPOINT = "/infection/all"

    def __init__(self):
        self.infection_service = InfectionService()

        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument("countries", type=str)

    def get(self):
        args = self.reqparse.parse_args()

        countries = args["countries"].split(",")

        return self.infection_service.get_infection_data_for_the_countries(
            countries=countries)
class InfectionRecoveredPerMillion(Resource):
    ENDPOINT = "/infection/recovered/per_million"

    def __init__(self):
        self.infection_service = InfectionService()

        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument("countries", type=str)

    def get(self):
        args = self.reqparse.parse_args()

        countries = args["countries"].split(",")

        return self.infection_service.get_countries_chart_data(
            countries=countries,
            key_data=InfectionService.RECOVERED_CASES_PER_MILLION)
    def __init__(self):
        self.infection_service = InfectionService()

        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument("countries", type=str)
 def __init__(self):
     self.infection_service = InfectionService()
Exemple #9
0
 def setUp(self):
     self.infection_service = InfectionService()
Exemple #10
0
class TestCovidAPI(unittest.TestCase):
    def setUp(self):
        self.infection_service = InfectionService()

    def tearDown(self):
        pass

    def testAPIAcess(self):
        r = requests.get('https://covidapi.info/api/v1/global')

        self.assertEqual(r.status_code, 200)

    def testGetPortugueseData(self):
        r = requests.get("https://covidapi.info/api/v1/country/PRT")

        data = r.json()

        self.assertEqual(r.status_code, 200)

    def testGetInfectionData(self):
        r = requests.get("https://covidapi.info/api/v1/country/PRT")
        data = r.json()

        count = data["count"]

        infection_data = self.infection_service.get_infection_data_for_the_country(
            "PRT")

        for i in range(1, len(infection_data)):
            self.assertEqual(
                infection_data[i]["daily_confirmed"],
                infection_data[i][InfectionService.CONFIRMED] -
                infection_data[i - 1][InfectionService.CONFIRMED])

            self.assertEqual(infection_data[0]["daily_confirmed"],
                             infection_data[0][InfectionService.CONFIRMED])

            self.assertGreaterEqual(
                infection_data[0][InfectionService.CONFIRMED], 0)

            self.assertEqual(
                infection_data[i]["daily_deaths"],
                infection_data[i][InfectionService.DEATHS] -
                infection_data[i - 1][InfectionService.DEATHS])

            self.assertEqual(infection_data[0]["daily_deaths"],
                             infection_data[0][InfectionService.DEATHS])

            self.assertEqual(
                infection_data[i]["daily_recovered"],
                infection_data[i][InfectionService.RECOVERED] -
                infection_data[i - 1][InfectionService.RECOVERED])

            self.assertEqual(infection_data[0]["daily_recovered"],
                             infection_data[0][InfectionService.RECOVERED])

        self.assertNotEqual(len(infection_data), count)
        self.assertGreater(infection_data[0][InfectionService.CONFIRMED], 0)

    def testGetCountriesChartData(self):
        infection_data = self.infection_service.get_countries_chart_data(
            countries=["PRT", "IND"])

        self.assertEqual(len(infection_data["countries"]), 2)
        self.assertGreater(infection_data["data"][0]["PRT"], 0)
        self.assertGreater(infection_data["data"][0]["IND"], 0)