Skip to content

Commit

Permalink
Merge pull request #41 from kpetremann/ruff
Browse files Browse the repository at this point in the history
ci: ruff and isort
  • Loading branch information
kpetremann authored Aug 19, 2024
2 parents ff7dd82 + 9143f54 commit 1db65c4
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 71 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
pip install black isort ruff
- name: Check black formatting
run: |
black . --check
- name: Lint with Ruff
run: ruff check .

- name: Lint with Black
run: black . --check --diff

- name: Lint with isort
run: isort . --check --diff

- name: Run tests in containers
run: |
Expand Down
2 changes: 0 additions & 2 deletions netbox_cmdb/netbox_cmdb/api/cmdb/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.db import transaction
from django.db.models import Q
from drf_yasg import openapi
from drf_yasg.openapi import Parameter
from drf_yasg.utils import swagger_auto_schema
from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired
from rest_framework import serializers, status
Expand Down
2 changes: 0 additions & 2 deletions netbox_cmdb/netbox_cmdb/api/snmp/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Route Policy views."""

from rest_framework.response import Response

from netbox_cmdb import filtersets
from netbox_cmdb.api.snmp.serializers import (
SNMPCommunitySerializer,
Expand Down
2 changes: 0 additions & 2 deletions netbox_cmdb/netbox_cmdb/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Forms."""

from typing import Any, Sequence

from dcim.models import Device
from dcim.models.devices import DeviceType
from dcim.models.sites import SiteGroup
Expand Down
2 changes: 1 addition & 1 deletion netbox_cmdb/netbox_cmdb/models/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_available_asns(self, min_asn, max_asn):
"""
Return all available ASNs in a given range.
"""
available_asns = {asn for asn in range(min_asn, max_asn + 1)}
available_asns = set(range(min_asn, max_asn + 1))
available_asns -= set(self.__class__.objects.all().values_list("number", flat=True))

return sorted(available_asns)
Expand Down
1 change: 0 additions & 1 deletion netbox_cmdb/netbox_cmdb/models/prefix_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from ipam.fields import IPNetworkField
from netbox.models import ChangeLoggedModel
from utilities.choices import ChoiceSet
Expand Down
2 changes: 0 additions & 2 deletions netbox_cmdb/netbox_cmdb/models/snmp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.db import models
from netbox.models import ChangeLoggedModel

Expand Down
30 changes: 15 additions & 15 deletions netbox_cmdb/netbox_cmdb/tests/bgp/test_bgp_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_create(self):
"ecmp_maximum_paths": 128,
}
bgp_global_serializer = BGPGlobalSerializer(data=data)
assert bgp_global_serializer.is_valid() == True
assert bgp_global_serializer.is_valid() is True
bgp_global_serializer.save()

global_conf = BGPGlobal.objects.get(device__name="router-test1")
Expand All @@ -64,9 +64,9 @@ def test_create(self):
assert global_conf.local_asn_id == 5
assert global_conf.ebgp_administrative_distance == 20
assert global_conf.ibgp_administrative_distance == 170
assert global_conf.graceful_restart == True
assert global_conf.graceful_restart is True
assert global_conf.graceful_restart_time == 240
assert global_conf.ecmp == True
assert global_conf.ecmp is True
assert global_conf.ecmp_maximum_paths == 128


Expand Down Expand Up @@ -98,7 +98,7 @@ def test_already_existing(self):
"ecmp_maximum_paths": 128,
}
bgp_global_serializer = BGPGlobalSerializer(data=data)
assert bgp_global_serializer.is_valid() == True
assert bgp_global_serializer.is_valid() is True
self.assertRaises(IntegrityError, bgp_global_serializer.save)

def test_update(self):
Expand All @@ -114,7 +114,7 @@ def test_update(self):
"ecmp_maximum_paths": 128,
}
bgp_global_serializer = BGPGlobalSerializer(instance=self.global_conf1, data=data)
assert bgp_global_serializer.is_valid() == True
assert bgp_global_serializer.is_valid() is True
bgp_global_serializer.save()

global_conf = BGPGlobal.objects.get(device__name="router-test1")
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_bgp_session_creation(self):
}

bgp_session_serializer = BGPSessionSerializer(data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

bgp_session_got = BGPSession.objects.get(
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_bgp_session_add__existing_session(self):
"password": "1234",
}
bgp_session_serializer = BGPSessionSerializer(data=data)
assert bgp_session_serializer.is_valid() == False
assert bgp_session_serializer.is_valid() is False
assert bgp_session_serializer.errors["errors"][0] == ErrorDetail(
string="[ErrorDetail(string='A BGP session already exists between these 2 devices and IP addresses.', code='invalid')]",
code="invalid",
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_bgp_session_update__state_and_password(self):
}

bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

bgp_session_got = BGPSession.objects.get(id=self.bgp_session.pk)
Expand Down Expand Up @@ -345,14 +345,14 @@ def test_bgp_session_update__modify_peer(self):
"password": "1234",
}
bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

bgp_session_got = BGPSession.objects.get(id=self.bgp_session.pk)
assert bgp_session_got.peer_a.description == "peer_a"
assert bgp_session_got.peer_a.maximum_prefixes == 50000
assert bgp_session_got.peer_a.enabled is False
assert bgp_session_got.peer_a.enforce_first_as == False
assert bgp_session_got.peer_a.enforce_first_as is False
assert bgp_session_got.peer_b.description == "peer_b"
assert bgp_session_got.peer_b.enabled is True

