Skip to content

Commit

Permalink
Use non-deprecated versions of assert functions in regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcook committed Nov 11, 2023
1 parent 0e3c159 commit 2f4de29
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 186 deletions.
2 changes: 1 addition & 1 deletion regression-tests/test_8bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def test8Bit(self):
print(json.dumps(j))
count = int(j["r_attrs"]["count"])

self.assertEquals(count, 2)
self.assertEqual(count, 2)
8 changes: 4 additions & 4 deletions regression-tests/test_Attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ def test_Attrs(self):
attrs['accountStatus'] = "normal"
r = self.allowFuncAttrs('fredbloggs', '127.0.0.1', "1234", attrs)
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

attrs['accountStatus'] = "blocked"
r = self.allowFuncAttrs('fredbloggs', '127.0.0.1', "1234", attrs)
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)

attrs['accountStatus'] = "normal"
attrs['countryList'] = [ "UK", "US" ]
r = self.allowFuncAttrs('fredbloggs', '127.0.0.1', "1234", attrs)
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

attrs['countryList'] = [ "UK", "US", "Blockmestan" ]
r = self.allowFuncAttrs('fredbloggs', '127.0.0.1', "1234", attrs)
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)

34 changes: 17 additions & 17 deletions regression-tests/test_Basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TestBasics(ApiTestCase):

def test_unauth(self):
r = requests.get(self.url("/?command=stats"))
self.assertEquals(r.status_code, requests.codes.unauthorized)
self.assertEqual(r.status_code, requests.codes.unauthorized)

def test_auth_stats(self):
r = self.session.get(self.url("/?command=stats"))
self.assertEquals(r.status_code, requests.codes.ok)
self.assertEqual(r.status_code, requests.codes.ok)

def test_ping(self):
for _ in range(10):
Expand All @@ -22,53 +22,53 @@ def test_ping(self):
if j['status'] == 'ok':
break
time.sleep(1)
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

def test_ping_acl_deny(self):
self.writeCmdToConsole('setACL({})')
r = self.pingFunc()
self.assertEquals(r.status_code, 401)
self.assertEqual(r.status_code, 401)
j = r.json()
self.assertEquals(j['status'], 'failure')
self.assertEquals(j['reason'], 'Source IP Address not in ACL')
self.assertEqual(j['status'], 'failure')
self.assertEqual(j['reason'], 'Source IP Address not in ACL')
self.writeCmdToConsole('setACL({"0.0.0.0/0"})')

def test_getBL(self):
r = self.getBLFunc()
j = r.json()
self.assertEquals(j['bl_entries'], [])
self.assertEqual(j['bl_entries'], [])

def test_customFunc(self):
r = self.customFunc("custom1")
j = r.json()
self.assertEquals(j['r_attrs']['login'], 'custom1')
self.assertEqual(j['r_attrs']['login'], 'custom1')

def test_customGetFunc(self):
r = self.customGetFunc("testCustomGet")
t = r.text
self.assertEquals(t, '1.2.3.4/32\n')
self.assertEqual(t, '1.2.3.4/32\n')

