mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-13 16:47:34 -06:00
Closes #17951: Extend Ruff ruleset
This commit is contained in:
parent
812ce8471a
commit
a183048891
@ -21,6 +21,7 @@ def copy_site_assignments(apps, schema_editor):
|
||||
termination_id=models.F('provider_network_id')
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
|
@ -341,7 +341,7 @@ class ProviderNetworkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
}
|
||||
|
||||
|
||||
class TestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
class TestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
model = CircuitTermination
|
||||
|
||||
@classmethod
|
||||
|
@ -223,7 +223,7 @@ class EventRuleImportForm(NetBoxModelImportForm):
|
||||
from extras.scripts import get_module_and_script
|
||||
module_name, script_name = action_object.split('.', 1)
|
||||
try:
|
||||
module, script = get_module_and_script(module_name, script_name)
|
||||
script = get_module_and_script(module_name, script_name)[1]
|
||||
except ObjectDoesNotExist:
|
||||
raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
|
||||
self.instance.action_object = script
|
||||
|
@ -38,7 +38,7 @@ class Command(BaseCommand):
|
||||
data = {}
|
||||
|
||||
module_name, script_name = script.split('.', 1)
|
||||
module, script_obj = get_module_and_script(module_name, script_name)
|
||||
script_obj = get_module_and_script(module_name, script_name)[1]
|
||||
script = script_obj.python_class
|
||||
|
||||
# Take user from command line if provided and exists, other
|
||||
|
@ -30,7 +30,7 @@ def get_python_name(scriptmodule):
|
||||
"""
|
||||
Return the Python name of a ScriptModule's file on disk.
|
||||
"""
|
||||
path, filename = os.path.split(scriptmodule.file_path)
|
||||
filename = os.path.split(scriptmodule.file_path)[0]
|
||||
return os.path.splitext(filename)[0]
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ def update_event_rules(apps, schema_editor):
|
||||
|
||||
for eventrule in EventRule.objects.filter(action_object_type=scriptmodule_ct):
|
||||
name = eventrule.action_parameters.get('script_name')
|
||||
obj, created = Script.objects.get_or_create(
|
||||
obj, __ = Script.objects.get_or_create(
|
||||
module_id=eventrule.action_object_id,
|
||||
name=name,
|
||||
defaults={'is_executable': False}
|
||||
|
@ -108,8 +108,8 @@ class NetIn(Lookup):
|
||||
return self.rhs
|
||||
|
||||
def as_sql(self, qn, connection):
|
||||
lhs, lhs_params = self.process_lhs(qn, connection)
|
||||
rhs, rhs_params = self.process_rhs(qn, connection)
|
||||
lhs = self.process_lhs(qn, connection)[0]
|
||||
rhs_params = self.process_rhs(qn, connection)[1]
|
||||
with_mask, without_mask = [], []
|
||||
for address in rhs_params[0]:
|
||||
if '/' in address:
|
||||
|
@ -42,7 +42,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
|
||||
"""
|
||||
This is a very basic test, which tests both prefixes without VRFs and prefixes with VRFs
|
||||
"""
|
||||
vrf1, vrf2, vrf3 = list(VRF.objects.all())
|
||||
vrf1, vrf2 = VRF.objects.all()[:2]
|
||||
prefixes = (
|
||||
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/16')),
|
||||
Prefix(status=PrefixStatusChoices.STATUS_ACTIVE, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/24')),
|
||||
@ -106,7 +106,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
|
||||
VRF A:10.1.1.0/24
|
||||
None: 192.168.0.0/16
|
||||
"""
|
||||
vrf1, vrf2, vrf3 = list(VRF.objects.all())
|
||||
vrf1 = VRF.objects.first()
|
||||
prefixes = [
|
||||
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/8')),
|
||||
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/16')),
|
||||
@ -130,7 +130,7 @@ class IPAddressOrderingTestCase(OrderingTestBase):
|
||||
"""
|
||||
This function tests ordering with the inclusion of vrfs
|
||||
"""
|
||||
vrf1, vrf2, vrf3 = list(VRF.objects.all())
|
||||
vrf1, vrf2 = VRF.objects.all()[:2]
|
||||
addresses = (
|
||||
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.0.1/24')),
|
||||
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.1.1/24')),
|
||||
|
@ -107,7 +107,7 @@ class ObjectPermissionMixin:
|
||||
return perms
|
||||
|
||||
def has_perm(self, user_obj, perm, obj=None):
|
||||
app_label, action, model_name = resolve_permission(perm)
|
||||
app_label, __, model_name = resolve_permission(perm)
|
||||
|
||||
# Superusers implicitly have all permissions
|
||||
if user_obj.is_active and user_obj.is_superuser:
|
||||
|
@ -213,7 +213,6 @@ class PluginTest(TestCase):
|
||||
self.assertEqual(get_plugin_config(plugin, 'bar'), None)
|
||||
self.assertEqual(get_plugin_config(plugin, 'bar', default=456), 456)
|
||||
|
||||
|
||||
def test_events_pipeline(self):
|
||||
"""
|
||||
Check that events pipeline is registered.
|
||||
|
@ -49,7 +49,7 @@ def handler_500(request, template_name=ERROR_500_TEMPLATE_NAME):
|
||||
template = loader.get_template(template_name)
|
||||
except TemplateDoesNotExist:
|
||||
return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
|
||||
type_, error, traceback = sys.exc_info()
|
||||
type_, error = sys.exc_info()[:2]
|
||||
|
||||
return HttpResponseServerError(template.render({
|
||||
'error': error,
|
||||
|
@ -49,7 +49,7 @@ def handle_rest_api_exception(request, *args, **kwargs):
|
||||
"""
|
||||
Handle exceptions and return a useful error message for REST API requests.
|
||||
"""
|
||||
type_, error, traceback = sys.exc_info()
|
||||
type_, error = sys.exc_info()[:2]
|
||||
data = {
|
||||
'error': str(error),
|
||||
'exception': type_.__name__,
|
||||
|
@ -83,7 +83,7 @@ class CountersTest(TestCase):
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_mptt_child_delete(self):
|
||||
device1, device2 = Device.objects.all()
|
||||
device1 = Device.objects.first()
|
||||
inventory_item1 = InventoryItem.objects.create(device=device1, name='Inventory Item 1')
|
||||
InventoryItem.objects.create(device=device1, name='Inventory Item 2', parent=inventory_item1)
|
||||
device1.refresh_from_db()
|
||||
|
@ -80,5 +80,3 @@ class ClusterSerializer(NetBoxModelSerializer):
|
||||
serializer = get_serializer_for_model(obj.scope)
|
||||
context = {'request': self.context['request']}
|
||||
return serializer(obj.scope, nested=True, context=context).data
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ class ClusterType(VLANGroupsMixin, NetBoxObjectType):
|
||||
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
|
||||
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
|
||||
], strawberry.union("ClusterScopeType")] | None:
|
||||
return self.scope
|
||||
return self.scope
|
||||
|
||||
|
||||
@strawberry_django.type(
|
||||
|
@ -3,17 +3,17 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
def copy_site_assignments(apps, schema_editor):
|
||||
"""
|
||||
Copy site ForeignKey values to the scope GFK.
|
||||
"""
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
Cluster = apps.get_model('virtualization', 'Cluster')
|
||||
Site = apps.get_model('dcim', 'Site')
|
||||
"""
|
||||
Copy site ForeignKey values to the scope GFK.
|
||||
"""
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
Cluster = apps.get_model('virtualization', 'Cluster')
|
||||
Site = apps.get_model('dcim', 'Site')
|
||||
|
||||
Cluster.objects.filter(site__isnull=False).update(
|
||||
scope_type=ContentType.objects.get_for_model(Site),
|
||||
scope_id=models.F('site_id')
|
||||
)
|
||||
Cluster.objects.filter(site__isnull=False).update(
|
||||
scope_type=ContentType.objects.get_for_model(Site),
|
||||
scope_id=models.F('site_id')
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
Loading…
Reference in New Issue
Block a user