Skip to content

Commit

Permalink
Merge pull request #114 from stfc/more_missing_tests
Browse files Browse the repository at this point in the history
Written more format_dict tests. Renamed a file.
  • Loading branch information
khalford authored Oct 30, 2023
2 parents 1a5908a + 7730ba2 commit f2d148d
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 617 deletions.
87 changes: 44 additions & 43 deletions .github/workflows/pynetbox.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
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.8", "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
cd pynetbox_data_uploader
pip install -r requirements.txt
- name: Analyse with pylint
run: cd pynetbox_data_uploader && pylint . --rcfile=.pylintrc

- name: Run tests and collect coverage
run: cd pynetbox_data_uploader && python3 -m pytest --cov-report xml:coverage.xml --cov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./pynetbox_data_uploader/coverage.xml

name: Pynetbox Data Uploader Tests

on:
push:
branches:
- master
pull_request:
paths:
- "pynetbox_data_uploader/**"
- ".github/workflows/pynetbox.yaml"

jobs:
lint_test_codecov:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.8", "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
cd pynetbox_data_uploader
pip install -r requirements.txt
- name: Analyse with pylint
run: cd pynetbox_data_uploader && pylint . --rcfile=.pylintrc

- name: Run tests and collect coverage
run: cd pynetbox_data_uploader && python3 -m pytest --cov-report xml:coverage.xml --cov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
files: ./pynetbox_data_uploader/coverage.xml

18 changes: 9 additions & 9 deletions pynetbox_data_uploader/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[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
# W0511: TODOs they're well....to do later

[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
# W0511: TODOs they're well....to do later

disable=C0114,W0511
32 changes: 16 additions & 16 deletions pynetbox_data_uploader/lib/enums/dcim_device_id.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from enum import Enum


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"
RACK = "dcim.racks"
LOCATION = "dcim.locations"
TENANT = "tenancy.tenants"
SITE = "dcim.sites"
MANUFACTURER = "dcim.manufacturers"
from enum import Enum


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"
RACK = "dcim.racks"
LOCATION = "dcim.locations"
TENANT = "tenancy.tenants"
SITE = "dcim.sites"
MANUFACTURER = "dcim.manufacturers"
28 changes: 14 additions & 14 deletions pynetbox_data_uploader/lib/enums/dcim_device_no_id.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from enum import Enum


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"
from enum import Enum


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"
50 changes: 25 additions & 25 deletions pynetbox_data_uploader/lib/netbox_api/netbox_check.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
class NetboxCheck:
"""
This class contains methods that check if an object exists in Netbox.
"""

def __init__(self, api):
self.netbox = api

def check_device_exists(self, device_name: str) -> bool:
"""
This method will check if a device exists in Netbox.
:param device_name: The name of the device.
:return: Returns bool.
"""
device = self.netbox.dcim.devices.get(name=device_name)
return bool(device)

def check_device_type_exists(self, device_type: str) -> bool:
"""
This method will check if a device exists in Netbox.
:param device_type: The name of the device.
:return: Returns bool.
"""
device_type = self.netbox.dcim.device_types.get(slug=device_type)
return bool(device_type)
class NetboxCheck:
"""
This class contains methods that check if an object exists in Netbox.
"""

def __init__(self, api):
self.netbox = api

def check_device_exists(self, device_name: str) -> bool:
"""
This method will check if a device exists in Netbox.
:param device_name: The name of the device.
:return: Returns bool.
"""
device = self.netbox.dcim.devices.get(name=device_name)
return bool(device)

def check_device_type_exists(self, device_type: str) -> bool:
"""
This method will check if a device exists in Netbox.
:param device_type: The name of the device.
:return: Returns bool.
"""
device_type = self.netbox.dcim.device_types.get(slug=device_type)
return bool(device_type)
50 changes: 25 additions & 25 deletions pynetbox_data_uploader/lib/netbox_api/netbox_connect.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import pynetbox as nb

# pylint:disable = too-few-public-methods


class NetboxConnect:
"""
This class is used to provide the Pynetbox Api object to other classes.
"""

def __init__(self, url: str, token: str):
"""
This method initialises NetboxConnect with URL and token
:param url: Netbox website URL.
:param token: Netbox authentication token.
"""
self.url = url
self.token = token

def api_object(self):
"""
This method returns the Pynetbox Api object.
:return: Returns the Api object
"""
return nb.api(self.url, self.token)
import pynetbox as nb

# pylint:disable = too-few-public-methods


class NetboxConnect:
"""
This class is used to provide the Pynetbox Api object to other classes.
"""

def __init__(self, url: str, token: str):
"""
This method initialises NetboxConnect with URL and token
:param url: Netbox website URL.
:param token: Netbox authentication token.
"""
self.url = url
self.token = token

def api_object(self):
"""
This method returns the Pynetbox Api object.
:return: Returns the Api object
"""
return nb.api(self.url, self.token)
78 changes: 39 additions & 39 deletions pynetbox_data_uploader/lib/netbox_api/netbox_create.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
from typing import Union, Dict, List


class NetboxCreate:
"""
This class contains methods that will interact create objects in Netbox.
"""

def __init__(self, api):
"""
This initialises the method with the api object.
:param api:
"""
self.netbox = api

def create_device(self, data: Union[Dict, List]) -> bool:
"""
This method uses the pynetbox Api to create a device in Netbox.
:param data: A list of or a single dictionary.
:return: Returns bool.
"""
devices = self.netbox.dcim.devices.create(data)
return bool(devices)

def create_device_type(
self, model: str, slug: str, manufacturer: str, u_height: int = 0
) -> bool:
"""
This method creates a new device type in Netbox.
:param model: The model name of the device.
:param slug: The URL friendly version of the model name.
:param manufacturer: The manufacturer of the device.
:param u_height: This is the height of the device in the rack. Default 0.
:return: Returns bool.
"""
device_type = self.netbox.dcim.device_types.create(
model=model, slug=slug, manufacturer=manufacturer, u_height=u_height
)
return bool(device_type)
from typing import Union, Dict, List


class NetboxCreate:
"""
This class contains methods that will interact create objects in Netbox.
"""

def __init__(self, api):
"""
This initialises the method with the api object.
:param api:
"""
self.netbox = api

def create_device(self, data: Union[Dict, List]) -> bool:
"""
This method uses the pynetbox Api to create a device in Netbox.
:param data: A list of or a single dictionary.
:return: Returns bool.
"""
devices = self.netbox.dcim.devices.create(data)
return bool(devices)

def create_device_type(
self, model: str, slug: str, manufacturer: str, u_height: int = 0
) -> bool:
"""
This method creates a new device type in Netbox.
:param model: The model name of the device.
:param slug: The URL friendly version of the model name.
:param manufacturer: The manufacturer of the device.
:param u_height: This is the height of the device in the rack. Default 0.
:return: Returns bool.
"""
device_type = self.netbox.dcim.device_types.create(
model=model, slug=slug, manufacturer=manufacturer, u_height=u_height
)
return bool(device_type)
Loading

0 comments on commit f2d148d

Please sign in to comment.