Пример #1
0
 def test_retrieve_all_2(self):
     attributes = set(const.VALID_CASE_STATS_ATTRIBUTES)
     attributes.remove("smoothedNew")
     attributes.remove("testing")
     result = CaseStatistics.retrieve_all(attributes)
     first = result[0]
     self.assertEqual(attributes, first.keys())
     self.assertEqual(len(result), 185)
Пример #2
0
 def test_retrieve_by_id_3(self):
     attributes = const.VALID_CASE_STATS_ATTRIBUTES
     result = CaseStatistics.retrieve_by_id("United States",
                                            const.Identifier.COUNTRY_NAME,
                                            attributes)
     self.assertEqual(attributes, result.keys())
     self.assertEqual(result["country"]["name"], "United States")
     self.assertEqual(result["country"]["codes"]["alpha3Code"], "USA")
     self.assertEqual(result["country"]["codes"]["alpha2Code"], "US")
Пример #3
0
 def test_retrieve_by_id_4(self):
     attributes = set(const.VALID_CASE_STATS_ATTRIBUTES)
     attributes.remove("location")
     attributes.remove("derivativeNew")
     attributes.remove("totals")
     result = CaseStatistics.retrieve_by_id("USA",
                                            const.Identifier.ALPHA3_CODE,
                                            attributes)
     self.assertEqual(attributes, result.keys())
     self.assertEqual(result["country"]["name"], "United States")
     self.assertEqual(result["country"]["codes"]["alpha3Code"], "USA")
     self.assertEqual(result["country"]["codes"]["alpha2Code"], "US")
Пример #4
0
def add_case_stats_instance(data):
    """
    Formats the given json data, creates a new instance of CaseStatistics, and
    adds the new instance to the db session
    """
    args = dict()
    args["country_codes_alpha3_code"] = data["country"]["codes"]["alpha3Code"]
    args["country_codes_alpha2_code"] = data["country"]["codes"]["alpha2Code"]
    args["country_name"] = data["country"]["name"]
    args["date"] = data["date"]
    args["derivative_new_active"] = data["derivativeNew"]["active"]
    args["derivative_new_cases"] = data["derivativeNew"]["cases"]
    args["derivative_new_deaths"] = data["derivativeNew"]["deaths"]
    args["derivative_new_recovered"] = data["derivativeNew"]["recovered"]
    args["history"] = data["history"]
    args["location_lat"] = data["location"]["lat"]
    args["location_lng"] = data["location"]["lng"]
    args["new_active"] = data["new"]["active"]
    args["new_cases"] = data["new"]["cases"]
    args["new_deaths"] = data["new"]["deaths"]
    args["new_recovered"] = data["new"]["recovered"]
    args["percentages_active"] = data["percentages"]["active"]
    args["percentages_fatality"] = data["percentages"]["fatality"]
    args["percentages_have_recovered"] = data["percentages"]["haveRecovered"]
    args["percentages_infected"] = data["percentages"]["infected"]
    args["smoothed_new_cases"] = data["smoothedNew"]["cases"]
    args["smoothed_new_deaths"] = data["smoothedNew"]["deaths"]
    args["sources"] = data["sources"]
    args["testing_new_tests"] = data["testing"]["newTests"]
    args["testing_new_tests_smoothed"] = data["testing"]["newTestsSmoothed"]
    args["testing_positive_rate"] = data["testing"]["positiveRate"]
    args["testing_total_tests"] = data["testing"]["totalTests"]
    args["totals_active"] = data["totals"]["active"]
    args["totals_cases"] = data["totals"]["cases"]
    args["totals_deaths"] = data["totals"]["deaths"]
    args["totals_recovered"] = data["totals"]["recovered"]
    case_stats_db_entry = CaseStatistics(**args)
    db.session.add(case_stats_db_entry)
Пример #5
0
 def test_retrieve_by_id_5(self):
     attributes = const.VALID_CASE_STATS_ATTRIBUTES
     result = CaseStatistics.retrieve_by_id("USA",
                                            const.Identifier.ALPHA2_CODE,
                                            attributes)
     self.assertIs(result, None)
Пример #6
0
 def test_retrieve_all_3(self):
     attributes = frozenset({"country", "date"})
     result = CaseStatistics.retrieve_all(attributes)
     first = result[0]
     self.assertEqual(attributes, first.keys())
     self.assertEqual(len(result), 185)
Пример #7
0
 def test_retrieve_all_1(self):
     result = CaseStatistics.retrieve_all(const.VALID_CASE_STATS_ATTRIBUTES)
     first = result[0]
     self.assertEqual(const.VALID_CASE_STATS_ATTRIBUTES, first.keys())
     self.assertEqual(len(result), 185)