Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3889 from netbox-community/3520-graph-template-la…
…nguage Fixes #3520: Add template_language to extras.Graph
- Loading branch information
Showing
11 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
|
||
from dcim.models import Site | ||
from extras.choices import ExportTemplateLanguageChoices | ||
from extras.models import Graph | ||
|
||
|
||
class GraphTest(TestCase): | ||
|
||
def setUp(self): | ||
|
||
self.site = Site(name='Site 1', slug='site-1') | ||
|
||
def test_graph_render_django(self): | ||
|
||
# Using the pluralize filter as a sanity check (it's only available in Django) | ||
TEMPLATE_TEXT = "{{ obj.name|lower }} thing{{ 2|pluralize }}" | ||
RENDERED_TEXT = "site 1 things" | ||
|
||
graph = Graph( | ||
type=ContentType.objects.get(app_label='dcim', model='site'), | ||
name='Graph 1', | ||
template_language=ExportTemplateLanguageChoices.LANGUAGE_DJANGO, | ||
source=TEMPLATE_TEXT, | ||
link=TEMPLATE_TEXT | ||
) | ||
|
||
self.assertEqual(graph.embed_url(self.site), RENDERED_TEXT) | ||
self.assertEqual(graph.embed_link(self.site), RENDERED_TEXT) | ||
|
||
def test_graph_render_jinja2(self): | ||
|
||
TEMPLATE_TEXT = "{{ [obj.name, obj.slug]|join(',') }}" | ||
RENDERED_TEXT = "Site 1,site-1" | ||
|
||
graph = Graph( | ||
type=ContentType.objects.get(app_label='dcim', model='site'), | ||
name='Graph 1', | ||
template_language=ExportTemplateLanguageChoices.LANGUAGE_JINJA2, | ||
source=TEMPLATE_TEXT, | ||
link=TEMPLATE_TEXT | ||
) | ||
|
||
self.assertEqual(graph.embed_url(self.site), RENDERED_TEXT) | ||
self.assertEqual(graph.embed_link(self.site), RENDERED_TEXT) |