Skip to content

Commit f478479

Browse files
committed
made refactoring of the API implementation code
1 parent 0864efd commit f478479

9 files changed

+290
-281
lines changed

.github/scripts/additional_api_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_login(self):
3737
type(self.api.api_version()), ZabbixAPIVersion, "Version getting was going wrong")
3838

3939
def test_basic_auth(self):
40-
"""Tests basic_auth function works properly"""
40+
"""Tests __basic_auth function works properly"""
4141

4242
self.assertEqual(
4343
self.api.use_basic, True, "Basic auth was going wrong")

.github/scripts/compatibility_api_test_5.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def test_classic_auth(self):
4040
password=self.password
4141
)
4242

43-
self.assertIsNotNone(self.zapi.session_id, "Login by user and password was going wrong")
43+
self.assertIsNotNone(self.zapi._ZabbixAPI__session_id, "Login by user and password was going wrong")
4444

45-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
45+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
4646

4747
self.assertEqual(
4848
type(resp), dict, "Request user.checkAuthentication was going wrong")
@@ -54,11 +54,11 @@ def test_classic_auth(self):
5454

5555
self.zapi.logout()
5656

57-
self.assertIsNone(self.zapi.session_id, "Logout was going wrong")
57+
self.assertIsNone(self.zapi._ZabbixAPI__session_id, "Logout was going wrong")
5858

5959
with self.assertRaises(ZabbixAPIException,
6060
msg="Request user.checkAuthentication after logout was going wrong"):
61-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
61+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
6262

6363
def test_token_auth(self):
6464
"""Tests auth using token"""

.github/scripts/compatibility_api_test_6.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def _create_token(self):
4242
password=self.password
4343
)
4444

45-
self.assertIsNotNone(self.zapi.session_id, "Login was going wrong")
45+
self.assertIsNotNone(self.zapi._ZabbixAPI__session_id, "Login was going wrong")
4646

47-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
47+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
4848

4949
self.assertEqual(
5050
type(resp), dict, "Request user.checkAuthentication was going wrong")
@@ -70,11 +70,11 @@ def _create_token(self):
7070

7171
self.zapi.logout()
7272

73-
self.assertIsNone(self.zapi.session_id, "Logout was going wrong")
73+
self.assertIsNone(self.zapi._ZabbixAPI__session_id, "Logout was going wrong")
7474

7575
with self.assertRaises(ZabbixAPIException,
7676
msg="Request user.checkAuthentication after logout was going wrong"):
77-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
77+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
7878

7979
def test_classic_auth(self):
8080
"""Tests auth using username and password"""
@@ -92,7 +92,7 @@ def test_token_auth(self):
9292

9393
self.zapi.login(token=self.token)
9494

95-
self.assertIsNotNone(self.zapi.session_id, "Login was going wrong")
95+
self.assertIsNotNone(self.zapi._ZabbixAPI__session_id, "Login was going wrong")
9696

9797
resp = self.zapi.user.checkAuthentication(token=self.token)
9898

.github/scripts/compatibility_api_test_latest.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def _create_token(self):
4242
password=self.password
4343
)
4444

45-
self.assertIsNotNone(self.zapi.session_id, "Login by user and password was going wrong")
45+
self.assertIsNotNone(self.zapi._ZabbixAPI__session_id, "Login by user and password was going wrong")
4646

47-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
47+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
4848

4949
self.assertEqual(
5050
type(resp), dict, "Request user.checkAuthentication was going wrong")
@@ -70,11 +70,11 @@ def _create_token(self):
7070

7171
self.zapi.logout()
7272

73-
self.assertIsNone(self.zapi.session_id, "Logout was going wrong")
73+
self.assertIsNone(self.zapi._ZabbixAPI__session_id, "Logout was going wrong")
7474

7575
with self.assertRaises(ZabbixAPIException,
7676
msg="Request user.checkAuthentication after logout was going wrong"):
77-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
77+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
7878

7979
def test_classic_auth(self):
8080
"""Tests auth using username and password"""
@@ -92,7 +92,7 @@ def test_token_auth(self):
9292

9393
self.zapi.login(token=self.token)
9494

95-
self.assertIsNotNone(self.zapi.session_id, "Login by token was going wrong")
95+
self.assertIsNotNone(self.zapi._ZabbixAPI__session_id, "Login by token was going wrong")
9696

9797
resp = self.zapi.user.checkAuthentication(token=self.token)
9898

@@ -106,7 +106,7 @@ def test_token_auth(self):
106106

107107
self.zapi.logout()
108108

109-
self.assertIsNone(self.zapi.session_id, "Logout was going wrong")
109+
self.assertIsNone(self.zapi._ZabbixAPI__session_id, "Logout was going wrong")
110110

111111
self.assertEqual(
112112
type(resp), dict, "Request user.checkAuthentication was going wrong")

.github/scripts/integration_api_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def test_check_auth(self):
4646

4747
resp = None
4848
if self.zapi:
49-
if self.zapi.session_id == self.zapi.token:
50-
resp = self.zapi.user.checkAuthentication(token=self.zapi.session_id)
49+
if self.zapi._ZabbixAPI__session_id == self.zapi._ZabbixAPI__token:
50+
resp = self.zapi.user.checkAuthentication(token=self.zapi._ZabbixAPI__session_id)
5151
else:
52-
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi.session_id)
52+
resp = self.zapi.user.checkAuthentication(sessionid=self.zapi._ZabbixAPI__session_id)
5353
self.assertEqual(
5454
type(resp), dict, "Request user.checkAuthentication was going wrong")
5555

examples/api/using_http_auth.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from zabbix_utils import ZabbixAPI
22

33
# Create an instance of the ZabbixAPI class with the Zabbix server URL
4-
api = ZabbixAPI(url="http://127.0.0.1")
5-
64
# Set Basic Authentication credentials for Zabbix API requests
75
# Basic Authentication - a simple authentication mechanism used in HTTP.
86
# It involves sending a username and password with each HTTP request.
9-
api.basic_auth(user="user", password="p@$sw0rd")
7+
api = ZabbixAPI(
8+
url="http://127.0.0.1",
9+
http_user="user",
10+
http_password="p@$sw0rd"
11+
)
1012

1113
# Login to the Zabbix API using provided user credentials
1214
api.login(user="Admin", password="zabbix")

0 commit comments

Comments
 (0)