Beispiel #1
0
    def test_get_provider_graphs(self):
        """
        Test retrieval of Graphs assigned to Providers.
        """
        provider = self.model.objects.first()
        ct = ContentType.objects.get(app_label='circuits', model='provider')
        graphs = (
            Graph(
                type=ct,
                name='Graph 1',
                source=
                'http://example.com/graphs.py?provider={{ obj.slug }}&foo=1'),
            Graph(
                type=ct,
                name='Graph 2',
                source=
                'http://example.com/graphs.py?provider={{ obj.slug }}&foo=2'),
            Graph(
                type=ct,
                name='Graph 3',
                source=
                'http://example.com/graphs.py?provider={{ obj.slug }}&foo=3'),
        )
        Graph.objects.bulk_create(graphs)

        url = reverse('circuits-api:provider-graphs',
                      kwargs={'pk': provider.pk})
        response = self.client.get(url, **self.header)

        self.assertEqual(len(response.data), 3)
        self.assertEqual(
            response.data[0]['embed_url'],
            'http://example.com/graphs.py?provider=provider-1&foo=1')
Beispiel #2
0
    def setUpTestData(cls):
        ct = ContentType.objects.get_for_model(Site)

        graphs = (
            Graph(type=ct, name='Graph 1', source='http://example.com/graphs.py?site={{ obj.name }}&foo=1'),
            Graph(type=ct, name='Graph 2', source='http://example.com/graphs.py?site={{ obj.name }}&foo=2'),
            Graph(type=ct, name='Graph 3', source='http://example.com/graphs.py?site={{ obj.name }}&foo=3'),
        )
        Graph.objects.bulk_create(graphs)
Beispiel #3
0
    def setUpTestData(cls):

        # Get the first three available types
        content_types = ContentType.objects.filter(GRAPH_MODELS)[:3]

        graphs = (
            Graph(name='Graph 1', type=content_types[0], template_language=TemplateLanguageChoices.LANGUAGE_DJANGO, source='http://example.com/1'),
            Graph(name='Graph 2', type=content_types[1], template_language=TemplateLanguageChoices.LANGUAGE_JINJA2, source='http://example.com/2'),
            Graph(name='Graph 3', type=content_types[2], template_language=TemplateLanguageChoices.LANGUAGE_JINJA2, source='http://example.com/3'),
        )
        Graph.objects.bulk_create(graphs)
Beispiel #4
0
    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=TemplateLanguageChoices.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)
Beispiel #5
0
    def setUpTestData(cls):

        graphs = (
            Graph(name='Graph 1',
                  type=GRAPH_TYPE_DEVICE,
                  source='http://example.com/1'),
            Graph(name='Graph 2',
                  type=GRAPH_TYPE_INTERFACE,
                  source='http://example.com/2'),
            Graph(name='Graph 3',
                  type=GRAPH_TYPE_SITE,
                  source='http://example.com/3'),
        )
        Graph.objects.bulk_create(graphs)
Beispiel #6
0
    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=TemplateLanguageChoices.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)
Beispiel #7
0
    def test_get_vminterface_graphs(self):
        """
        Test retrieval of Graphs assigned to VM interfaces.
        """
        ct = ContentType.objects.get_for_model(VMInterface)
        graphs = (
            Graph(type=ct, name='Graph 1', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=1'),
            Graph(type=ct, name='Graph 2', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=2'),
            Graph(type=ct, name='Graph 3', source='http://example.com/graphs.py?interface={{ obj.name }}&foo=3'),
        )
        Graph.objects.bulk_create(graphs)

        self.add_permissions('virtualization.view_vminterface')
        url = reverse('virtualization-api:vminterface-graphs', kwargs={
            'pk': VMInterface.objects.first().pk
        })
        response = self.client.get(url, **self.header)

        self.assertEqual(len(response.data), 3)
        self.assertEqual(response.data[0]['embed_url'], 'http://example.com/graphs.py?interface=Interface 1&foo=1')