Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.0.2 #27

Merged
merged 15 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 4 additions & 148 deletions .github/scripts/additional_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import sys
import ssl
import base64
import unittest
from aiohttp import ClientSession, TCPConnector

Expand All @@ -18,77 +17,6 @@
ZABBIX_URL = 'https://127.0.0.1:443'
ZABBIX_USER = 'Admin'
ZABBIX_PASSWORD = 'zabbix'
HTTP_USER = 'http_user'
HTTP_PASSWORD = 'http_pass'


class IntegrationAPITest(unittest.TestCase):
"""Test working with a real Zabbix API instance synchronously"""

def setUp(self):
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/http_auth/'
self.api = ZabbixAPI(
url=self.url,
user=self.user,
password=self.password,
skip_version_check=True,
validate_certs=False,
http_user=HTTP_USER,
http_password=HTTP_PASSWORD
)

def tearDown(self):
if self.api:
self.api.logout()

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

self.assertEqual(
type(self.api), ZabbixAPI, "Login was going wrong")
self.assertEqual(
type(self.api.api_version()), APIVersion, "Version getting was going wrong")

def test_basic_auth(self):
"""Tests __basic_auth function works properly"""

self.assertEqual(
self.api._ZabbixAPI__basic_cred, base64.b64encode(
"http_user:http_pass".encode()
).decode(), "Basic auth credentials generation was going wrong")

def test_version_get(self):
"""Tests getting version info works properly"""

version = None
if self.api:
version = self.api.apiinfo.version()
self.assertEqual(
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")

def test_check_auth(self):
"""Tests checking authentication state works properly"""

resp = None
if self.api:
if self.api._ZabbixAPI__session_id == self.api._ZabbixAPI__token:
resp = self.api.user.checkAuthentication(token=self.api._ZabbixAPI__session_id)
else:
resp = self.api.user.checkAuthentication(sessionid=self.api._ZabbixAPI__session_id)
self.assertEqual(
type(resp), dict, "Request user.checkAuthentication was going wrong")

def test_user_get(self):
"""Tests getting users info works properly"""

users = None
if self.api:
users = self.api.user.get(
output=['userid', 'name']
)
self.assertEqual(type(users), list, "Request user.get was going wrong")


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


class IntegrationAsyncAPITest(unittest.IsolatedAsyncioTestCase):
"""Test working with a real Zabbix API instance asynchronously"""

async def asyncSetUp(self):
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/http_auth/'
self.api = AsyncZabbixAPI(
url=self.url,
skip_version_check=True,
validate_certs=False,
http_user=HTTP_USER,
http_password=HTTP_PASSWORD
)
await self.api.login(
user=self.user,
password=self.password
)

async def asyncTearDown(self):
if self.api:
await self.api.logout()

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

self.assertEqual(
type(self.api), AsyncZabbixAPI, "Login was going wrong")
self.assertEqual(
type(self.api.api_version()), APIVersion, "Version getting was going wrong")

async def test_basic_auth(self):
"""Tests __basic_auth function works properly"""

basic_auth = self.api.client_session._default_auth

self.assertEqual(
base64.b64encode(f"{basic_auth.login}:{basic_auth.password}".encode()).decode(),
base64.b64encode(f"{HTTP_USER}:{HTTP_PASSWORD}".encode()).decode(),
"Basic auth credentials generation was going wrong"
)

async def test_version_get(self):
"""Tests getting version info works properly"""

version = None
if self.api:
version = await self.api.apiinfo.version()
self.assertEqual(
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")

async def test_check_auth(self):
"""Tests checking authentication state works properly"""

resp = None
if self.api:
if self.api._AsyncZabbixAPI__session_id == self.api._AsyncZabbixAPI__token:
resp = await self.api.user.checkAuthentication(token=(self.api._AsyncZabbixAPI__session_id or ''))
else:
resp = await self.api.user.checkAuthentication(sessionid=(self.api._AsyncZabbixAPI__session_id or ''))
self.assertEqual(
type(resp), dict, "Request user.checkAuthentication was going wrong")

async def test_user_get(self):
"""Tests getting users info works properly"""

users = None
if self.api:
users = await self.api.user.get(
output=['userid', 'name']
)
self.assertEqual(type(users), list, "Request user.get was going wrong")


class CustomCertAsyncAPITest(unittest.IsolatedAsyncioTestCase):
"""Test working with a real Zabbix API instance asynchronously"""

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

context = ssl.create_default_context()
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')
session = ClientSession(
self.session = ClientSession(
connector=TCPConnector(ssl=context)
)

self.api = AsyncZabbixAPI(
url=self.url,
skip_version_check=True,
client_session=session
client_session=self.session
)
await self.api.login(
user=self.user,
Expand All @@ -255,6 +109,8 @@ async def asyncSetUp(self):
async def asyncTearDown(self):
if self.api:
await self.api.logout()
if not self.session.closed:
await self.session.close()

async def test_login(self):
"""Tests login function works properly"""
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/compatibility_api_test_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def prepare_items(self):
value_type=3
)['itemids'][0]

time.sleep(2)

self.assertIsNotNone(hostid, "Creating test item was going wrong")

zapi.logout()

def test_send_values(self):
"""Tests sending item values"""

time.sleep(10)

items = [
ItemValue(self.hostname, self.itemkey, 10),
ItemValue(self.hostname, self.itemkey, 'test message'),
Expand Down Expand Up @@ -337,7 +337,7 @@ async def prepare_items(self):
async def test_send_values(self):
"""Tests sending item values"""

time.sleep(2)
time.sleep(10)

items = [
ItemValue(self.hostname, self.itemkey, 10),
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/compatibility_api_test_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ def prepare_items(self):
value_type=3
)['itemids'][0]

time.sleep(2)

self.assertIsNotNone(hostid, "Creating test item was going wrong")

zapi.logout()

def test_send_values(self):
"""Tests sending item values"""

time.sleep(10)

items = [
ItemValue(self.hostname, self.itemkey, 10),
ItemValue(self.hostname, self.itemkey, 'test message'),
Expand Down Expand Up @@ -403,7 +403,7 @@ async def prepare_items(self):
async def test_send_values(self):
"""Tests sending item values"""

time.sleep(2)
time.sleep(10)

items = [
ItemValue(self.hostname, self.itemkey, 10),
Expand Down
Loading
Loading