From 4453187c6c7936dfe763d2dc951ba41502d5ff90 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 12:02:00 +0100 Subject: [PATCH 01/16] MAINT: Refactor directory structure Changed the package name to be more appropriate. And restructured the modules to be in correct directories. --- .gitignore | 2 +- .../Tests/test_csv_utils.py | 0 .../Tests/test_netbox_connect.py | 2 +- .../Tests/test_netbox_create.py | 0 .../Tests/test_netbox_existence.py | 0 .../lib}/CSV/csv_utils.py | 0 .../lib}/CSV/format_dict.py | 0 .../lib}/Enums/dcim_device_id.py | 0 .../lib}/Enums/dcim_device_no_id.py | 0 .../lib}/Netbox_Api/netbox_connect.py | 0 .../lib}/Netbox_Api/netbox_create.py | 0 .../lib}/Netbox_Api/netbox_data.py | 0 .../lib}/Netbox_Api/netbox_existence.py | 0 Pynetbox_Data_Uploader/pytest.ini | 5 +++++ .../requirements.txt | Bin 15 files changed, 7 insertions(+), 2 deletions(-) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader}/Tests/test_csv_utils.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader}/Tests/test_netbox_connect.py (90%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader}/Tests/test_netbox_create.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader}/Tests/test_netbox_existence.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/CSV/csv_utils.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/CSV/format_dict.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Enums/dcim_device_id.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Enums/dcim_device_no_id.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Netbox_Api/netbox_connect.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Netbox_Api/netbox_create.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Netbox_Api/netbox_data.py (100%) rename {Netbox_CSV_Read => Pynetbox_Data_Uploader/lib}/Netbox_Api/netbox_existence.py (100%) create mode 100644 Pynetbox_Data_Uploader/pytest.ini rename {Netbox_CSV_Read => Pynetbox_Data_Uploader}/requirements.txt (100%) diff --git a/.gitignore b/.gitignore index d39e7248..8d0d9e54 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ venv/ .coverage coverage.xml -Netbox_CSV_Read/DataFiles \ No newline at end of file +Pynetbox_Data_Uploader/DataFiles \ No newline at end of file diff --git a/Netbox_CSV_Read/Tests/test_csv_utils.py b/Pynetbox_Data_Uploader/Tests/test_csv_utils.py similarity index 100% rename from Netbox_CSV_Read/Tests/test_csv_utils.py rename to Pynetbox_Data_Uploader/Tests/test_csv_utils.py diff --git a/Netbox_CSV_Read/Tests/test_netbox_connect.py b/Pynetbox_Data_Uploader/Tests/test_netbox_connect.py similarity index 90% rename from Netbox_CSV_Read/Tests/test_netbox_connect.py rename to Pynetbox_Data_Uploader/Tests/test_netbox_connect.py index b1caaa60..993839d1 100644 --- a/Netbox_CSV_Read/Tests/test_netbox_connect.py +++ b/Pynetbox_Data_Uploader/Tests/test_netbox_connect.py @@ -1,4 +1,4 @@ -from unittest.mock import MagicMock, NonCallableMock, patch +from unittest.mock import NonCallableMock, patch from Netbox_Api.netbox_connect import NetboxConnect import pytest diff --git a/Netbox_CSV_Read/Tests/test_netbox_create.py b/Pynetbox_Data_Uploader/Tests/test_netbox_create.py similarity index 100% rename from Netbox_CSV_Read/Tests/test_netbox_create.py rename to Pynetbox_Data_Uploader/Tests/test_netbox_create.py diff --git a/Netbox_CSV_Read/Tests/test_netbox_existence.py b/Pynetbox_Data_Uploader/Tests/test_netbox_existence.py similarity index 100% rename from Netbox_CSV_Read/Tests/test_netbox_existence.py rename to Pynetbox_Data_Uploader/Tests/test_netbox_existence.py diff --git a/Netbox_CSV_Read/CSV/csv_utils.py b/Pynetbox_Data_Uploader/lib/CSV/csv_utils.py similarity index 100% rename from Netbox_CSV_Read/CSV/csv_utils.py rename to Pynetbox_Data_Uploader/lib/CSV/csv_utils.py diff --git a/Netbox_CSV_Read/CSV/format_dict.py b/Pynetbox_Data_Uploader/lib/CSV/format_dict.py similarity index 100% rename from Netbox_CSV_Read/CSV/format_dict.py rename to Pynetbox_Data_Uploader/lib/CSV/format_dict.py diff --git a/Netbox_CSV_Read/Enums/dcim_device_id.py b/Pynetbox_Data_Uploader/lib/Enums/dcim_device_id.py similarity index 100% rename from Netbox_CSV_Read/Enums/dcim_device_id.py rename to Pynetbox_Data_Uploader/lib/Enums/dcim_device_id.py diff --git a/Netbox_CSV_Read/Enums/dcim_device_no_id.py b/Pynetbox_Data_Uploader/lib/Enums/dcim_device_no_id.py similarity index 100% rename from Netbox_CSV_Read/Enums/dcim_device_no_id.py rename to Pynetbox_Data_Uploader/lib/Enums/dcim_device_no_id.py diff --git a/Netbox_CSV_Read/Netbox_Api/netbox_connect.py b/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_connect.py similarity index 100% rename from Netbox_CSV_Read/Netbox_Api/netbox_connect.py rename to Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_connect.py diff --git a/Netbox_CSV_Read/Netbox_Api/netbox_create.py b/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_create.py similarity index 100% rename from Netbox_CSV_Read/Netbox_Api/netbox_create.py rename to Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_create.py diff --git a/Netbox_CSV_Read/Netbox_Api/netbox_data.py b/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_data.py similarity index 100% rename from Netbox_CSV_Read/Netbox_Api/netbox_data.py rename to Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_data.py diff --git a/Netbox_CSV_Read/Netbox_Api/netbox_existence.py b/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_existence.py similarity index 100% rename from Netbox_CSV_Read/Netbox_Api/netbox_existence.py rename to Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_existence.py diff --git a/Pynetbox_Data_Uploader/pytest.ini b/Pynetbox_Data_Uploader/pytest.ini new file mode 100644 index 00000000..65c35ff4 --- /dev/null +++ b/Pynetbox_Data_Uploader/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +pythonpath = lib +testpaths = Tests +python_files = *.py +python_functions = test_* \ No newline at end of file diff --git a/Netbox_CSV_Read/requirements.txt b/Pynetbox_Data_Uploader/requirements.txt similarity index 100% rename from Netbox_CSV_Read/requirements.txt rename to Pynetbox_Data_Uploader/requirements.txt From d10e13692aea63c2b996f0d9ed8e273cd6a44e0c Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 12:14:46 +0100 Subject: [PATCH 02/16] Created Github Workflow Created a workflow to run pytests and pylint at pull request to master branch. --- .github/workflows/Pynetbox.yaml | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/Pynetbox.yaml diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml new file mode 100644 index 00000000..38a371bc --- /dev/null +++ b/.github/workflows/Pynetbox.yaml @@ -0,0 +1,36 @@ +name: Pynetbox Data Uploader Tests + +on: + push: + branches: + - master + pull_request: + paths: + - "Pynetbox_Data_Uploader/**" + - ".github/workflows/Pynetbox.yaml" + +jobs: + test_and_lint: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: ["3.x"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r ./requirements.txt + + - name: Run tests + run: cd Tests/ && python3 -m pytest . + + - name: Analyse with pylint + run: | + pylint lib From e637f655a922f8ae57ff83065c7cfea2164df74b Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 12:54:48 +0100 Subject: [PATCH 03/16] Changed path of requirements file in workflow --- .github/workflows/Pynetbox.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index 38a371bc..c1b0eeed 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -26,11 +26,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r ./requirements.txt + pip install -r Pynetbox_Data_Uploader/requirements.txt - name: Run tests run: cd Tests/ && python3 -m pytest . - name: Analyse with pylint run: | - pylint lib + pylint Pynetbox_Data_Uploader/lib From 19f231ed13d9404c76f5b6024236fddb3aae9223 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 12:58:00 +0100 Subject: [PATCH 04/16] Changed path for Pytest workflow --- .github/workflows/Pynetbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index c1b0eeed..4bcb2f4b 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -29,7 +29,7 @@ jobs: pip install -r Pynetbox_Data_Uploader/requirements.txt - name: Run tests - run: cd Tests/ && python3 -m pytest . + run: cd Pynetbox_Data_Uploader && python3 -m pytest . - name: Analyse with pylint run: | From ed7f3e0b19f4db6b60bc853cca38db7dd1ec1f08 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 12:58:00 +0100 Subject: [PATCH 05/16] MAINT: Changed path for Pytest workflow --- .github/workflows/Pynetbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index c1b0eeed..4bcb2f4b 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -29,7 +29,7 @@ jobs: pip install -r Pynetbox_Data_Uploader/requirements.txt - name: Run tests - run: cd Tests/ && python3 -m pytest . + run: cd Pynetbox_Data_Uploader && python3 -m pytest . - name: Analyse with pylint run: | From a7c0774a6af97740ae285f97fed5de7f4869e7fe Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 13:00:08 +0100 Subject: [PATCH 06/16] MAINT: Added Pylint to requirements.txt --- Pynetbox_Data_Uploader/requirements.txt | Bin 72 -> 88 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Pynetbox_Data_Uploader/requirements.txt b/Pynetbox_Data_Uploader/requirements.txt index be73a76dbebcb6ec0aebe2cd6c54a28625855aca..a12310d5b83abb5afdfc794c83ad11ace15e7118 100644 GIT binary patch delta 25 ccmeZ>nBXE(z);DM!;s04$56t+%fJQ308A+aR{#J2 delta 9 Qcma#>nBc;~%fQ6|01HI{kN^Mx From cc6d14cb334391173be9ebed838736d52c85a04e Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 13:04:59 +0100 Subject: [PATCH 07/16] Added __init__.py to all python directories. --- Pynetbox_Data_Uploader/Tests/__init__.py | 0 Pynetbox_Data_Uploader/lib/CSV/__init__.py | 0 Pynetbox_Data_Uploader/lib/Enums/__init__.py | 0 Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py | 0 Pynetbox_Data_Uploader/lib/__init__.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Pynetbox_Data_Uploader/Tests/__init__.py create mode 100644 Pynetbox_Data_Uploader/lib/CSV/__init__.py create mode 100644 Pynetbox_Data_Uploader/lib/Enums/__init__.py create mode 100644 Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py create mode 100644 Pynetbox_Data_Uploader/lib/__init__.py diff --git a/Pynetbox_Data_Uploader/Tests/__init__.py b/Pynetbox_Data_Uploader/Tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Pynetbox_Data_Uploader/lib/CSV/__init__.py b/Pynetbox_Data_Uploader/lib/CSV/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Pynetbox_Data_Uploader/lib/Enums/__init__.py b/Pynetbox_Data_Uploader/lib/Enums/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py b/Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Pynetbox_Data_Uploader/lib/__init__.py b/Pynetbox_Data_Uploader/lib/__init__.py new file mode 100644 index 00000000..e69de29b From 83400f29fe91fd00bb034ec5c732b42dea70126d Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 13:49:10 +0100 Subject: [PATCH 08/16] Linting Fixes --- Pynetbox_Data_Uploader/.pylintrc | 13 ++++++++++++ .../{Tests => lib/csv_things}/__init__.py | 0 .../lib/{CSV => csv_things}/csv_utils.py | 21 +++++++++---------- .../lib/{CSV => csv_things}/format_dict.py | 8 +++---- .../lib/{CSV => enums}/__init__.py | 0 .../lib/{Enums => enums}/dcim_device_id.py | 0 .../lib/{Enums => enums}/dcim_device_no_id.py | 12 +++++------ .../lib/{Enums => netbox_api}/__init__.py | 0 .../netbox_connect.py | 1 + .../netbox_create.py | 2 +- .../{Netbox_Api => netbox_api}/netbox_data.py | 11 +++++----- .../netbox_existence.py | 4 ++-- .../{lib/Netbox_Api => tests}/__init__.py | 0 .../{Tests => tests}/test_csv_utils.py | 12 +++++------ .../{Tests => tests}/test_netbox_connect.py | 4 ++-- .../{Tests => tests}/test_netbox_create.py | 2 +- .../{Tests => tests}/test_netbox_existence.py | 2 +- 17 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 Pynetbox_Data_Uploader/.pylintrc rename Pynetbox_Data_Uploader/{Tests => lib/csv_things}/__init__.py (100%) rename Pynetbox_Data_Uploader/lib/{CSV => csv_things}/csv_utils.py (59%) rename Pynetbox_Data_Uploader/lib/{CSV => csv_things}/format_dict.py (88%) rename Pynetbox_Data_Uploader/lib/{CSV => enums}/__init__.py (100%) rename Pynetbox_Data_Uploader/lib/{Enums => enums}/dcim_device_id.py (100%) rename Pynetbox_Data_Uploader/lib/{Enums => enums}/dcim_device_no_id.py (52%) rename Pynetbox_Data_Uploader/lib/{Enums => netbox_api}/__init__.py (100%) rename Pynetbox_Data_Uploader/lib/{Netbox_Api => netbox_api}/netbox_connect.py (93%) rename Pynetbox_Data_Uploader/lib/{Netbox_Api => netbox_api}/netbox_create.py (96%) rename Pynetbox_Data_Uploader/lib/{Netbox_Api => netbox_api}/netbox_data.py (87%) rename Pynetbox_Data_Uploader/lib/{Netbox_Api => netbox_api}/netbox_existence.py (91%) rename Pynetbox_Data_Uploader/{lib/Netbox_Api => tests}/__init__.py (100%) rename Pynetbox_Data_Uploader/{Tests => tests}/test_csv_utils.py (73%) rename Pynetbox_Data_Uploader/{Tests => tests}/test_netbox_connect.py (80%) rename Pynetbox_Data_Uploader/{Tests => tests}/test_netbox_create.py (96%) rename Pynetbox_Data_Uploader/{Tests => tests}/test_netbox_existence.py (95%) diff --git a/Pynetbox_Data_Uploader/.pylintrc b/Pynetbox_Data_Uploader/.pylintrc new file mode 100644 index 00000000..8593071a --- /dev/null +++ b/Pynetbox_Data_Uploader/.pylintrc @@ -0,0 +1,13 @@ +[FORMAT] +# Black will enforce 88 chars on Python code +# this will enforce 120 chars on docs / comments +max-line-length=120 + +# Disable various warnings: +# C0114: Missing module string - we don't need module strings for the small repo +# C0115: Missing class doc string - a lot of the actions are self explanatory +# W0511: TODOs they're well....to do later +# R0801: Similar lines - Imports and method signatures will flag this, such as forwarding action args +# C0116: Missing method docstring - Adds too much noise + +disable=C0114,C0115,E0401,W0511,R0801,C0116 \ No newline at end of file diff --git a/Pynetbox_Data_Uploader/Tests/__init__.py b/Pynetbox_Data_Uploader/lib/csv_things/__init__.py similarity index 100% rename from Pynetbox_Data_Uploader/Tests/__init__.py rename to Pynetbox_Data_Uploader/lib/csv_things/__init__.py diff --git a/Pynetbox_Data_Uploader/lib/CSV/csv_utils.py b/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py similarity index 59% rename from Pynetbox_Data_Uploader/lib/CSV/csv_utils.py rename to Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py index cc105ba0..0cdee35c 100644 --- a/Pynetbox_Data_Uploader/lib/CSV/csv_utils.py +++ b/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py @@ -1,30 +1,29 @@ -import pandas from typing import List, Dict +import pandas as pd class CsvUtils: """ - This class provides methods to read data from CSV files and allow the data to be easily read and used elsewhere. + This class provides methods to read data from csv_things files + and allow the data to be easily read and used elsewhere. """ - def __init__(self): - self.pd = pandas - - def csv_to_python(self, file_path: str) -> Dict: + @staticmethod + def csv_to_python(file_path: str) -> Dict: """ This method reads data from csv files and writes them to a dictionary. - :param file_path: The file path of the CSV file to be read from. + :param file_path: The file path of the csv_things file to be read from. :return: Returns the data from the csv as a dictionary. """ - dataframe = self.pd.read_csv(file_path) + dataframe = pd.read_csv(file_path) dataframe = dataframe.to_dict(orient="list") return dataframe @staticmethod def separate_data(data: dict) -> List: """ - This method reduces Pandas CSV to Dict conversion to individual dictionaries. - :param data: The data from the CSV file - :return: Returns a list of dictionaries which each represent a row of data from CSV. + This method reduces Pandas csv_things to Dict conversion to individual dictionaries. + :param data: The data from the csv_things file + :return: Returns a list of dictionaries which each represent a row of data from csv_things. """ data_keys = list(data.keys()) len_rows = len(data[data_keys[0]]) diff --git a/Pynetbox_Data_Uploader/lib/CSV/format_dict.py b/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py similarity index 88% rename from Pynetbox_Data_Uploader/lib/CSV/format_dict.py rename to Pynetbox_Data_Uploader/lib/csv_things/format_dict.py index 04b0655c..e2d327db 100644 --- a/Pynetbox_Data_Uploader/lib/CSV/format_dict.py +++ b/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py @@ -1,8 +1,8 @@ from typing import Dict, List -from Enums.dcim_device_id import DeviceInfoID -from Enums.dcim_device_no_id import DeviceInfoNoID -from Netbox_Api.netbox_connect import NetboxConnect -from Netbox_Api.netbox_data import NetboxGetID +from enums.dcim_device_id import DeviceInfoID +from enums.dcim_device_no_id import DeviceInfoNoID +from netbox_api.netbox_connect import NetboxConnect +from netbox_api.netbox_data import NetboxGetID class FormatDict(NetboxConnect): diff --git a/Pynetbox_Data_Uploader/lib/CSV/__init__.py b/Pynetbox_Data_Uploader/lib/enums/__init__.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/CSV/__init__.py rename to Pynetbox_Data_Uploader/lib/enums/__init__.py diff --git a/Pynetbox_Data_Uploader/lib/Enums/dcim_device_id.py b/Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/Enums/dcim_device_id.py rename to Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py diff --git a/Pynetbox_Data_Uploader/lib/Enums/dcim_device_no_id.py b/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py similarity index 52% rename from Pynetbox_Data_Uploader/lib/Enums/dcim_device_no_id.py rename to Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py index 66b0c2e8..95382dd4 100644 --- a/Pynetbox_Data_Uploader/lib/Enums/dcim_device_no_id.py +++ b/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py @@ -5,9 +5,9 @@ class DeviceInfoNoID(Enum): """ This Enums Class stores enums that are used to retrieve data from Netbox. """ - position = "position" - name = "name" - serial = "serial" - airflow = "airflow" - status = "status" - face = "face" \ No newline at end of file + POSITION = "position" + NAME = "name" + SERIAL = "serial" + AIRFLOW = "airflow" + STATUS = "status" + FACE = "face" diff --git a/Pynetbox_Data_Uploader/lib/Enums/__init__.py b/Pynetbox_Data_Uploader/lib/netbox_api/__init__.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/Enums/__init__.py rename to Pynetbox_Data_Uploader/lib/netbox_api/__init__.py diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_connect.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py similarity index 93% rename from Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_connect.py rename to Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py index f57554a0..f8091586 100644 --- a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_connect.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py @@ -1,4 +1,5 @@ import pynetbox as nb +# pylint:disable = too-few-public-methods class NetboxConnect: diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_create.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py similarity index 96% rename from Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_create.py rename to Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py index fe16efe1..d8a95b1a 100644 --- a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_create.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py @@ -1,5 +1,5 @@ from typing import Optional -from Netbox_Api.netbox_connect import NetboxConnect +from netbox_api.netbox_connect import NetboxConnect class NetboxDCIM: diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_data.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py similarity index 87% rename from Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_data.py rename to Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py index 579b9bba..297d5885 100644 --- a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_data.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py @@ -1,8 +1,9 @@ -from Netbox_Api.netbox_connect import NetboxConnect -from Enums.dcim_device_id import DeviceInfoID -from Enums.dcim_device_no_id import DeviceInfoNoID from operator import attrgetter from typing import Optional +from netbox_api.netbox_connect import NetboxConnect +from enums.dcim_device_id import DeviceInfoID +from enums.dcim_device_no_id import DeviceInfoNoID +# pylint:disable = too-few-public-methods class NetboxGetID(NetboxConnect): @@ -32,12 +33,12 @@ def get_id(self, attr_string: str, netbox_value: str, site_value: str) -> int | :return: Returns the value/ID """ attr_string = attr_string.upper() - attr_to_look_for = getattr(self.enums_id, attr_string).value # Gets Enums value + attr_to_look_for = getattr(self.enums_id, attr_string).value # Gets enums value value = attrgetter(attr_to_look_for)(self.netbox) # Gets netbox attr if attr_string == "DEVICE_TYPE": value = value.get(slug=netbox_value).id elif attr_string == "LOCATION": - if type(site_value) == int: + if isinstance(site_value, int): site_name = self.netbox.dcim.sites.get(site_value).name site_slug = site_name.replace(" ", "-").lower() value = value.get(name=netbox_value, site=site_slug) diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_existence.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_existence.py similarity index 91% rename from Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_existence.py rename to Pynetbox_Data_Uploader/lib/netbox_api/netbox_existence.py index ce3aad5c..f7c2fe62 100644 --- a/Pynetbox_Data_Uploader/lib/Netbox_Api/netbox_existence.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_existence.py @@ -1,5 +1,5 @@ from typing import Optional -from Netbox_Api.netbox_connect import NetboxConnect +from netbox_api.netbox_connect import NetboxConnect class NetboxExistence: @@ -29,4 +29,4 @@ def check_device_type_exists(self, device_type: str) -> bool: :return: Returns bool. """ device_type = self.netbox.dcim.device_types.get(slug=device_type) - return bool(device_type) \ No newline at end of file + return bool(device_type) diff --git a/Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py b/Pynetbox_Data_Uploader/tests/__init__.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/Netbox_Api/__init__.py rename to Pynetbox_Data_Uploader/tests/__init__.py diff --git a/Pynetbox_Data_Uploader/Tests/test_csv_utils.py b/Pynetbox_Data_Uploader/tests/test_csv_utils.py similarity index 73% rename from Pynetbox_Data_Uploader/Tests/test_csv_utils.py rename to Pynetbox_Data_Uploader/tests/test_csv_utils.py index 54cd1c37..69c0e694 100644 --- a/Pynetbox_Data_Uploader/Tests/test_csv_utils.py +++ b/Pynetbox_Data_Uploader/tests/test_csv_utils.py @@ -1,5 +1,5 @@ -from unittest.mock import MagicMock, NonCallableMock -from CSV.csv_utils import CsvUtils +from unittest.mock import MagicMock, NonCallableMock, patch +from csv_things.csv_utils import CsvUtils import pytest @@ -12,10 +12,9 @@ def test_csv_to_python(instance): """ This test ensures that the csv_read method is called once with the file_path arg. """ - mock_dataframe = MagicMock() file_path = NonCallableMock() - instance.pd = mock_dataframe - instance.csv_to_python(file_path) + with patch("csv_things.csv_utils.pd") as mock_dataframe: + instance.csv_to_python(file_path) mock_dataframe.read_csv.assert_called_once_with(file_path) @@ -27,4 +26,5 @@ def test_separate_data(instance): test_data = {"key1": ["Adata1", "Bdata1"], "key2": ["Adata2", "Bdata2"]} format_data = instance.separate_data(test_data) - assert format_data == [{"key1": "Adata1", "key2": "Adata2"}, {"key1": "Bdata1", "key2": "Bdata2"}] + assert format_data == [{"key1": "Adata1", "key2": "Adata2"}, + {"key1": "Bdata1", "key2": "Bdata2"}] diff --git a/Pynetbox_Data_Uploader/Tests/test_netbox_connect.py b/Pynetbox_Data_Uploader/tests/test_netbox_connect.py similarity index 80% rename from Pynetbox_Data_Uploader/Tests/test_netbox_connect.py rename to Pynetbox_Data_Uploader/tests/test_netbox_connect.py index 993839d1..1c703ccb 100644 --- a/Pynetbox_Data_Uploader/Tests/test_netbox_connect.py +++ b/Pynetbox_Data_Uploader/tests/test_netbox_connect.py @@ -1,5 +1,5 @@ from unittest.mock import NonCallableMock, patch -from Netbox_Api.netbox_connect import NetboxConnect +from netbox_api.netbox_connect import NetboxConnect import pytest @@ -14,7 +14,7 @@ def test_api_object(instance): """ This test checks that the Api method is called once. """ - with patch("Netbox_Api.netbox_connect.nb") as mock_netbox: + with patch("netbox_api.netbox_connect.nb") as mock_netbox: res = instance.api_object() mock_netbox.api.assert_called_once_with(instance.url, instance.token) assert res == mock_netbox.api.return_value diff --git a/Pynetbox_Data_Uploader/Tests/test_netbox_create.py b/Pynetbox_Data_Uploader/tests/test_netbox_create.py similarity index 96% rename from Pynetbox_Data_Uploader/Tests/test_netbox_create.py rename to Pynetbox_Data_Uploader/tests/test_netbox_create.py index fa69d008..e8a19fe5 100644 --- a/Pynetbox_Data_Uploader/Tests/test_netbox_create.py +++ b/Pynetbox_Data_Uploader/tests/test_netbox_create.py @@ -1,5 +1,5 @@ from unittest.mock import MagicMock, NonCallableMock -from Netbox_Api.netbox_create import NetboxDCIM +from netbox_api.netbox_create import NetboxDCIM import pytest diff --git a/Pynetbox_Data_Uploader/Tests/test_netbox_existence.py b/Pynetbox_Data_Uploader/tests/test_netbox_existence.py similarity index 95% rename from Pynetbox_Data_Uploader/Tests/test_netbox_existence.py rename to Pynetbox_Data_Uploader/tests/test_netbox_existence.py index 5dd5aece..4de3c446 100644 --- a/Pynetbox_Data_Uploader/Tests/test_netbox_existence.py +++ b/Pynetbox_Data_Uploader/tests/test_netbox_existence.py @@ -1,5 +1,5 @@ from unittest.mock import MagicMock, NonCallableMock -from Netbox_Api.netbox_existence import NetboxExistence +from netbox_api.netbox_existence import NetboxExistence import pytest From 443eb2d7d2c0e75ed5a4dd89297c5d6718717b19 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 13:52:54 +0100 Subject: [PATCH 09/16] Added import error to .pylintrc --- Pynetbox_Data_Uploader/.pylintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Pynetbox_Data_Uploader/.pylintrc b/Pynetbox_Data_Uploader/.pylintrc index 8593071a..6fa198d4 100644 --- a/Pynetbox_Data_Uploader/.pylintrc +++ b/Pynetbox_Data_Uploader/.pylintrc @@ -9,5 +9,6 @@ max-line-length=120 # W0511: TODOs they're well....to do later # R0801: Similar lines - Imports and method signatures will flag this, such as forwarding action args # C0116: Missing method docstring - Adds too much noise +# E0401: Ignore import errors as imports work -disable=C0114,C0115,E0401,W0511,R0801,C0116 \ No newline at end of file +disable=C0114,C0115,E0401,W0511,R0801,C0116,E0401 \ No newline at end of file From 41f9b744550fdc9b8362bca95cc06fa5fe989f37 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 13:53:12 +0100 Subject: [PATCH 10/16] MAINT: Lint fix --- Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py index 297d5885..8248c332 100644 --- a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py @@ -26,7 +26,7 @@ def __init__(self, url: str, token: str, api: Optional = None): def get_id(self, attr_string: str, netbox_value: str, site_value: str) -> int | str: """ - This method uses the Pynetbox Api .get() method to retrieve the ID of a string value from Netbox. + This method uses Pynetbox Api .get() to retrieve the ID of a string value from Netbox. :param attr_string: The attribute string to get. :param netbox_value: The value to search for in Netbox. :param site_value: The value of the site key in the dictionary From 827140b1e12b9c3b57c1203ed8afa0ad5218ef74 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 14:11:15 +0100 Subject: [PATCH 11/16] Linting Fixes --- .github/workflows/Pynetbox.yaml | 2 +- Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py | 1 + Pynetbox_Data_Uploader/lib/csv_things/format_dict.py | 1 + Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py | 1 + Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py | 1 + .../lib/netbox_api/netbox_connect.py | 1 + .../lib/netbox_api/netbox_create.py | 2 +- Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py | 8 ++++++-- Pynetbox_Data_Uploader/tests/test_csv_utils.py | 11 ++++++----- Pynetbox_Data_Uploader/tests/test_netbox_existence.py | 2 +- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index 4bcb2f4b..de5e4621 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -33,4 +33,4 @@ jobs: - name: Analyse with pylint run: | - pylint Pynetbox_Data_Uploader/lib + pylint --recursive yes test lib diff --git a/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py b/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py index 0cdee35c..df4d0107 100644 --- a/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py +++ b/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py @@ -7,6 +7,7 @@ class CsvUtils: This class provides methods to read data from csv_things files and allow the data to be easily read and used elsewhere. """ + @staticmethod def csv_to_python(file_path: str) -> Dict: """ diff --git a/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py b/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py index e2d327db..f1ac1e24 100644 --- a/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py +++ b/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py @@ -9,6 +9,7 @@ class FormatDict(NetboxConnect): """ This class takes dictionaries with string values and changes those to ID values from Netbox. """ + def __init__(self, dicts: list): """ This method initialises the class with the following parameters. diff --git a/Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py b/Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py index 84624c2c..5877fcf0 100644 --- a/Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py +++ b/Pynetbox_Data_Uploader/lib/enums/dcim_device_id.py @@ -5,6 +5,7 @@ class DeviceInfoID(Enum): """ This Enums Class stores enums that are used to retrieve data from Netbox. """ + DEVICE_ROLE = "dcim.device_roles" DESCRIPTION = "dcim.devices" DEVICE_TYPE = "dcim.device_types" diff --git a/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py b/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py index 95382dd4..21759889 100644 --- a/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py +++ b/Pynetbox_Data_Uploader/lib/enums/dcim_device_no_id.py @@ -5,6 +5,7 @@ class DeviceInfoNoID(Enum): """ This Enums Class stores enums that are used to retrieve data from Netbox. """ + POSITION = "position" NAME = "name" SERIAL = "serial" diff --git a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py index f8091586..5ad46feb 100644 --- a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_connect.py @@ -1,4 +1,5 @@ import pynetbox as nb + # pylint:disable = too-few-public-methods diff --git a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py index d8a95b1a..890b0409 100644 --- a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py @@ -23,7 +23,7 @@ def create_device(self, data: dict | list) -> bool: return bool(devices) def create_device_type( - self, model: str, slug: str, manufacturer: str, u_height=1 + self, model: str, slug: str, manufacturer: str, u_height=1 ) -> bool: """ This method creates a new device type in Netbox. diff --git a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py index 8248c332..c318e780 100644 --- a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_data.py @@ -1,8 +1,9 @@ from operator import attrgetter -from typing import Optional +from typing import Optional, Union from netbox_api.netbox_connect import NetboxConnect from enums.dcim_device_id import DeviceInfoID from enums.dcim_device_no_id import DeviceInfoNoID + # pylint:disable = too-few-public-methods @@ -10,6 +11,7 @@ class NetboxGetID(NetboxConnect): """ This class retrieves field value ID's from Netbox. """ + def __init__(self, url: str, token: str, api: Optional = None): """ This method initialises the class with the following parameters. @@ -24,7 +26,9 @@ def __init__(self, url: str, token: str, api: Optional = None): self.enums_id = DeviceInfoID self.enums_no_id = DeviceInfoNoID - def get_id(self, attr_string: str, netbox_value: str, site_value: str) -> int | str: + def get_id( + self, attr_string: str, netbox_value: str, site_value: str + ) -> Union[int, str]: """ This method uses Pynetbox Api .get() to retrieve the ID of a string value from Netbox. :param attr_string: The attribute string to get. diff --git a/Pynetbox_Data_Uploader/tests/test_csv_utils.py b/Pynetbox_Data_Uploader/tests/test_csv_utils.py index 69c0e694..6d6363c6 100644 --- a/Pynetbox_Data_Uploader/tests/test_csv_utils.py +++ b/Pynetbox_Data_Uploader/tests/test_csv_utils.py @@ -1,4 +1,4 @@ -from unittest.mock import MagicMock, NonCallableMock, patch +from unittest.mock import NonCallableMock, patch from csv_things.csv_utils import CsvUtils import pytest @@ -23,8 +23,9 @@ def test_separate_data(instance): This test ensures that the dictionaries from panda formatted into row by row dictionaries. These are much more understandable and can be used individually or in bulk. """ - test_data = {"key1": ["Adata1", "Bdata1"], - "key2": ["Adata2", "Bdata2"]} + test_data = {"key1": ["Adata1", "Bdata1"], "key2": ["Adata2", "Bdata2"]} format_data = instance.separate_data(test_data) - assert format_data == [{"key1": "Adata1", "key2": "Adata2"}, - {"key1": "Bdata1", "key2": "Bdata2"}] + assert format_data == [ + {"key1": "Adata1", "key2": "Adata2"}, + {"key1": "Bdata1", "key2": "Bdata2"}, + ] diff --git a/Pynetbox_Data_Uploader/tests/test_netbox_existence.py b/Pynetbox_Data_Uploader/tests/test_netbox_existence.py index 4de3c446..b59fed17 100644 --- a/Pynetbox_Data_Uploader/tests/test_netbox_existence.py +++ b/Pynetbox_Data_Uploader/tests/test_netbox_existence.py @@ -34,4 +34,4 @@ def test_check_device_type_exists(instance): device_type = NonCallableMock() instance.netbox.dcim.device_types = mock_device_types instance.check_device_type_exists(device_type) - mock_device_types.get.assert_called_once_with(slug=device_type) \ No newline at end of file + mock_device_types.get.assert_called_once_with(slug=device_type) From 6656bb92e0ddc450f6c7ed016e652dad13c18ef0 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 14:44:00 +0100 Subject: [PATCH 12/16] Changed Pylint run command in workflow. --- .github/workflows/Pynetbox.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index de5e4621..5e90c641 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -33,4 +33,5 @@ jobs: - name: Analyse with pylint run: | - pylint --recursive yes test lib + pylint $(git ls-files '*.py') + From db067057037c44307b1f75461710e300618c0af7 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 14:55:23 +0100 Subject: [PATCH 13/16] Changed pylint to run with pylintrc path --- .github/workflows/Pynetbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Pynetbox.yaml b/.github/workflows/Pynetbox.yaml index 5e90c641..84f45a5d 100644 --- a/.github/workflows/Pynetbox.yaml +++ b/.github/workflows/Pynetbox.yaml @@ -33,5 +33,5 @@ jobs: - name: Analyse with pylint run: | - pylint $(git ls-files '*.py') + cd Pynetbox_Data_Uploader && pylint $(git ls-files '*.py') --rcfile=.pylintrc From ee1c1b2bee34f5161d5ecf2739d398aa6edfc09f Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 12 Oct 2023 15:33:37 +0100 Subject: [PATCH 14/16] Removed DataFiles from gitignore. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8d0d9e54..ac7b7a49 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ venv/ .coverage coverage.xml -Pynetbox_Data_Uploader/DataFiles \ No newline at end of file From 5e197d1af188ccfb09808045624ba8ad659ff670 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Fri, 13 Oct 2023 12:55:09 +0100 Subject: [PATCH 15/16] Rename csv_things and csv_utils --- .../lib/{csv_things => netbox_api}/format_dict.py | 0 .../lib/{csv_things => utils}/__init__.py | 0 .../{csv_things/csv_utils.py => utils/csv_to_dict.py} | 10 +++++----- Pynetbox_Data_Uploader/tests/test_csv_utils.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename Pynetbox_Data_Uploader/lib/{csv_things => netbox_api}/format_dict.py (100%) rename Pynetbox_Data_Uploader/lib/{csv_things => utils}/__init__.py (100%) rename Pynetbox_Data_Uploader/lib/{csv_things/csv_utils.py => utils/csv_to_dict.py} (74%) diff --git a/Pynetbox_Data_Uploader/lib/csv_things/format_dict.py b/Pynetbox_Data_Uploader/lib/netbox_api/format_dict.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/csv_things/format_dict.py rename to Pynetbox_Data_Uploader/lib/netbox_api/format_dict.py diff --git a/Pynetbox_Data_Uploader/lib/csv_things/__init__.py b/Pynetbox_Data_Uploader/lib/utils/__init__.py similarity index 100% rename from Pynetbox_Data_Uploader/lib/csv_things/__init__.py rename to Pynetbox_Data_Uploader/lib/utils/__init__.py diff --git a/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py b/Pynetbox_Data_Uploader/lib/utils/csv_to_dict.py similarity index 74% rename from Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py rename to Pynetbox_Data_Uploader/lib/utils/csv_to_dict.py index df4d0107..1cbd41c3 100644 --- a/Pynetbox_Data_Uploader/lib/csv_things/csv_utils.py +++ b/Pynetbox_Data_Uploader/lib/utils/csv_to_dict.py @@ -4,7 +4,7 @@ class CsvUtils: """ - This class provides methods to read data from csv_things files + This class provides methods to read data from csv files and allow the data to be easily read and used elsewhere. """ @@ -12,7 +12,7 @@ class CsvUtils: def csv_to_python(file_path: str) -> Dict: """ This method reads data from csv files and writes them to a dictionary. - :param file_path: The file path of the csv_things file to be read from. + :param file_path: The file path of the utils file to be read from. :return: Returns the data from the csv as a dictionary. """ dataframe = pd.read_csv(file_path) @@ -22,9 +22,9 @@ def csv_to_python(file_path: str) -> Dict: @staticmethod def separate_data(data: dict) -> List: """ - This method reduces Pandas csv_things to Dict conversion to individual dictionaries. - :param data: The data from the csv_things file - :return: Returns a list of dictionaries which each represent a row of data from csv_things. + This method reduces Pandas utils to Dict conversion to individual dictionaries. + :param data: The data from the utils file + :return: Returns a list of dictionaries which each represent a row of data from utils. """ data_keys = list(data.keys()) len_rows = len(data[data_keys[0]]) diff --git a/Pynetbox_Data_Uploader/tests/test_csv_utils.py b/Pynetbox_Data_Uploader/tests/test_csv_utils.py index 6d6363c6..9605e6a2 100644 --- a/Pynetbox_Data_Uploader/tests/test_csv_utils.py +++ b/Pynetbox_Data_Uploader/tests/test_csv_utils.py @@ -1,5 +1,5 @@ from unittest.mock import NonCallableMock, patch -from csv_things.csv_utils import CsvUtils +from utils.csv_to_dict import CsvUtils import pytest @@ -13,7 +13,7 @@ def test_csv_to_python(instance): This test ensures that the csv_read method is called once with the file_path arg. """ file_path = NonCallableMock() - with patch("csv_things.csv_utils.pd") as mock_dataframe: + with patch("utils.csv_utils.pd") as mock_dataframe: instance.csv_to_python(file_path) mock_dataframe.read_csv.assert_called_once_with(file_path) From 2548d9f9423d9e393e7224f7b551bec22d653ab2 Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Fri, 13 Oct 2023 13:00:56 +0100 Subject: [PATCH 16/16] MAINT: Type hint for u_height in netbox_create --- Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py index 890b0409..fea180a8 100644 --- a/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py +++ b/Pynetbox_Data_Uploader/lib/netbox_api/netbox_create.py @@ -23,7 +23,7 @@ def create_device(self, data: dict | list) -> bool: return bool(devices) def create_device_type( - self, model: str, slug: str, manufacturer: str, u_height=1 + self, model: str, slug: str, manufacturer: str, u_height: int = 1 ) -> bool: """ This method creates a new device type in Netbox.