Example #1
0
    def test_from_dict_predefined_graph2(self):
        pg = PredefinedGraph(name='test', slug='test-graph')
        pg.save()
        # Make dummy item that contains another predefined graph.
        pg.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_LINE,
            value='line-1', index=100)
        pg.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_PREDEFINED_GRAPH,
            value='test-graph-sub', index=110)

        pg2 = PredefinedGraph(name='test', slug='test-graph-sub')
        pg2.save()
        # Make 2 random dummy items.
        pg2.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_LINE,
            value='sub-1',
            index=100)
        pg2.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_LINE,
            value='sub-2',
            index=110)

        graph_items = pg.unfolded_graph_items()
        self.assertEquals(len(graph_items), 3)
        self.assertEquals(graph_items[0].value, 'line-1')
        self.assertEquals(graph_items[1].value, 'sub-1')
        self.assertEquals(graph_items[2].value, 'sub-2')
Example #2
0
    def test_graph_items_from_request(self):
        pg = PredefinedGraph(name='test', slug='test')
        pg.save()
        # Make 2 dummy items
        pg.graphitem_set.create()
        pg.graphitem_set.create()
        result, graph_settings = self.graph_items_from_request(
            'graph=test')

        self.assertEquals(len(result), 2)
        for graph_item in result:
            self.assertTrue(isinstance(graph_item, GraphItem))
Example #3
0
    def test_graph_items_from_request5(self):
        """
        Add custom location to graph_item.
        """
        pg = PredefinedGraph(name='test', slug='test')
        pg.save()
        # Make dummy item, no location defined
        pg.graphitem_set.create(graph_type=GraphItem.GRAPH_TYPE_LINE)

        result, graph_settings = self.graph_items_from_request(
            'graph=test&location=111.1')

        self.assertEquals(len(result), 1)
        for graph_item in result:
            self.assertTrue(isinstance(graph_item, GraphItem))
            self.assertEquals(graph_item.location.ident, '111.1')
Example #4
0
    def test_graph_items_from_request2(self):
        pg = PredefinedGraph(name='test', slug='test')
        pg.save()
        # Make 2 dummy items
        pg.graphitem_set.create(value='test-item-1')
        pg.graphitem_set.create(value='test-item-2')

        pg2 = PredefinedGraph(name='test2', slug='test2')
        pg2.save()
        # Make 1 dummy item
        pg2.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_PREDEFINED_GRAPH,
            value='test',
            )

        result, graph_settings = self.graph_items_from_request(
            'graph=test2')

        # 2 results: the graph item from pg2 is "unfolded" in graph
        # items from pg.
        for element in result:
            self.assertTrue(isinstance(element, GraphItem))
        self.assertEquals(len(result), 2)
Example #5
0
    def test_from_dict_predefined_graph(self):
        pg = PredefinedGraph(name='test', slug='test-graph')
        pg.save()
        # Make 2 dummy items
        pg.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_LINE,
            value='test-value1',
            index=100)
        pg.graphitem_set.create(
            graph_type=GraphItem.GRAPH_TYPE_LINE,
            value='test-value2',
            index=110)

        graph_item_dict = {
            'type': 'predefined-graph',
            'value': 'test-graph'
            }
        graph_items = GraphItem.from_dict(graph_item_dict)
        self.assertEquals(len(graph_items), 2)
        self.assertEquals(
            graph_items[0].graph_type, GraphItem.GRAPH_TYPE_LINE)
        self.assertEquals(graph_items[0].value, 'test-value1')
        self.assertEquals(graph_items[1].value, 'test-value2')