mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Initial implementation of tests for plugins framework
This commit is contained in:
15
netbox/extras/tests/dummy_plugin/__init__.py
Normal file
15
netbox/extras/tests/dummy_plugin/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from extras.plugins import PluginConfig
|
||||
|
||||
|
||||
class DummyPluginConfig(PluginConfig):
|
||||
name = 'extras.tests.dummy_plugin'
|
||||
verbose_name = 'Dummy plugin'
|
||||
version = '0.0'
|
||||
description = 'For testing purposes only'
|
||||
base_url = 'dummy-plugin'
|
||||
middleware = [
|
||||
'extras.tests.dummy_plugin.middleware.DummyMiddleware'
|
||||
]
|
||||
|
||||
|
||||
config = DummyPluginConfig
|
||||
9
netbox/extras/tests/dummy_plugin/admin.py
Normal file
9
netbox/extras/tests/dummy_plugin/admin.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from netbox.admin import admin_site
|
||||
from .models import DummyModel
|
||||
|
||||
|
||||
@admin.register(DummyModel, site=admin_site)
|
||||
class AnimalAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'number')
|
||||
9
netbox/extras/tests/dummy_plugin/api/serializers.py
Normal file
9
netbox/extras/tests/dummy_plugin/api/serializers.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from extras.tests.dummy_plugin.models import DummyModel
|
||||
|
||||
|
||||
class DummySerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = DummyModel
|
||||
fields = ('id', 'name', 'sound')
|
||||
6
netbox/extras/tests/dummy_plugin/api/urls.py
Normal file
6
netbox/extras/tests/dummy_plugin/api/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from rest_framework import routers
|
||||
from .views import DummyViewSet
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('dummy-models', DummyViewSet)
|
||||
urlpatterns = router.urls
|
||||
8
netbox/extras/tests/dummy_plugin/api/views.py
Normal file
8
netbox/extras/tests/dummy_plugin/api/views.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from extras.tests.dummy_plugin.models import DummyModel
|
||||
from .serializers import DummySerializer
|
||||
|
||||
|
||||
class DummyViewSet(ModelViewSet):
|
||||
queryset = DummyModel.objects.all()
|
||||
serializer_class = DummySerializer
|
||||
7
netbox/extras/tests/dummy_plugin/middleware.py
Normal file
7
netbox/extras/tests/dummy_plugin/middleware.py
Normal file
@@ -0,0 +1,7 @@
|
||||
class DummyMiddleware:
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
return self.get_response(request)
|
||||
23
netbox/extras/tests/dummy_plugin/migrations/0001_initial.py
Normal file
23
netbox/extras/tests/dummy_plugin/migrations/0001_initial.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='DummyModel',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=20)),
|
||||
('number', models.IntegerField(default=100)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
]
|
||||
13
netbox/extras/tests/dummy_plugin/models.py
Normal file
13
netbox/extras/tests/dummy_plugin/models.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class DummyModel(models.Model):
|
||||
name = models.CharField(
|
||||
max_length=20
|
||||
)
|
||||
number = models.IntegerField(
|
||||
default=100
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
28
netbox/extras/tests/dummy_plugin/navigation.py
Normal file
28
netbox/extras/tests/dummy_plugin/navigation.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from extras.plugins import PluginMenuButton, PluginMenuItem
|
||||
from utilities.choices import ButtonColorChoices
|
||||
|
||||
|
||||
menu_items = (
|
||||
PluginMenuItem(
|
||||
link='plugins:dummy_plugin:dummy_models',
|
||||
link_text='Item 1',
|
||||
buttons=(
|
||||
PluginMenuButton(
|
||||
link='plugins:netbox_animal_sounds:random_animal',
|
||||
title='Random animal',
|
||||
icon_class='fa-question'
|
||||
),
|
||||
PluginMenuButton(
|
||||
link='admin:netbox_animal_sounds_animal_add',
|
||||
title='Add a new animal',
|
||||
icon_class='fa-plus',
|
||||
color=ButtonColorChoices.GREEN,
|
||||
permissions=['netbox_animal_sounds.add_animal']
|
||||
),
|
||||
)
|
||||
),
|
||||
PluginMenuItem(
|
||||
link='plugins:dummy_plugin:dummy_models',
|
||||
link_text='Item 2',
|
||||
),
|
||||
)
|
||||
20
netbox/extras/tests/dummy_plugin/template_content.py
Normal file
20
netbox/extras/tests/dummy_plugin/template_content.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from extras.plugins import PluginTemplateExtension
|
||||
|
||||
|
||||
class SiteContent(PluginTemplateExtension):
|
||||
model = 'dcim.site'
|
||||
|
||||
def left_page(self):
|
||||
return "SITE CONTENT - LEFT PAGE"
|
||||
|
||||
def right_page(self):
|
||||
return "SITE CONTENT - RIGHT PAGE"
|
||||
|
||||
def full_width_page(self):
|
||||
return "SITE CONTENT - FULL WIDTH PAGE"
|
||||
|
||||
def full_buttons(self):
|
||||
return "SITE CONTENT - BUTTONS"
|
||||
|
||||
|
||||
template_extensions = [SiteContent]
|
||||
8
netbox/extras/tests/dummy_plugin/urls.py
Normal file
8
netbox/extras/tests/dummy_plugin/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = (
|
||||
path('models/', views.DummyModelsView.as_view(), name='dummy_models'),
|
||||
)
|
||||
11
netbox/extras/tests/dummy_plugin/views.py
Normal file
11
netbox/extras/tests/dummy_plugin/views.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import View
|
||||
|
||||
from .models import DummyModel
|
||||
|
||||
|
||||
class DummyModelsView(View):
|
||||
|
||||
def get(self, request):
|
||||
instance_count = DummyModel.objects.count()
|
||||
return HttpResponse(f"Instances: {instance_count}")
|
||||
Reference in New Issue
Block a user