Skip to content

Commit

Permalink
[config] Imported preview logic from django-netjsonconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jan 12, 2017
1 parent d5c9175 commit 12ef673
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions openwisp2/config/templates/admin/config/change_form.html
@@ -0,0 +1 @@
{% extends "admin/django_netjsonconfig/change_form.html" %}
1 change: 1 addition & 0 deletions openwisp2/config/templates/admin/config/preview.html
@@ -0,0 +1 @@
{% extends "admin/django_netjsonconfig/preview.html" %}
1 change: 1 addition & 0 deletions openwisp2/config/templates/admin/submit_line.html
@@ -0,0 +1 @@
{% extends "admin/django_netjsonconfig/submit_line.html" %}
35 changes: 35 additions & 0 deletions openwisp2/config/tests/test_admin.py
Expand Up @@ -2,6 +2,8 @@
from django.test import TestCase
from django.urls import reverse

import json

from . import CreateConfigTemplateMixin
from ...tests import TestOrganizationMixin
from ..models import Config, Template
Expand Down Expand Up @@ -33,3 +35,36 @@ def test_config_and_template_different_organization(self):
# remove conflicting template and ensure doesn't error
response = self.client.post(path, {'templates': '', 'key': self.TEST_KEY})
self.assertNotIn('errors field-templates', str(response.content))

def test_preview_config(self):
org = self._create_org()
self._create_template(organization=org)
templates = Template.objects.all()
path = reverse('admin:config_config_preview')
config = json.dumps({
'interfaces': [
{
'name': 'eth0',
'type': 'ethernet',
'addresses': [
{
'family': 'ipv4',
'proto': 'dhcp'
}
]
}
]
})
data = {
'name': 'test-config',
'organization': org.pk,
'mac_address': self.TEST_MAC_ADDRESS,
'backend': 'netjsonconfig.OpenWrt',
'config': config,
'csrfmiddlewaretoken': 'test',
'templates': ','.join([str(t.pk) for t in templates])
}
response = self.client.post(path, data)
self.assertContains(response, '<pre class="djnjc-preformatted')
self.assertContains(response, 'eth0')
self.assertContains(response, 'dhcp')
2 changes: 1 addition & 1 deletion tests/settings.py
Expand Up @@ -21,14 +21,14 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django_extensions',
'organizations',
'sortedm2m',
'reversion',
'openwisp2.pki',
'openwisp2.config',
'openwisp2.ui',
'django.contrib.admin'
]

STATICFILES_FINDERS = [
Expand Down

0 comments on commit 12ef673

Please sign in to comment.