| 1 |
import unittest,sys |
| 2 |
sys.path.append('../') |
| 3 |
from a10 import axapi_auth, axapi_action |
| 4 |
|
| 5 |
a10_tps = "192.168.199.152" |
| 6 |
username = "admin" |
| 7 |
password = "a10" |
| 8 |
hostname = "TH4435" |
| 9 |
|
| 10 |
class Test_Auth(unittest.TestCase): |
| 11 |
|
| 12 |
def testAssertTrue(self): |
| 13 |
print("Testing axapi_auth") |
| 14 |
try: |
| 15 |
mitigator_base_url, signature = axapi_auth(a10_tps, username, password) |
| 16 |
print("base url: ", mitigator_base_url, "Signature: ", signature) |
| 17 |
axapi_action(mitigator_base_url+"/axapi/v3/logoff") |
| 18 |
|
| 19 |
except Exception as e: |
| 20 |
self.fail("Not authenticated") |
| 21 |
|
| 22 |
|
| 23 |
class Test_API_Actions(unittest.TestCase): |
| 24 |
|
| 25 |
def testAssertTrue(self): |
| 26 |
try: |
| 27 |
print("Testing GET") |
| 28 |
mitigator_base_url, signature = axapi_auth(a10_tps, username, password) |
| 29 |
r = axapi_action(mitigator_base_url+"/axapi/v3/version/oper", method='GET', signature=signature) |
| 30 |
print(str(r)) |
| 31 |
print("Testing POST") |
| 32 |
hostname_payload = {"hostname": {"value": hostname}} |
| 33 |
r = axapi_action(mitigator_base_url+"/axapi/v3/hostname", payload=hostname_payload, signature=signature) |
| 34 |
print(str(r)) |
| 35 |
axapi_action(mitigator_base_url+"/axapi/v3/logoff") |
| 36 |
|
| 37 |
except Exception as e: |
| 38 |
self.fail("Failed") |
| 39 |
|
| 40 |
if __name__ == "__main__": |
| 41 |
unittest.main() |
| 42 |
|
| 43 |
|