def test_deviceParsing(self):
r = self.allowFuncDeviceProtocol('foobar', '127.0.0.1', "12432", '"name" "Mac OS X Mail" "version" "10.0 (3226)" "os" "Mac OS X" "os-version" "10.12 (16A323)" "vendor" "Apple Inc."', "imap")
j = r.json()
self.assertRegexpMatches(json.dumps(j), "Mac OS X")
self.assertRegex(json.dumps(j), "Mac OS X")
r = self.allowFuncDeviceProtocol('foobar', '127.0.0.1', "12432", 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A', "http")
j = r.json()
self.assertRegexpMatches(json.dumps(j), "Mac OS X")
self.assertRegex(json.dumps(j), "Mac OS X")
r = self.allowFuncDeviceProtocol('foobar', '127.0.0.1', "12432", 'OpenXchange.Android.Mail/1.0+1234 (OS: 7.0; device: Samsung/GT9700)', "mobileapi")
j = r.json()
self.assertRegexpMatches(json.dumps(j), "Android")
self.assertRegex(json.dumps(j), "Android")

def test_getDBStats(self):
self.reportFunc('dbstats', '1.4.3.2', '1234', False);
r = self.getDBStatsLogin('dbstats')
j = r.json();
self.assertRegexpMatches(json.dumps(j), "countLogins")
self.assertRegex(json.dumps(j), "countLogins")
r = self.getDBStatsIP('1.4.3.2')
j = r.json();
self.assertRegexpMatches(json.dumps(j), "countLogins")
self.assertRegexpMatches(json.dumps(j), "bl_reason")
self.assertRegexpMatches(json.dumps(j), '"blacklisted": false')
self.assertRegex(json.dumps(j), "countLogins")
self.assertRegex(json.dumps(j), "bl_reason")
self.assertRegex(json.dumps(j), '"blacklisted": false')

def chunkGen(self):
payload = dict()
Expand All @@ -85,4 +85,4 @@ def testChunked(self):
data=self.chunkGen(),
headers={'Content-Type': 'application/json'})
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')
54 changes: 27 additions & 27 deletions regression-tests/test_Blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,137 +11,137 @@ class TestBlacklist(ApiTestCase):
def test_NetmaskBlacklist(self):
r = self.allowFunc('goodie', '193.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.allowFunc('goodie', '2002:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.addBLEntryNetmask("193.168.0.0/16", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.addBLEntryNetmask("2002:503:ba3e::/64", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.allowFunc('goodie', '193.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

r = self.allowFunc('goodie', '2002:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

time.sleep(11);

r = self.allowFunc('goodie', '193.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.allowFunc('goodie', '2002:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

def test_IPBlacklist(self):
r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.allowFunc('goodie', '2001:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.addBLEntryIP("192.168.72.14", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.addBLEntryIP("2001:503:ba3e::2:30", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

r = self.allowFunc('goodie', '2001:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

time.sleep(11);

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.allowFunc('goodie', '2001:503:ba3e::2:30', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

def test_LoginBlacklist(self):
r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.addBLEntryLogin("goodie", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

time.sleep(11);

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

def test_IPLoginBlacklist(self):
r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.addBLEntryIPLogin("192.168.72.14", "goodie", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

r = self.allowFunc('goody', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

r = self.allowFunc('goodie', '192.168.72.15', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

time.sleep(11);

r = self.allowFunc('goodie', '192.168.72.14', "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

def test_PersistBlacklist(self):
Expand All @@ -151,7 +151,7 @@ def test_PersistBlacklist(self):

r = self.addBLEntryIPPersist("99.99.99.99", 10, "test blacklist")
j = r.json()
self.assertEquals(j['status'], 'ok')
self.assertEqual(j['status'], 'ok')

print("Killing process")
proc3.terminate()
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/test_Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestBlock(ApiTestCase):
def test_block(self):
r = self.allowFunc("baddie", "127.0.0.1", "1234")
j = r.json()
self.assertEquals(j['status'], 0)
self.assertEqual(j['status'], 0)
r.close()

for i in range(100):
Expand All @@ -18,6 +18,6 @@ def test_block(self):

r = self.allowFunc('baddie', '127.0.0.1', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertEqual(j['status'], -1)
r.close()

10 changes: 5 additions & 5 deletions regression-tests/test_GeoIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ def test_geoIP(self):
# don't allow IPs from Japan (arbitrary)
r = self.allowFunc('baddie', '112.78.112.20', "1234")
j = r.json()
self.assertEquals(j['status'], -1)
self.assertRegexpMatches(json.dumps(j), "Japan")
self.assertEqual(j['status'], -1)
self.assertRegex(json.dumps(j), "Japan")
r.close()

# def test_geoIP2City(self):
# attrs = dict()
# attrs['ip'] = '128.243.1.1'
# r = self.customFuncWithName("geoip2", attrs)
# j = r.json()
# self.assertRegexpMatches(json.dumps(j), "Nottingham")
# self.assertRegex(json.dumps(j), "Nottingham")
# r.close()

def test_geoIP2LookupVals(self):
Expand All @@ -39,6 +39,6 @@ def test_geoIP2LookupVals(self):
r = self.customFuncWithName("geoip2_lookupValue", attrs)
j = r.json()
print(json.dumps(j))
self.assertRegexpMatches(json.dumps(j['r_attrs']['city']), "Nottingham")
self.assertRegexpMatches(json.dumps(j['r_attrs']['latitude']), "52.9538")
self.assertRegex(json.dumps(j['r_attrs']['city']), "Nottingham")
self.assertRegex(json.dumps(j['r_attrs']['latitude']), "52.9538")
r.close()
4 changes: 2 additions & 2 deletions regression-tests/test_Prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def parsePrometheusResponse(self, response):
def getWforcePrometheusValues(self):
r = self.getWforceMetrics()
self.assertTrue(r)
self.assertEquals(r.status_code, 200)
self.assertEqual(r.status_code, 200)

return self.parsePrometheusResponse(r.text)

def getTrackalertPrometheusValues(self):
r = self.getTrackalertMetrics()
self.assertTrue(r)
self.assertEquals(r.status_code, 200)
self.assertEqual(r.status_code, 200)

return self.parsePrometheusResponse(r.text)

Expand Down
Loading

0 comments on commit 2f4de29

Please sign in to comment.