Skip to content

Commit

Permalink
Closes #187: Mock external APIs, softwares and e-mails
Browse files Browse the repository at this point in the history
* Mock PeeringDB API GET requests
* Mock bgpq3 subprocess call
* Python 3.8 being released test the code against it
* Mock NetBox API responses
* Test PeeringDB database synchronization
* Fix e-mail sending form
* Test e-mail form and view
* Test template views
  • Loading branch information
gmazoyer committed Dec 8, 2019
1 parent fd4af9d commit 657533d
Show file tree
Hide file tree
Showing 32 changed files with 1,125 additions and 107 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ language: python
python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
matrix:
include:
- python: "3.6"
env: TOXENV=black
- python: "3.7"
dist: "xenial"
sudo: true
before_install:
- git clone https://github.com/snar/bgpq3.git
- cd bgpq3 && ./configure && make && sudo make install
install:
- pip install tox tox-travis coveralls
before_script:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Questions? Comments? Join us in the #peering-manager Slack channel on
## Requirements

This tool is written with the
[Django framework](https://www.djangoproject.com/) and requires Python with
[Django framework](https://www.djangoproject.com/) and requires Python 3 with
some dependencies to run. For a complete list of requirements, see
`requirements.txt`.

It is built against Python 3 versions. Tested versions are 3.5, 3.6 and 3.7.
Tested Python versions are 3.5, 3.6, 3.7 and 3.8.

The best way to start setting up this tool is to use **pip** within a
**virtualenv**.
Expand Down
10 changes: 1 addition & 9 deletions netbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from django.conf import settings


NAMESPACES = {"dcim": "dcim"}


class NetBox(object):
"""
Class used to interact with the NetBox API.
Expand All @@ -30,12 +27,7 @@ def get_devices(self):
self.logger.debug(
"calling dcim.devices.filter: role=%s", settings.NETBOX_DEVICE_ROLES
)
result = self.api.dcim.devices.filter(role=settings.NETBOX_DEVICE_ROLES)

if not result:
return None

return result
return self.api.dcim.devices.filter(role=settings.NETBOX_DEVICE_ROLES)

def napalm(self, device_id, method):
"""
Expand Down
5 changes: 0 additions & 5 deletions netbox/tests.py

This file was deleted.

Empty file added netbox/tests/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions netbox/tests/fixtures/device.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"id": 1,
"name": "router01.example.net",
"display_name": "router01.example.net",
"device_type": {
"id": 1,
"url": "http://netbox.example.net/api/dcim/device-types/1/",
"manufacturer": {
"id": 5,
"url": "http://netbox.example.net/api/dcim/manufacturers/5/",
"name": "Juniper",
"slug": "juniper"
},
"model": "SRX300",
"slug": "srx300",
"display_name": "Juniper SRX300"
},
"device_role": {
"id": 7,
"url": "http://netbox.example.net/api/dcim/device-roles/7/",
"name": "Router",
"slug": "router"
},
"tenant": {
"id": 1,
"url": "http://netbox.example.net/api/tenancy/tenants/1/",
"name": "example.net",
"slug": "example-net"
},
"platform": {
"id": 3,
"url": "http://netbox.example.net/api/dcim/platforms/3/",
"name": "Juniper Junos",
"slug": "juniper-junos"
},
"serial": "CV3216AF0132",
"asset_tag": null,
"site": {
"id": 4,
"url": "http://netbox.example.net/api/dcim/sites/4/",
"name": "Metz",
"slug": "metz"
},
"rack": {
"id": 1,
"url": "http://netbox.example.net/api/dcim/racks/1/",
"name": "RACK-001",
"display_name": "RACK-001"
},
"position": 9,
"face": {
"value": 0,
"label": "Front"
},
"parent_device": null,
"status": {
"value": 1,
"label": "Active"
},
"primary_ip": {
"id": 7,
"url": "http://netbox.example.net/api/ipam/ip-addresses/7/",
"family": 6,
"address": "2001:678:794::2/128"
},
"primary_ip4": {
"id": 265,
"url": "http://netbox.example.net/api/ipam/ip-addresses/265/",
"family": 4,
"address": "45.154.62.2/32"
},
"primary_ip6": {
"id": 7,
"url": "http://netbox.example.net/api/ipam/ip-addresses/7/",
"family": 6,
"address": "2001:db8::2/128"
},
"cluster": null,
"virtual_chassis": null,
"vc_position": null,
"vc_priority": null,
"comments": "",
"local_context_data": null,
"tags": [],
"custom_fields": {},
"config_context": {},
"created": "2016-12-16",
"last_updated": "2019-11-01T16:25:55.481312+01:00"
}
42 changes: 42 additions & 0 deletions netbox/tests/fixtures/device_facts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"vendor": "Juniper",
"model": "SRX300",
"serial_number": "CV3216AF0132",
"os_version": "15.1X49-D170.4",
"hostname": "router01",
"fqdn": "router01.example.net",
"uptime": 4082036,
"interface_list": [
"ge-0/0/0",
"gr-0/0/0",
"ip-0/0/0",
"lsq-0/0/0",
"lt-0/0/0",
"mt-0/0/0",
"sp-0/0/0",
"ge-0/0/1",
"ge-0/0/2",
"ge-0/0/3",
"ge-0/0/4",
"ge-0/0/5",
"ge-0/0/6",
"ge-0/0/7",
"ae0",
"gre",
"ipip",
"irb",
"jsrv",
"lo0",
"lsi",
"mtun",
"pimd",
"pime",
"pp0",
"ppd0",
"ppe0",
"st0",
"tap",
"vlan",
"vtep"
]
}
185 changes: 185 additions & 0 deletions netbox/tests/fixtures/devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"name": "router01.example.net",
"display_name": "router01.example.net",
"device_type": {
"id": 1,
"url": "http://netbox.example.net/api/dcim/device-types/1/",
"manufacturer": {
"id": 5,
"url": "http://netbox.example.net/api/dcim/manufacturers/5/",
"name": "Juniper",
"slug": "juniper"
},
"model": "SRX300",
"slug": "srx300",
"display_name": "Juniper SRX300"
},
"device_role": {
"id": 7,
"url": "http://netbox.example.net/api/dcim/device-roles/7/",
"name": "Router",
"slug": "router"
},
"tenant": {
"id": 1,
"url": "http://netbox.example.net/api/tenancy/tenants/1/",
"name": "example.net",
"slug": "example-net"
},
"platform": {
"id": 3,
"url": "http://netbox.example.net/api/dcim/platforms/3/",
"name": "Juniper Junos",
"slug": "juniper-junos"
},
"serial": "CV3216AF0132",
"asset_tag": null,
"site": {
"id": 4,
"url": "http://netbox.example.net/api/dcim/sites/4/",
"name": "Metz",
"slug": "metz"
},
"rack": {
"id": 1,
"url": "http://netbox.example.net/api/dcim/racks/1/",
"name": "RACK-001",
"display_name": "RACK-001"
},
"position": 9,
"face": {
"value": 0,
"label": "Front"
},
"parent_device": null,
"status": {
"value": 1,
"label": "Active"
},
"primary_ip": {
"id": 7,
"url": "http://netbox.example.net/api/ipam/ip-addresses/7/",
"family": 6,
"address": "2001:678:794::2/128"
},
"primary_ip4": {
"id": 265,
"url": "http://netbox.example.net/api/ipam/ip-addresses/265/",
"family": 4,
"address": "45.154.62.2/32"
},
"primary_ip6": {
"id": 7,
"url": "http://netbox.example.net/api/ipam/ip-addresses/7/",
"family": 6,
"address": "2001:db8::2/128"
},
"cluster": null,
"virtual_chassis": null,
"vc_position": null,
"vc_priority": null,
"comments": "",
"local_context_data": null,
"tags": [],
"custom_fields": {},
"config_context": {},
"created": "2016-12-16",
"last_updated": "2019-11-01T16:25:55.481312+01:00"
},
{
"id": 14,
"name": "router02.example.net",
"display_name": "router02.example.net",
"device_type": {
"id": 18,
"url": "http://netbox.example.net/api/dcim/device-types/18/",
"manufacturer": {
"id": 5,
"url": "http://netbox.example.net/api/dcim/manufacturers/5/",
"name": "Juniper",
"slug": "juniper"
},
"model": "SRX320",
"slug": "srx320",
"display_name": "Juniper SRX320"
},
"device_role": {
"id": 7,
"url": "http://netbox.example.net/api/dcim/device-roles/7/",
"name": "Router",
"slug": "router"
},
"tenant": {
"id": 1,
"url": "http://netbox.example.net/api/tenancy/tenants/1/",
"name": "example.net",
"slug": "example-net"
},
"platform": {
"id": 3,
"url": "http://netbox.example.net/api/dcim/platforms/3/",
"name": "Juniper Junos",
"slug": "juniper-junos"
},
"serial": "CW2516AF0387",
"asset_tag": null,
"site": {
"id": 3,
"url": "http://netbox.example.net/api/dcim/sites/3/",
"name": "Bettembourg",
"slug": "bettembourg"
},
"rack": {
"id": 3,
"url": "http://netbox.example.net/api/dcim/racks/3/",
"name": "RACK-002",
"display_name": "RACK-002"
},
"position": 13,
"face": {
"value": 0,
"label": "Front"
},
"parent_device": null,
"status": {
"value": 1,
"label": "Active"
},
"primary_ip": {
"id": 178,
"url": "http://netbox.example.net/api/ipam/ip-addresses/178/",
"family": 6,
"address": "2001:678:794::1/128"
},
"primary_ip4": {
"id": 270,
"url": "http://netbox.example.net/api/ipam/ip-addresses/270/",
"family": 4,
"address": "45.154.62.1/32"
},
"primary_ip6": {
"id": 178,
"url": "http://netbox.example.net/api/ipam/ip-addresses/178/",
"family": 6,
"address": "2001:db8::1/128"
},
"cluster": null,
"virtual_chassis": null,
"vc_position": null,
"vc_priority": null,
"comments": "",
"local_context_data": null,
"tags": [],
"custom_fields": {},
"config_context": {},
"created": "2018-07-18",
"last_updated": "2019-11-01T16:26:45.768360+01:00"
}
]
}

0 comments on commit 657533d

Please sign in to comment.