Expand All @@ -373,7 +373,7 @@ def test_bgp_session_update__patch_peer_a_route_policy(self):
},
}
bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

bgp_session_got = BGPSession.objects.get(id=self.bgp_session.pk)
Expand All @@ -383,11 +383,11 @@ def test_bgp_session_update__patch_peer_a_route_policy(self):
data["peer_a"]["route_policy_out"] = None

bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

bgp_session_got = BGPSession.objects.get(id=self.bgp_session.pk)
assert bgp_session_got.peer_a.route_policy_out == None
assert bgp_session_got.peer_a.route_policy_out is None

def test_bgp_session_update__add_afisafi(self):
"""Adding ipv4-unicast afisafi to an existing session"""
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_bgp_session_update__add_afisafi(self):
}

bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

def test_bgp_session_update__replace_afisafi(self):
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_bgp_session_update__replace_afisafi(self):
}

bgp_session_serializer = BGPSessionSerializer(instance=self.bgp_session, data=data)
assert bgp_session_serializer.is_valid() == True
assert bgp_session_serializer.is_valid() is True
bgp_session_serializer.save()

# check in database that the object has been modified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_bgp_community_list_creation(self):
}

bgp_com_list_serializer = BGPCommunityListSerializer(data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True

def test_bgp_community_list_creation_with_empty_terms(self):
data = {
Expand All @@ -76,7 +76,7 @@ def test_bgp_community_list_creation_with_empty_terms(self):
}

bgp_com_list_serializer = BGPCommunityListSerializer(data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True

with self.assertRaisesRegex(
ValidationError,
Expand All @@ -91,7 +91,7 @@ def test_bgp_community_list_creation_without_terms(self):
}

bgp_com_list_serializer = BGPCommunityListSerializer(data=data)
assert bgp_com_list_serializer.is_valid() == False
assert bgp_com_list_serializer.is_valid() is False


class BGPCommunityListSerializerUpdate(BaseTestCase):
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_bgp_community_list_update_add_term(self):
],
}
bgp_com_list_serializer = BGPCommunityListSerializer(instance=self.prefix_list, data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True
bgp_com_list_serializer.save()
validate(self.device, data)

Expand All @@ -152,7 +152,7 @@ def test_bgp_community_list_update_remove_term(self):
],
}
bgp_com_list_serializer = BGPCommunityListSerializer(instance=self.prefix_list, data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True
bgp_com_list_serializer.save()
validate(self.device, data)

Expand All @@ -172,7 +172,7 @@ def test_bgp_community_list_update_replace_terms(self):
],
}
bgp_com_list_serializer = BGPCommunityListSerializer(instance=self.prefix_list, data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True
bgp_com_list_serializer.save()
validate(self.device, data)

Expand All @@ -193,7 +193,7 @@ def test_bgp_community_list_update_attr_term(self):
],
}
bgp_com_list_serializer = BGPCommunityListSerializer(instance=self.prefix_list, data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True
bgp_com_list_serializer.save()
validate(self.device, data)

Expand All @@ -204,7 +204,7 @@ def test_bgp_community_list_update_no_terms(self):
"terms": [],
}
bgp_com_list_serializer = BGPCommunityListSerializer(instance=self.prefix_list, data=data)
assert bgp_com_list_serializer.is_valid() == True
assert bgp_com_list_serializer.is_valid() is True

with self.assertRaisesRegex(
ValidationError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_prefix_list_creation(self):
}

pf_serializer = PrefixListSerializer(data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True

def test_prefix_list_creation_with_empty_terms(self):
data = {
Expand All @@ -80,7 +80,7 @@ def test_prefix_list_creation_with_empty_terms(self):
}

pf_serializer = PrefixListSerializer(data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True

with self.assertRaisesRegex(
ValidationError,
Expand All @@ -96,7 +96,7 @@ def test_prefix_list_creation_without_terms(self):
}

pf_serializer = PrefixListSerializer(data=data)
assert pf_serializer.is_valid() == False
assert pf_serializer.is_valid() is False


class PrefixListSerializerUpdate(BaseTestCase):
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_prefix_list_update_add_term(self):
],
}
pf_serializer = PrefixListSerializer(instance=self.prefix_list, data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True
pf_serializer.save()
validate(self.device, data)

Expand All @@ -161,7 +161,7 @@ def test_prefix_list_update_remove_term(self):
],
}
pf_serializer = PrefixListSerializer(instance=self.prefix_list, data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True
pf_serializer.save()
validate(self.device, data)

Expand All @@ -184,7 +184,7 @@ def test_prefix_list_update_replace_terms(self):
],
}
pf_serializer = PrefixListSerializer(instance=self.prefix_list, data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True
pf_serializer.save()
validate(self.device, data)

Expand All @@ -206,7 +206,7 @@ def test_prefix_list_update_attr_term(self):
],
}
pf_serializer = PrefixListSerializer(instance=self.prefix_list, data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True
pf_serializer.save()
validate(self.device, data)

Expand All @@ -218,7 +218,7 @@ def test_prefix_list_update_no_terms(self):
"terms": [],
}
pf_serializer = PrefixListSerializer(instance=self.prefix_list, data=data)
assert pf_serializer.is_valid() == True
assert pf_serializer.is_valid() is True

with self.assertRaisesRegex(
ValidationError,
Expand Down
Loading

0 comments on commit 1db65c4

Please sign in to comment.