示例#1
0
def add_countries_instance(data):
    """
    Formats the given json data, creates a new instance of Countries, and
    adds the new instance to the db session
    """
    args = dict()
    args["alternate_names"] = data["alternateNames"]
    args["area"] = data["area"]
    args["borders"] = data["borders"]
    args["calling_codes"] = data["callingCodes"]
    args["capital_img"] = data["capital"]["img"]
    args["capital_location_lat"] = data["capital"]["location"]["lat"]
    args["capital_location_lng"] = data["capital"]["location"]["lng"]
    args["capital_name"] = data["capital"]["name"]
    args["codes_alpha2_code"] = data["codes"]["alpha2Code"]
    args["codes_alpha3_code"] = data["codes"]["alpha3Code"]
    args["currencies"] = data["currencies"]
    args["flag"] = data["flag"]
    args["languages"] = data["languages"]
    args["location_lat"] = data["location"]["lat"]
    args["location_lng"] = data["location"]["lng"]
    args["name"] = data["name"]
    args["news"] = data["news"]
    args["population"] = data["population"]
    args["region_region"] = data["region"]["region"]
    args["region_subregion"] = data["region"]["subregion"]
    args["regional_blocs"] = data["regionalBlocs"]
    args["sources"] = data["sources"]
    args["timezones"] = data["timezones"]
    countries_db_entry = Countries(**args)
    db.session.add(countries_db_entry)
示例#2
0
 def test_retrieve_by_id_2(self):
     attributes = const.VALID_COUNTRIES_ATTRIBUTES
     result = Countries.retrieve_by_id("US", const.Identifier.ALPHA2_CODE,
                                       attributes)
     self.assertEqual(attributes, result.keys())
     self.assertEqual(result["name"], "United States")
     self.assertEqual(result["codes"]["alpha3Code"], "USA")
     self.assertEqual(result["codes"]["alpha2Code"], "US")
示例#3
0
 def test_retrieve_all_2(self):
     attributes = set(const.VALID_COUNTRIES_ATTRIBUTES)
     attributes.remove("location")
     attributes.remove("callingCodes")
     result = Countries.retrieve_all(attributes)
     first = result[0]
     self.assertEqual(attributes, first.keys())
     self.assertEqual(len(result), 185)
示例#4
0
 def test_retrieve_by_id_4(self):
     attributes = set(const.VALID_COUNTRIES_ATTRIBUTES)
     attributes.remove("location")
     attributes.remove("languages")
     attributes.remove("currencies")
     result = Countries.retrieve_by_id("USA", const.Identifier.ALPHA3_CODE,
                                       attributes)
     self.assertEqual(attributes, result.keys())
     self.assertEqual(result["name"], "United States")
     self.assertEqual(result["codes"]["alpha3Code"], "USA")
     self.assertEqual(result["codes"]["alpha2Code"], "US")
示例#5
0
 def test_search_2(self):
     query = "United Washington D.C."
     result = Countries.search(query)
     first = result[0]
     self.assertEqual({"name", "codes"}, first.keys())
     self.assertEqual(len(result), 1)
示例#6
0
 def test_retrieve_by_id_5(self):
     attributes = const.VALID_COUNTRIES_ATTRIBUTES
     result = Countries.retrieve_by_id("USA", const.Identifier.ALPHA2_CODE,
                                       attributes)
     self.assertIs(result, None)
示例#7
0
 def test_retrieve_all_3(self):
     attributes = frozenset({"name", "codes"})
     result = Countries.retrieve_all(attributes)
     first = result[0]
     self.assertEqual(attributes, first.keys())
     self.assertEqual(len(result), 185)
示例#8
0
 def test_retrieve_all_1(self):
     result = Countries.retrieve_all(const.VALID_COUNTRIES_ATTRIBUTES)
     first = result[0]
     self.assertEqual(const.VALID_COUNTRIES_ATTRIBUTES, first.keys())
     self.assertEqual(len(result), 185)