diff --git a/.gitignore b/.gitignore index 0df1bcc..c6c3c6f 100644 --- a/.gitignore +++ b/.gitignore @@ -167,4 +167,5 @@ poetry.toml # End of https://www.toptal.com/developers/gitignore/api/python -main.py \ No newline at end of file +main.py +*/.json \ No newline at end of file diff --git a/Json/Query.py b/Json/Query.py new file mode 100644 index 0000000..e29aa0d --- /dev/null +++ b/Json/Query.py @@ -0,0 +1,14 @@ +import json + + +def convertJson(cursor): + jsonData = [] + rows = [item for item in cursor] + cols = [item[0] for item in cursor.description] + for row in rows: + data = {} + for index, value in zip(cols, row): + data[index] = value + jsonData.append(data) + encodedData = json.dumps(jsonData, ensure_ascii=False) + return encodedData diff --git a/dal/dao.py b/dal/dao.py index 55b125b..f4cdda4 100644 --- a/dal/dao.py +++ b/dal/dao.py @@ -1,13 +1,12 @@ import sqlite3 +import os -''' -Connecting with database -''' - -class Database: - def __init__(self, path): - self.databasePath = path - - def makeConnection(self): - return sqlite3.connect(f"{self.databasePath}") +def databaseConnection(): + dirname = os.path.dirname(__file__) + file_name = os.path.join(dirname, '..', 'database', 'hawqalDB.sqlite') + with open(file_name, 'r', encoding="utf-8"): + database = sqlite3.connect(file_name) + cursor = database.cursor() + cursor.execute("pragma encoding") + return cursor diff --git a/hawqal/__init__.py b/hawqal/__init__.py index 7fb398c..7c4c6d1 100644 --- a/hawqal/__init__.py +++ b/hawqal/__init__.py @@ -1,9 +1,17 @@ from hawqal.cities import City from hawqal.country import Country from hawqal.states import States +from .filters.state_filter import StateFilter +from .filters.city_filter import CityFilter +from .filters.country_filter import CountryFilter + getCities = City.getCities +getCity = City.getCity getCountries = Country.getCountries +getCountry = Country.getCountry getStates = States.getStates +getState = States.getState -__all__ = [getCities, getCountries, getStates] +__all__ = [getCountries, getStates, + getState, StateFilter, CountryFilter, getCountry, getCities, CityFilter, getCity] diff --git a/hawqal/cities.py b/hawqal/cities.py index 41c885a..46a65ef 100644 --- a/hawqal/cities.py +++ b/hawqal/cities.py @@ -1,66 +1,136 @@ -from dal.dao import Database -from filter.filter import Filter +from dal.dao import databaseConnection import string import os +import json +from .filters.city_filter import CityFilter +from Json.Query import convertJson class City: @staticmethod - def getCities(country="", state="", meta={}): + def getCities(country_name="", state_name="", filter=CityFilter()): """ - 1. Countries function takes two parameters as input country name and filters.\n - 2. By default, function will return countries name.\n - 3. Additional fields are included in filter.\n - 4. From filter of boolean TRUE fields will be included in output - e.g - { - "coordinates": True, - "country": True, - "state":True - } + Description:\n + getCities function returns data of cities w.r.t to country or state in JSON format + Default: \n + By default it will return all the cities with all the fields including\n + - city_id\n + - country_name\n + - city_name\n + - state_id\n + - state_name\n + - latitude\n + - longitude\n + Args:\n + country_name (str): Optional : To get the cities of some specific country.\n + state_name (str): Optional : To get the cities of some specific state.\n + filters (CityFilter): Optional : A class object specifying which fields to include in the results.\n + Returns:\n + list: A json object containing the requested information about the cities.\n + Example: \n + - To get all cities + ``` + hawqal.getCities() + ```\n + - To get all cities of some country + ``` + hawqal.getCities(country_name="Pakistan") + ```\n + - To get all cities of some state in a country + ``` + hawqal.getCities(country_name="Pakistan",state_name="Punjab") + ```\n + - To apply filters and exclude state_name + ``` + hawqal.getCities(filter=hawqal.CityFilter(state_name=False)) + ``` """ - file_name = os.path.join( - os.path.dirname(__file__), '..', 'database', 'hawqalDB.sqlite') + cursor = databaseConnection() + query = "SELECT " + if len(str(filter)) != 0: + query = query + str(filter) + " FROM cities" + else: + query = query + " * FROM cities" - with open(file_name, 'r', encoding="utf8") as db: - database = Database(file_name).makeConnection() - cursor = database.cursor() + if country_name != "" and state_name != "": + query = query + \ + f" WHERE country_name = '{string.capwords(country_name)}' AND state_name = '{string.capwords(state_name)}'" + elif country_name != "": + query = query + \ + f" WHERE country_name = '{string.capwords(country_name)}'" + elif state_name != "": + query = query + \ + f" WHERE state_name = '{string.capwords(state_name)}'" - if state == "" and country == "" and len(meta) == 0: - data = cursor.execute( - f"SELECT city_name FROM cities ORDER BY city_name") - cities = [city[0] for city in data] - return cities - elif country != "" and type(country) != type({}) and state == "" and len(meta) == 0: - data = cursor.execute( - f"SELECT city_name FROM cities WHERE (country_name='{string.capwords(country)}' OR state_name='{string.capwords(country)}') ORDER BY city_name") - return [city[0] for city in data] + cursor.execute(query) - elif (type(country) == type({}) and state == "" and len(meta) == 0): - selectedFields = Filter.CityFilters(country) - if len(selectedFields) != 0: - data = cursor.execute( - f"SELECT city_name,{selectedFields} FROM cities ORDER BY city_name") - return [list(city) for city in list(data)] - else: - data = cursor.execute( - f"SELECT city_name FROM cities ORDER BY city_name") - return [city[0] for city in list(data)] + return convertJson(cursor) - elif country != "" and type(state) == type({}) and len(meta) == 0: - selectedFields = Filter.CityFilters(state) - if len(selectedFields) != 0: - data = cursor.execute( - f"SELECT city_name,{selectedFields} FROM cities WHERE (country_name='{string.capwords(country)}' OR state_name='{string.capwords(country)}') ORDER BY city_name") - return [list(city) for city in list(data)] - else: - data = cursor.execute( - f"SELECT city_name FROM cities WHERE (country_name='{string.capwords(country)}' OR state_name='{string.capwords(country)}') ORDER BY city_name") - return [city[0] for city in data] + @staticmethod + def getCity(country_name="", state_name="", city_name="", filter=CityFilter()): + """ + Description:\n + getCity function returns data of a single city JSON format + Default: \n + By default it will return data of a city if we provide that in the function with all the field + including\n + - city_id\n + - country_name\n + - city_name\n + - state_id\n + - state_name\n + - latitude\n + - longitude\n + Args:\n + country_name (str): Optional : To get the cities of some specific country.\n + state_name (str): Optional : To get the cities of some specific state.\n + city_name (str): Required : To get the city.\n + filters (CityFilter): Optional : A class object specifying which fields to include in the results.\n + Returns:\n + list: A JSON object containing the requested information about the cities.\n + Example: \n + - To get single city with all the filters + ``` + hawqal.getCity(city_name="wah") + ```\n + - To get city of specific country + ``` + hawqal.getCity(country_name="Pakistan",city_name="wah") + ```\n + - To get city of specific state + ``` + hawqal.getCity(state_name="punjab",city_name="wah") + ```\n + - To get city of specific state and country + ``` + hawqal.getCity(country_name="pakistan",state_name="punjab",city_name="wah") + ```\n + - To apply filters and exclude longitude + ``` + hawqal.getCity(country_name="pakistan",state_name="punjab",city_name="wah",filter=hawqal.CityFilter(longitude=False)) + ``` + """ + cursor = databaseConnection() + if city_name == "": + raise ValueError("City name must be set") + query = "SELECT " + if len(str(filter)) != 0: + query = "SELECT " + str(filter) + " FROM cities " + else: + query = query + " * FROM cities " + if country_name != "": + query = query + \ + f" WHERE country_name='{string.capwords(country_name)}' AND city_name='{string.capwords(city_name)}' " + elif state_name != "": + query = query + \ + f"Where state_name='{string.capwords(state_name)}' and city_name='{string.capwords(city_name)}'" + elif country_name != "" and state_name != "": + query = query + \ + f"Where state_name='{string.capwords(state_name)}' and country_name='{string.capwords(country_name)} and city_name='{string.capwords(city_name)}' '" + else: + query = query + f"where city_name='{string.capwords(city_name)}'" + + cursor.execute(query) - elif country != "" and state != "" and len(meta) > 0: - selectedFields = Filter.CityFilters(meta) - data = cursor.execute( - f"SELECT city_name,{selectedFields} FROM cities WHERE country_name='{string.capwords(string.capwords(country))}' AND state_name='{string.capwords(string.capwords(state))}' ORDER BY city_name") - return [list(city) for city in list(data)] + return convertJson(cursor) diff --git a/hawqal/country.py b/hawqal/country.py index 5601c79..0d4619d 100644 --- a/hawqal/country.py +++ b/hawqal/country.py @@ -1,77 +1,112 @@ -from dal.dao import Database -from filter.filter import Filter -import os +from dal.dao import databaseConnection +from Json.Query import convertJson +from .filters.country_filter import CountryFilter import string +import os class Country: @staticmethod - def getCountries(country="", meta={}): + def getCountries(filter=CountryFilter()): """ - 1. Countries function takes two parameters as input country name and filters.\n - 2. By default, function will return countries name.\n - 3. Additional fields are included in filter.\n - 4. From filter of boolean TRUE fields will be included in output - e.g - { - "coordinates": True, - "region": True, - "currency": True, - "timezone": True, - "capital": True - } - + Description:\n + Get information about multiple countries from the database + Default: \n + By default, this method returns data about all countries, including the following fields:\n + - country_name\n + - iso_code\n + - phone_code\n + - capital\n + - currency\n + - currency_name\n + - currency_symbol\n + - country_domain\n + - region\n + - subregion\n + - timezone\n + - zone_city\n + - UTC\n + - latitude\n + - longitude\n + Args:\n + filters (CountryFilter): Optional : A class object specifying which fields to include in the results.\n + Returns:\n + list: A JSON object containing the requested information about the countries.\n + Example: \n + - To get all the countries + ``` + hawqal.getCountries() + ``` + - To apply filters and exclude longitude + ``` + hawqal.getCountries(filter=hawqal.CountryFilter(longitude=False)) + ``` """ + cursor = databaseConnection() + query = "SELECT " + if len(str(filter)) != 0: + query = query + str(filter) + + query = query + " FROM countries ORDER BY country_name ASC" + else: + query = query + " * FROM countries ORDER BY country_name ASC" + cursor.execute(query) - file_name = os.path.join(os.path.dirname( - __file__), '..', 'database', 'hawqalDB.sqlite') + return convertJson(cursor) + + @staticmethod + def getCountry(country_name="", filter=CountryFilter()): + """ + Description:\n + Get information about a specific country from the database. + Default: + By default, this method returns data about a country, including the following fields:\n + - country_name\n + - iso_code\n + - phone_code\n + - capital\n + - currency\n + - currency_name\n + - currency_symbol\n + - country_domain\n + - region\n + - subregion\n + - timezone\n + - zone_city\n + - UTC\n + - latitude\n + - longitude\n + Args:\n + country_name (str): Required : Name of country + filters (CityFilter): Optional : A class object specifying which fields to include in the results.\n + Returns:\n + list: A JSON object containing the requested information about the country.\n + Example: \n + - To get the specific country data + ``` + hawqal.getCountry(country_name="pakistan") + ``` + - To apply filters and exclude longitude + ``` + hawqal.getCountry(country_name="pakistan",filter=hawqal.CountryFilter(longitude=False)) + ``` + """ + cursor = databaseConnection() + if country_name == "": + raise ValueError("country_name must be set") - with open(file_name, 'r', encoding="utf8") as db: - database = Database(file_name).makeConnection() - cursor = database.cursor() + query = "SELECT " - if country == "" and len(meta) == 0: - data = cursor.execute( - f"SELECT country_name FROM countries ORDER BY country_name ASC") - return [country[0] for country in list(data)] + if len(str(filter)) != 0: + query = query + str(filter) + " FROM countries " + else: + query = query + " * FROM countries " - elif type(country) == type({}): - if type(meta) == type(""): - if meta != "": - selectedFields = Filter.CountryFilter(country) - data = cursor.execute( - f'SELECT country_name,{selectedFields} FROM countries WHERE country_name = "{string.capwords(meta)}"') - return [list(country) for country in data][0] - else: - selectedFields = Filter.CountryFilter(country) - data = cursor.execute( - f'SELECT country_name,{selectedFields} FROM countries') - return [list(country) for country in data] - else: - meta, country = country, "" - selectedFields = Filter.CountryFilter(meta) - if len(selectedFields) != 0: - data = cursor.execute( - f'SELECT country_name,{selectedFields} FROM countries') - return [list(country) for country in data] - else: - data = cursor.execute( - f'SELECT country_name FROM countries') - return [country[0] for country in data] + if country_name != "": + query = query + \ + f" WHERE country_name = '{string.capwords(country_name)}' ORDER BY country_name ASC" - elif (country != "" and len(meta) > 0): - selectedFields = Filter.CountryFilter(meta) - if len(selectedFields) != 0: - data = cursor.execute( - f'SELECT country_name,{selectedFields} FROM countries WHERE country_name = "{string.capwords(country)}"') - return [list(country) for country in data][0] - else: - data = cursor.execute( - f'SELECT country_name FROM countries WHERE country_name = "{string.capwords(country)}"') - return [list(country) for country in data][0] + cursor.execute(query) - elif (country != "" and len(meta) == 0): - data = cursor.execute( - f'SELECT * FROM countries WHERE country_name = "{string.capwords(country)}"') - return [list(country) for country in data][0] + return convertJson(cursor) diff --git a/hawqal/filters/city_filter.py b/hawqal/filters/city_filter.py new file mode 100644 index 0000000..fa3669d --- /dev/null +++ b/hawqal/filters/city_filter.py @@ -0,0 +1,17 @@ +class CityFilter: + def __init__(self, city_id=False, city_name=False, state_name=False, state_id=False, country_name=False, latitude=False, + longitude=False): + self.country_name = country_name + self.longitude = longitude + self.latitude = latitude + self.city_id = city_id + self.city_name = city_name + self.state_name = state_name + self.state_id = state_id + + def __str__(self): + fields = "" + for field in ['country_name', 'city_id', 'city_name', 'state_id', 'state_name', 'latitude', 'longitude']: + if getattr(self, field): + fields = fields + field + "," + return fields[:-1] diff --git a/hawqal/filters/country_filter.py b/hawqal/filters/country_filter.py new file mode 100644 index 0000000..4af8891 --- /dev/null +++ b/hawqal/filters/country_filter.py @@ -0,0 +1,24 @@ +class CountryFilter: + def __init__(self, country_name=False, iso_code=False, phone_code=False, capital=False, currency=False, currency_name=False, currency_symbol=False, country_domain=False, region=False, subregion=False, timezone=False, zone_city=False, UTC=False, latitude=False, longitude=False): + self.country_name = country_name + self.longitude = longitude + self.latitude = latitude + self.iso_code = iso_code + self.phone_code = phone_code + self.capital = capital + self.currency = currency + self.currency_name = currency_name + self.currency_symbol = currency_symbol + self.country_domain = country_domain + self.region = region + self.subregion = subregion + self.timezone = timezone + self.zone_city = zone_city + self.UTC = UTC + + def __str__(self): + fields = "" + for field in ['country_name', 'iso_code', 'phone_code', 'capital', 'currency', 'currency_name', 'currency_symbol', 'country_domain', 'region', 'subregion', 'timezone', 'zone_city', 'UTC', 'longitude', 'latitude']: + if getattr(self, field): + fields = fields + field + ',' + return fields[:-1] diff --git a/filter/filter.py b/hawqal/filters/filter.py similarity index 98% rename from filter/filter.py rename to hawqal/filters/filter.py index d279480..def18d4 100644 --- a/filter/filter.py +++ b/hawqal/filters/filter.py @@ -50,4 +50,4 @@ def CityFilters(meta): for key, value in meta.items(): if value: fields = fields + keyArrtibutes[key] + ',' - return fields[:-1] + return fields[:-1] \ No newline at end of file diff --git a/hawqal/filters/state_filter.py b/hawqal/filters/state_filter.py new file mode 100644 index 0000000..49d7d00 --- /dev/null +++ b/hawqal/filters/state_filter.py @@ -0,0 +1,14 @@ +class StateFilter: + def __init__(self, state_id=False, state_name=False, country_name=False, longitude=False, latitude=False): + self.state_id = state_id + self.state_name = state_name + self.country_name = country_name + self.longitude = longitude + self.latitude = latitude + + def __str__(self): + fields = "" + for field in ['state_id', 'state_name', 'country_name', 'longitude', 'latitude']: + if getattr(self, field): + fields = fields + field + ',' + return fields[:-1] diff --git a/hawqal/states.py b/hawqal/states.py index 0e78990..c28650e 100644 --- a/hawqal/states.py +++ b/hawqal/states.py @@ -1,73 +1,108 @@ -from dal.dao import Database -from filter.filter import Filter +from dal.dao import databaseConnection +from .filters.state_filter import StateFilter import string +from Json.Query import convertJson import os class States: @staticmethod - def getStates(country="", meta={}): + def getStates(country_name="", filter=StateFilter()): """ - 1. States function takes two parameters as input state name and filters.\n - 2. By default, function will return states name.\n - 3. Additional fields are included in filter.\n - 4. From filter of boolean TRUE fields will be included in output - e.g - { - "coordinates":True - } - + Description:\n + Get information about multiple states from the database + Default: \n + By default, this method returns data about all states, including the following fields:\n + - state_id\n + - state_name\n + - country_name\n + - latitude\n + - longitude\n + Args:\n + filters (StateFilter): Optional : A class object specifying which fields to include in the results.\n + country_name: Optional : Name of country + Returns:\n + list: A JSON object containing the requested information about the countries.\n + Example: \n + - To get all the states + ``` + hawqal.getState() + ```\n + - To get state of specific country + ``` + hawqal.getState(country_name="pakistan",state_name="punjab") + ```\n + - To apply filters and exclude longitude + ``` + hawqal.getState(state_name="punjab",filter=hawqal.StateFilter(longitude=False)) + ```\n """ - file_name = os.path.join( - os.path.dirname(__file__), '..', 'database', 'hawqalDB.sqlite') + cursor = databaseConnection() + query = "SELECT " + if len(str(filter)) != 0: + query = query + str(filter) + " FROM states" + else: + query = query + " * FROM states" - with open(file_name, 'r', encoding="utf8") as db: - database = Database(file_name).makeConnection() - cursor = database.cursor() + if len(country_name) > 0: + query = query + \ + f' where country_name= "{string.capwords(country_name)}"' - if country == "" and len(meta) == 0: - data = cursor.execute( - f'SELECT state_name FROM states') - return [state[0] for state in data] + cursor.execute(query) - elif type(country) == type({}) and len(meta) == 0: - if type(meta) == type(""): - if meta != "": - selectedFields = Filter.CountryFilter(country) - data = cursor.execute( - f'SELECT state_name,{selectedFields} FROM states WHERE country_name = "{string.capwords(meta)}"') - return [list(country) for country in data] - else: - meta, country = country, "" - selectedFields = Filter.StateFilter(meta) - data = cursor.execute( - f'SELECT state_name,{selectedFields} FROM states') - return [list(country) for country in data] - else: - selectedFields = Filter.CountryFilter(country) - if len(selectedFields) != 0: - data = cursor.execute( - f'SELECT state_name,{selectedFields} FROM states ORDER BY state_name') - return [list(country) for country in data] - else: - data = cursor.execute( - f'SELECT state_name FROM states ORDER BY state_name') - return [country[0] for country in data] + return convertJson(cursor) - elif country != "" and len(meta) > 0: - selectedFields = Filter.StateFilter(meta) - if len(selectedFields) != 0: - data = cursor.execute( - f'SELECT state_name,{selectedFields} FROM states WHERE country_name = "{string.capwords(country)}"') - return [list(country) for country in data] - else: - data = cursor.execute( - f'SELECT state_name FROM states WHERE country_name = "{string.capwords(country)}"') - return [country[0] for country in data] + @staticmethod + def getState(country_name="", state_name="", filter=StateFilter()): + """ + Description:\n + Get information about state from the database\n + Default: + By default, this method returns data about single state, including the following fields:\n + - state_id\n + - state_name\n + - country_name\n + - latitude\n + - longitude\n + Args:\n + filters (StateFilter): Optional : A class object specifying which fields to include in the results.\n + country_name: Optional : Name of country + state_name: Required : Name of the State + Returns:\n + list: A JSON object containing the requested information about the countries.\n + Example: \n + - To get single state with all the filters + ``` + hawqal.getState(state_name="punjab") + ```\n + - To get state of specific country + ``` + hawqal.getState(country_name="Pakistan",state_name="punjab") + ```\n + - To apply filters and exclude longitude + ``` + hawqal.getStates(state_name="punjab",filter=hawqal.StateFilter(longitude=False)) + ```\n + """ + if state_name == "": + raise ValueError("state_name must be set") + cursor = databaseConnection() + query = "SELECT " + if len(str(filter)) != 0: + query = query + str(filter) + " FROM states " + else: + query = query + " * FROM states " - elif country != "" and len(meta) == 0: - selectedFields = Filter.StateFilter(meta) - data = cursor.execute( - f'SELECT state_name FROM states WHERE country_name = "{string.capwords(country)}"') - return [country[0] for country in list(data)] + if len(country_name) > 0 and len(state_name) > 0: + query = query + \ + f'where country_name = "{string.capwords(country_name)}" and state_name = "{string.capwords(state_name)}"' + elif len(country_name) > 0: + query = query + \ + f'where country_name = "{string.capwords(country_name)}"' + elif len(state_name) > 0: + query = query + \ + f'where state_name = "{string.capwords(state_name)}"' + query = query + " ORDER BY country_name ASC" + cursor.execute(query) + return convertJson(cursor) diff --git a/screenshots/100.PNG b/screenshots/100.PNG new file mode 100644 index 0000000..b059d02 Binary files /dev/null and b/screenshots/100.PNG differ diff --git a/screenshots/101.PNG b/screenshots/101.PNG new file mode 100644 index 0000000..2edf868 Binary files /dev/null and b/screenshots/101.PNG differ diff --git a/screenshots/102.PNG b/screenshots/102.PNG new file mode 100644 index 0000000..1f50a3d Binary files /dev/null and b/screenshots/102.PNG differ diff --git a/screenshots/11.PNG b/screenshots/11.PNG new file mode 100644 index 0000000..443f2ad Binary files /dev/null and b/screenshots/11.PNG differ diff --git a/screenshots/22.PNG b/screenshots/22.PNG new file mode 100644 index 0000000..385a9e2 Binary files /dev/null and b/screenshots/22.PNG differ diff --git a/screenshots/33.PNG b/screenshots/33.PNG new file mode 100644 index 0000000..2f03dd4 Binary files /dev/null and b/screenshots/33.PNG differ diff --git a/screenshots/44.PNG b/screenshots/44.PNG new file mode 100644 index 0000000..1e4d6a8 Binary files /dev/null and b/screenshots/44.PNG differ diff --git a/screenshots/55.PNG b/screenshots/55.PNG new file mode 100644 index 0000000..7b9987f Binary files /dev/null and b/screenshots/55.PNG differ diff --git a/screenshots/66.PNG b/screenshots/66.PNG new file mode 100644 index 0000000..47f454e Binary files /dev/null and b/screenshots/66.PNG differ diff --git a/screenshots/77.PNG b/screenshots/77.PNG new file mode 100644 index 0000000..a304ad5 Binary files /dev/null and b/screenshots/77.PNG differ diff --git a/screenshots/88.PNG b/screenshots/88.PNG new file mode 100644 index 0000000..ee59944 Binary files /dev/null and b/screenshots/88.PNG differ diff --git a/screenshots/99.PNG b/screenshots/99.PNG new file mode 100644 index 0000000..83c4b48 Binary files /dev/null and b/screenshots/99.PNG differ diff --git a/setup.py b/setup.py index 82695cc..7fd5963 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(fname): setup( name="hawqal", - version="0.1.5.9", + version="0.0.6", description="Python package that contains the data of world's countries,states and their cities name", long_description_content_type="text/markdown", long_description=read('README.md'), diff --git a/test_hawqal.py b/test_hawqal.py index 145b0dc..83ea233 100644 --- a/test_hawqal.py +++ b/test_hawqal.py @@ -1,24 +1,25 @@ +import json import unittest from hawqal.country import Country from hawqal.states import States from hawqal.cities import City - +from hawqal.filters.country_filter import CountryFilter +from hawqal.filters.city_filter import CityFilter +from hawqal.filters.state_filter import StateFilter class TestFunc(unittest.TestCase): def test_getCountries(self): - self.assertEqual(len(Country.getCountries()), 250) - self.assertEqual(len(Country.getCountries( - "pakistan", {"coordinates": True})), 3) + self.assertEqual(len(json.loads(Country.getCountries())), 250) + self.assertEqual(len(json.loads(Country.getCountry(country_name="pakistan"))),1) def test_getStates(self): - self.assertEqual(len(States.getStates()), 4989) - self.assertEqual(len(States.getStates("pakistan")), 8) + self.assertEqual(len(json.loads(States.getStates())), 4989) + self.assertEqual(len(json.loads(States.getState(country_name="pakistan",state_name="Punjab"))), 1) def test_getCities(self): - self.assertEqual(len(City.getCities()), 150710) - self.assertEqual(len(City.getCities("pakistan")), 458) - self.assertEqual(len(City.getCities("punjab")), 329) + self.assertEqual(len(json.loads(City.getCities())), 150710) + self.assertEqual(len(json.loads(City.getCity(country_name="pakistan",state_name='punjab',city_name='wah'))), 1) if __name__ == '__main__':