Skip to content

Commit 205c840

Browse files
authored
Release v2.0.2
2 parents e4a2ec8 + d27bad1 commit 205c840

34 files changed

+1328
-435
lines changed

.github/scripts/additional_api_tests.py

Lines changed: 4 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import sys
88
import ssl
9-
import base64
109
import unittest
1110
from aiohttp import ClientSession, TCPConnector
1211

@@ -18,77 +17,6 @@
1817
ZABBIX_URL = 'https://127.0.0.1:443'
1918
ZABBIX_USER = 'Admin'
2019
ZABBIX_PASSWORD = 'zabbix'
21-
HTTP_USER = 'http_user'
22-
HTTP_PASSWORD = 'http_pass'
23-
24-
25-
class IntegrationAPITest(unittest.TestCase):
26-
"""Test working with a real Zabbix API instance synchronously"""
27-
28-
def setUp(self):
29-
self.user = ZABBIX_USER
30-
self.password = ZABBIX_PASSWORD
31-
self.url = ZABBIX_URL + '/http_auth/'
32-
self.api = ZabbixAPI(
33-
url=self.url,
34-
user=self.user,
35-
password=self.password,
36-
skip_version_check=True,
37-
validate_certs=False,
38-
http_user=HTTP_USER,
39-
http_password=HTTP_PASSWORD
40-
)
41-
42-
def tearDown(self):
43-
if self.api:
44-
self.api.logout()
45-
46-
def test_login(self):
47-
"""Tests login function works properly"""
48-
49-
self.assertEqual(
50-
type(self.api), ZabbixAPI, "Login was going wrong")
51-
self.assertEqual(
52-
type(self.api.api_version()), APIVersion, "Version getting was going wrong")
53-
54-
def test_basic_auth(self):
55-
"""Tests __basic_auth function works properly"""
56-
57-
self.assertEqual(
58-
self.api._ZabbixAPI__basic_cred, base64.b64encode(
59-
"http_user:http_pass".encode()
60-
).decode(), "Basic auth credentials generation was going wrong")
61-
62-
def test_version_get(self):
63-
"""Tests getting version info works properly"""
64-
65-
version = None
66-
if self.api:
67-
version = self.api.apiinfo.version()
68-
self.assertEqual(
69-
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")
70-
71-
def test_check_auth(self):
72-
"""Tests checking authentication state works properly"""
73-
74-
resp = None
75-
if self.api:
76-
if self.api._ZabbixAPI__session_id == self.api._ZabbixAPI__token:
77-
resp = self.api.user.checkAuthentication(token=self.api._ZabbixAPI__session_id)
78-
else:
79-
resp = self.api.user.checkAuthentication(sessionid=self.api._ZabbixAPI__session_id)
80-
self.assertEqual(
81-
type(resp), dict, "Request user.checkAuthentication was going wrong")
82-
83-
def test_user_get(self):
84-
"""Tests getting users info works properly"""
85-
86-
users = None
87-
if self.api:
88-
users = self.api.user.get(
89-
output=['userid', 'name']
90-
)
91-
self.assertEqual(type(users), list, "Request user.get was going wrong")
9220

9321

9422
class CustomCertAPITest(unittest.TestCase):
@@ -154,80 +82,6 @@ def test_user_get(self):
15482
self.assertEqual(type(users), list, "Request user.get was going wrong")
15583

15684

157-
class IntegrationAsyncAPITest(unittest.IsolatedAsyncioTestCase):
158-
"""Test working with a real Zabbix API instance asynchronously"""
159-
160-
async def asyncSetUp(self):
161-
self.user = ZABBIX_USER
162-
self.password = ZABBIX_PASSWORD
163-
self.url = ZABBIX_URL + '/http_auth/'
164-
self.api = AsyncZabbixAPI(
165-
url=self.url,
166-
skip_version_check=True,
167-
validate_certs=False,
168-
http_user=HTTP_USER,
169-
http_password=HTTP_PASSWORD
170-
)
171-
await self.api.login(
172-
user=self.user,
173-
password=self.password
174-
)
175-
176-
async def asyncTearDown(self):
177-
if self.api:
178-
await self.api.logout()
179-
180-
async def test_login(self):
181-
"""Tests login function works properly"""
182-
183-
self.assertEqual(
184-
type(self.api), AsyncZabbixAPI, "Login was going wrong")
185-
self.assertEqual(
186-
type(self.api.api_version()), APIVersion, "Version getting was going wrong")
187-
188-
async def test_basic_auth(self):
189-
"""Tests __basic_auth function works properly"""
190-
191-
basic_auth = self.api.client_session._default_auth
192-
193-
self.assertEqual(
194-
base64.b64encode(f"{basic_auth.login}:{basic_auth.password}".encode()).decode(),
195-
base64.b64encode(f"{HTTP_USER}:{HTTP_PASSWORD}".encode()).decode(),
196-
"Basic auth credentials generation was going wrong"
197-
)
198-
199-
async def test_version_get(self):
200-
"""Tests getting version info works properly"""
201-
202-
version = None
203-
if self.api:
204-
version = await self.api.apiinfo.version()
205-
self.assertEqual(
206-
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")
207-
208-
async def test_check_auth(self):
209-
"""Tests checking authentication state works properly"""
210-
211-
resp = None
212-
if self.api:
213-
if self.api._AsyncZabbixAPI__session_id == self.api._AsyncZabbixAPI__token:
214-
resp = await self.api.user.checkAuthentication(token=(self.api._AsyncZabbixAPI__session_id or ''))
215-
else:
216-
resp = await self.api.user.checkAuthentication(sessionid=(self.api._AsyncZabbixAPI__session_id or ''))
217-
self.assertEqual(
218-
type(resp), dict, "Request user.checkAuthentication was going wrong")
219-
220-
async def test_user_get(self):
221-
"""Tests getting users info works properly"""
222-
223-
users = None
224-
if self.api:
225-
users = await self.api.user.get(
226-
output=['userid', 'name']
227-
)
228-
self.assertEqual(type(users), list, "Request user.get was going wrong")
229-
230-
23185
class CustomCertAsyncAPITest(unittest.IsolatedAsyncioTestCase):
23286
"""Test working with a real Zabbix API instance asynchronously"""
23387

@@ -238,14 +92,14 @@ async def asyncSetUp(self):
23892

23993
context = ssl.create_default_context()
24094
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')
241-
session = ClientSession(
95+
self.session = ClientSession(
24296
connector=TCPConnector(ssl=context)
24397
)
24498

24599
self.api = AsyncZabbixAPI(
246100
url=self.url,
247101
skip_version_check=True,
248-
client_session=session
102+
client_session=self.session
249103
)
250104
await self.api.login(
251105
user=self.user,
@@ -255,6 +109,8 @@ async def asyncSetUp(self):
255109
async def asyncTearDown(self):
256110
if self.api:
257111
await self.api.logout()
112+
if not self.session.closed:
113+
await self.session.close()
258114

259115
async def test_login(self):
260116
"""Tests login function works properly"""

.github/scripts/compatibility_api_test_5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ def prepare_items(self):
147147
value_type=3
148148
)['itemids'][0]
149149

150-
time.sleep(2)
151-
152150
self.assertIsNotNone(hostid, "Creating test item was going wrong")
153151

154152
zapi.logout()
155153

156154
def test_send_values(self):
157155
"""Tests sending item values"""
158156

157+
time.sleep(10)
158+
159159
items = [
160160
ItemValue(self.hostname, self.itemkey, 10),
161161
ItemValue(self.hostname, self.itemkey, 'test message'),
@@ -337,7 +337,7 @@ async def prepare_items(self):
337337
async def test_send_values(self):
338338
"""Tests sending item values"""
339339

340-
time.sleep(2)
340+
time.sleep(10)
341341

342342
items = [
343343
ItemValue(self.hostname, self.itemkey, 10),

.github/scripts/compatibility_api_test_6.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ def prepare_items(self):
179179
value_type=3
180180
)['itemids'][0]
181181

182-
time.sleep(2)
183-
184182
self.assertIsNotNone(hostid, "Creating test item was going wrong")
185183

186184
zapi.logout()
187185

188186
def test_send_values(self):
189187
"""Tests sending item values"""
190188

189+
time.sleep(10)
190+
191191
items = [
192192
ItemValue(self.hostname, self.itemkey, 10),
193193
ItemValue(self.hostname, self.itemkey, 'test message'),
@@ -403,7 +403,7 @@ async def prepare_items(self):
403403
async def test_send_values(self):
404404
"""Tests sending item values"""
405405

406-
time.sleep(2)
406+
time.sleep(10)
407407

408408
items = [
409409
ItemValue(self.hostname, self.itemkey, 10),

0 commit comments

Comments
 (0)