Skip to content

Commit c759b97

Browse files
committed
Added new test cases.
1 parent df442be commit c759b97

3 files changed

Lines changed: 111 additions & 5 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
py_modules=['IP2Location'],
1515
url="https://github.com/ip2location/ip2location-python",
1616
packages=setuptools.find_packages(),
17-
tests_require=[pytest>=4.6.11],
17+
tests_require=['pytest>=3.0.6'],
1818
classifiers=[
1919
"Development Status :: 5 - Production/Stable",
2020
"Intended Audience :: Developers",

tests/test_database.py

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def testinvaliddatabase():
1414
except ValueError as e:
1515
assert "The database file does not seem to exist." == str(e)
1616

17+
def testfunctionexist():
18+
database = IP2Location.IP2Location(ipv4database)
19+
functions_list = ['open', 'close', 'get_all', 'get_country_short', 'get_country_long', 'get_region', 'get_city', 'get_latitude', 'get_longitude', 'get_isp', 'get_domain', 'get_zipcode', 'get_timezone', 'get_netspeed', 'get_idd_code', 'get_area_code', 'get_weather_code', 'get_weather_name', 'get_mcc', 'get_mnc', 'get_mobile_brand', 'get_elevation', 'get_usage_type']
20+
for x in range(len(functions_list)):
21+
assert hasattr(database, functions_list[x]) == True, "Function did not exist."
22+
1723
def testipv4countrycode():
1824
database = IP2Location.IP2Location(ipv4database)
1925
rec = database.get_all("8.8.8.8")
@@ -24,10 +30,105 @@ def testipv4countryname():
2430
rec = database.get_all("8.8.8.8")
2531
assert rec.country_long == "United States of America", "Test failed because country name not same."
2632

27-
def testipv4unsupportedfield():
33+
def testgetcountryshort():
2834
database = IP2Location.IP2Location(ipv4database)
29-
rec = database.get_all("8.8.8.8")
30-
assert rec.city == None, "Test failed because city name not same."
35+
rec = database.get_country_short("8.8.8.8")
36+
assert rec == "US", "Test failed because country code not same."
37+
38+
def testgetcountrylong():
39+
database = IP2Location.IP2Location(ipv4database)
40+
rec = database.get_country_long("8.8.8.8")
41+
assert rec == "United States of America", "Test failed because country name not same."
42+
43+
def testgetregion():
44+
database = IP2Location.IP2Location(ipv4database)
45+
rec = database.get_region("8.8.8.8")
46+
assert rec == None
47+
48+
def testgetcity():
49+
database = IP2Location.IP2Location(ipv4database)
50+
rec = database.get_city("8.8.8.8")
51+
assert rec == None
52+
53+
def testgetlatitude():
54+
database = IP2Location.IP2Location(ipv4database)
55+
rec = database.get_latitude("8.8.8.8")
56+
assert rec == None
57+
58+
def testgetlongitude():
59+
database = IP2Location.IP2Location(ipv4database)
60+
rec = database.get_longitude("8.8.8.8")
61+
assert rec == None
62+
63+
def testgetisp():
64+
database = IP2Location.IP2Location(ipv4database)
65+
rec = database.get_isp("8.8.8.8")
66+
assert rec == None
67+
68+
def testgetdomain():
69+
database = IP2Location.IP2Location(ipv4database)
70+
rec = database.get_domain("8.8.8.8")
71+
assert rec == None
72+
73+
def testgetzipcode():
74+
database = IP2Location.IP2Location(ipv4database)
75+
rec = database.get_zipcode("8.8.8.8")
76+
assert rec == None
77+
78+
def testgettimezone():
79+
database = IP2Location.IP2Location(ipv4database)
80+
rec = database.get_timezone("8.8.8.8")
81+
assert rec == None
82+
83+
def testgetnetspeed():
84+
database = IP2Location.IP2Location(ipv4database)
85+
rec = database.get_netspeed("8.8.8.8")
86+
assert rec == None
87+
88+
def testgetiddcode():
89+
database = IP2Location.IP2Location(ipv4database)
90+
rec = database.get_idd_code("8.8.8.8")
91+
assert rec == None
92+
93+
def testgetareacode():
94+
database = IP2Location.IP2Location(ipv4database)
95+
rec = database.get_area_code("8.8.8.8")
96+
assert rec == None
97+
98+
def testgetweathercode():
99+
database = IP2Location.IP2Location(ipv4database)
100+
rec = database.get_weather_code("8.8.8.8")
101+
assert rec == None
102+
103+
def testgetweathername():
104+
database = IP2Location.IP2Location(ipv4database)
105+
rec = database.get_weather_name("8.8.8.8")
106+
assert rec == None
107+
108+
def testgetmcc():
109+
database = IP2Location.IP2Location(ipv4database)
110+
rec = database.get_mcc("8.8.8.8")
111+
assert rec == None
112+
113+
def testgetmnc():
114+
database = IP2Location.IP2Location(ipv4database)
115+
rec = database.get_mnc("8.8.8.8")
116+
assert rec == None
117+
118+
def testgetmobilebrand():
119+
database = IP2Location.IP2Location(ipv4database)
120+
rec = database.get_mobile_brand("8.8.8.8")
121+
assert rec == None
122+
123+
def testgetelevation():
124+
database = IP2Location.IP2Location(ipv4database)
125+
rec = database.get_elevation("8.8.8.8")
126+
assert rec == None
127+
128+
def testgetusagetype():
129+
database = IP2Location.IP2Location(ipv4database)
130+
rec = database.get_usage_type("8.8.8.8")
131+
assert rec == None
31132

32133
def testipv6countrycode():
33134
database = IP2Location.IP2Location(ipv6database)

tests/test_webservice.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ def testcountrycode():
1919

2020
def testgetcredit():
2121
credit = ws.getcredit()
22-
assert str(credit).isdigit() == True, "Test failed because it is no a digit value."
22+
assert str(credit).isdigit() == True, "Test failed because it is no a digit value."
23+
24+
def testfunctionexist():
25+
functions_list = ['lookup', 'getcredit']
26+
for x in range(len(functions_list)):
27+
assert hasattr(ws, functions_list[x]) == True, "Function did not exist."

0 commit comments

Comments
 (0)