Skip to content

Commit

Permalink
Merge pull request #104 from kytos-ng/upgrade/python
Browse files Browse the repository at this point in the history
Update test dependencies
  • Loading branch information
viniarck authored Mar 28, 2024
2 parents 732bd70 + 0d9e0aa commit b09b598
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ All notable changes to the of_lldp NApp will be documented in this file.
[2023.2.0] - 2024-02-16
***********************

Changed
=======
- Updated python environment installation from 3.9 to 3.11
- Updated test dependencies

[2023.2.0] - 2024-02-16
***********************

Changed
=======
- ``FLOW_VLAN_VID`` from settings now is used or made available in all interfaces from the switch where a flow is created or deleted.
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ To install this NApp, first, make sure to have the same venv activated as you ha
$ git clone https://github.com/kytos-ng/of_lldp.git
$ cd of_lldp
$ python setup.py develop
$ python3 -m pip install --editable .
To install the kytos environment, please follow our
`development environment setup <https://github.com/kytos-ng/documentation/blob/master/tutorials/napps/development_environment_setup.rst>`_.

Requirements
============
Expand Down
4 changes: 3 additions & 1 deletion controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def upsert_interfaces(
**{"_id": interface_id, "updated_at": utc_now},
}
)
payload = model.dict(exclude={"inserted_at"}, exclude_none=True)
payload = model.model_dump(
exclude={"inserted_at"}, exclude_none=True
)
ops.append(
UpdateOne(
{"_id": interface_id},
Expand Down
8 changes: 4 additions & 4 deletions db/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class DocumentBaseModel(BaseModel):
"""DocumentBaseModel."""

id: str = Field(None, alias="_id")
inserted_at: Optional[datetime]
updated_at: Optional[datetime]
inserted_at: Optional[datetime] = None
updated_at: Optional[datetime] = None

def dict(self, **kwargs) -> dict:
def model_dump(self, **kwargs) -> dict:
"""Model to dict."""
values = super().dict(**kwargs)
values = super().model_dump(**kwargs)
if "id" in values and values["id"]:
values["_id"] = values["id"]
if "exclude" in kwargs and "_id" in kwargs["exclude"]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def read_requirements(path="requirements/run.txt"):
author='Kytos Team',
author_email='[email protected]',
license='MIT',
install_requires=read_requirements() + ['setuptools >= 36.0.1'],
install_requires=read_requirements() + ['importlib_metadata'],
packages=[],
cmdclass={
'clean': Cleaner,
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Main methods."""
import asyncio
from unittest.mock import AsyncMock, MagicMock, call, patch

from httpx import Response
Expand Down Expand Up @@ -416,13 +417,13 @@ async def test_rest_get_lldp_interfaces(self):
assert response.status_code == 200
assert response.json() == expected_data

async def test_enable_disable_lldp_200(self, event_loop):
async def test_enable_disable_lldp_200(self):
"""Test 200 response for enable_lldp and disable_lldp methods."""
data = {"interfaces": ['00:00:00:00:00:00:00:01:1',
'00:00:00:00:00:00:00:01:2',
'00:00:00:00:00:00:00:02:1',
'00:00:00:00:00:00:00:02:2']}
self.napp.controller.loop = event_loop
self.napp.controller.loop = asyncio.get_running_loop()
self.napp.publish_liveness_status = MagicMock()
endpoint = f"{self.base_endpoint}/interfaces/disable"
response = await self.api_client.post(endpoint, json=data)
Expand All @@ -444,7 +445,7 @@ async def test_enable_disable_lldp_404(self):
response = await self.api_client.post(endpoint, json=data)
assert response.status_code == 404

async def test_enable_disable_lldp_400(self, event_loop):
async def test_enable_disable_lldp_400(self):
"""Test 400 response for enable_lldp and disable_lldp methods."""
data = {"interfaces": ['00:00:00:00:00:00:00:01:1',
'00:00:00:00:00:00:00:01:2',
Expand All @@ -453,7 +454,7 @@ async def test_enable_disable_lldp_400(self, event_loop):
'00:00:00:00:00:00:00:03:1',
'00:00:00:00:00:00:00:03:2',
'00:00:00:00:00:00:00:04:1']}
self.napp.controller.loop = event_loop
self.napp.controller.loop = asyncio.get_running_loop()
self.napp.publish_liveness_status = MagicMock()
url = f'{self.base_endpoint}/interfaces/disable'
response = await self.api_client.post(url, json=data)
Expand Down Expand Up @@ -484,9 +485,9 @@ async def test_set_time_400(self):
response = await self.api_client.post(url, json=data)
assert response.status_code == 400

async def test_endpoint_enable_liveness(self, event_loop):
async def test_endpoint_enable_liveness(self):
"""Test POST v1/liveness/enable."""
self.napp.controller.loop = event_loop
self.napp.controller.loop = asyncio.get_running_loop()
self.napp.liveness_manager.enable = MagicMock()
self.napp.publish_liveness_status = MagicMock()
url = f"{self.base_endpoint}/liveness/enable"
Expand All @@ -498,9 +499,9 @@ async def test_endpoint_enable_liveness(self, event_loop):
assert self.napp.liveness_manager.enable.call_count == 1
assert self.napp.publish_liveness_status.call_count == 1

async def test_endpoint_disable_liveness(self, event_loop):
async def test_endpoint_disable_liveness(self):
"""Test POST v1/liveness/disable."""
self.napp.controller.loop = event_loop
self.napp.controller.loop = asyncio.get_running_loop()
self.napp.liveness_manager.disable = MagicMock()
self.napp.publish_liveness_status = MagicMock()
url = f"{self.base_endpoint}/liveness/disable"
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ envlist = coverage,lint


[testenv]
whitelist_externals = rm
deps = -Urrequirements/dev.in
allowlist_externals = rm
deps = -rrequirements/dev.in
setenv=
PYTHONPATH = {toxworkdir}/py39/var/lib/kytos/:{envdir}
PYTHONPATH = {toxworkdir}/py311/var/lib/kytos/:{envdir}


[testenv:coverage]
skip_install = true
envdir = {toxworkdir}/py39
envdir = {toxworkdir}/py311
commands=
python3 setup.py coverage {posargs}


[testenv:lint]
skip_install = true
envdir = {toxworkdir}/py39
envdir = {toxworkdir}/py311
commands = python3 setup.py lint

0 comments on commit b09b598

Please sign in to comment.