-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from stfc/more_missing_tests
Written more format_dict tests. Renamed a file.
- Loading branch information
Showing
16 changed files
with
653 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.