Пример #1
0
 def test_dict_list_xml(self):
     resp = widget(lambda r: {'item': [{'value': 1, 'text': "test1"},
             {'value': 2, 'text': "test2"}]})(self.xml_request)
     self.assertEqual('<?xml version="1.0" ?><root>'
             '<item><text>test1</text><value>1</value></item>'
             '<item><text>test2</text><value>2</value></item></root>',
             resp.content)
Пример #2
0
 def test_tuples(self):
     widget = rag_widget(lambda r: ((10, "ten"), (5, "five"),
             (1, "one")))
     resp = widget(self.request)
     self.assertEqual('{"item": [{"value": 10, "text": "ten"}, '
             '{"value": 5, "text": "five"}, {"value": 1, "text": "one"}]}',
             resp.content)
Пример #3
0
 def test_single_value_and_parameter_with_format(self):
     # reset POST
     del self.request.POST['format']
     widget = number_widget(absolute='true', format="json")(lambda r: [10])
     resp = widget(self.request)
     json = '{"item": [{"value": 10}], "absolute": "true"}'
     self.assertEqual(json, resp.content)
Пример #4
0
 def test_2tuples(self):
     widget = pie_chart(lambda r: [(1, "one"), (2, "two"),
             (3, "three")])
     resp = widget(self.request)
     self.assertEqual('{"item": [{"value": 1, "label": "one"}, '
             '{"value": 2, "label": "two"}, '
             '{"value": 3, "label": "three"}]}', resp.content)
Пример #5
0
 def test_list_tuples(self):
     widget = text_widget(lambda r: [("test1", TEXT_NONE),
             ("test2", TEXT_INFO), ("test3", TEXT_WARN)])
     resp = widget(self.request)
     self.assertEqual('{"item": [{"text": "test1", "type": 0}, '
             '{"text": "test2", "type": 2}, '
             '{"text": "test3", "type": 1}]}', resp.content)
Пример #6
0
 def test_encrypted_json_get(self):
     req = HttpRequest()
     req.GET['format'] = '2'
     resp = widget(encrypted=True)(lambda r: "test")(req)
     self.assertNotEqual('"test"', resp.content)
     self.assertEqual(44, len(resp.content))
     self.assertEqual(resp._headers['content-type'], ('Content-Type', 'application/json'))
Пример #7
0
 def test_point_generation(self):
     data = self._get_test_data()
     data["item"]["axis"] = {"min": 0, "max": 20, "points": 5, "precision": 0}
     widget = bullet_graph(lambda r: data)
     resp = widget(self.request)
     # The basic case is to just pass through the data
     self.assertEqual(
             '{'
             '"item": {'
             '"label": "test label", '
             '"sublabel": "test sub label", '
             '"range": {'
             '"amber": {"start": 5, "end": 10}, '
             '"green": {"start": 10, "end": 15}, '
             '"red": {"start": 0, "end": 5}'
             '}, '
             '"measure": {'
             '"current": {"start": 0, "end": 7}, '
             '"projected": {"start": 9, "end": 12}'
             '}, '
             '"comparative": {"point": [11, 14]}, '
             '"axis": {"point": [0, 5, 10, 15, 20]}'
             '}, '
             '"orientation": "vertical"'
             '}', 
             resp.content)
Пример #8
0
 def test_wrong_api_key(self):
     self.settings_manager.set(GECKOBOARD_API_KEY='abc')
     req = HttpRequest()
     req.META['HTTP_AUTHORIZATION'] = "basic %s" % base64.b64encode('def')
     resp = widget(lambda r: "test")(req)
     self.assertTrue(isinstance(resp, HttpResponseForbidden), resp)
     self.assertEqual('Geckoboard API key incorrect', resp.content)
 def test_tuples(self):
     widget = geck_o_meter(lambda r: (2, (1, "min"), (3, "max")))
     resp = widget(self.request)
     self.assertJSONEqual(
         ('{"item": 2, "max": {"value": 3, "text": "max"}, '
          '"min": {"value": 1, "text": "min"}}'),
         resp.content.decode('utf8'))
 def test_list(self):
     widget = text_widget(lambda r: ["test1", "test2"])
     resp = widget(self.request)
     self.assertJSONEqual(
         ('{"item": [{"text": "test1", "type": 0}, '
          '{"text": "test2", "type": 0}]}'),
         resp.content.decode('utf8'))
Пример #11
0
 def test_api_key(self):
     self.settings_manager.set(GECKOBOARD_API_KEY='abc')
     req = HttpRequest()
     req.META['HTTP_AUTHORIZATION'] = "basic %s" % base64.b64encode('abc')
     resp = widget(lambda r: "test")(req)
     self.assertEqual('<?xml version="1.0" ?><root>test</root>',
             resp.content)
Пример #12
0
 def test_axes(self):
     widget = line_chart(lambda r: ([1, 2, 3],
             ["first", "last"], ["low", "high"]))
     resp = widget(self.request)
     self.assertEqual('{"item": [1, 2, 3], "settings": '
             '{"axisx": ["first", "last"], "axisy": ["low", "high"]}}',
             resp.content)
Пример #13
0
 def test_color(self):
     widget = line_chart(lambda r: ([1, 2, 3],
             ["first", "last"], ["low", "high"], "00112233"))
     resp = widget(self.request)
     self.assertEqual('{"item": [1, 2, 3], "settings": '
             '{"axisx": ["first", "last"], "axisy": ["low", "high"], '
             '"colour": "00112233"}}', resp.content)
Пример #14
0
 def test_xml_post(self):
     req = HttpRequest()
     req.POST['format'] = '1'
     resp = widget(lambda r: "test")(req)
     self.assertEqual('<?xml version="1.0" ?><root>test</root>',
             resp.content)
     self.assertEqual(resp._headers['content-type'], ('Content-Type', 'application/xml'))
 def test_dict_list_json(self):
     data = [OrderedDict([('value', 1), ('text', "test1")]),
             OrderedDict([('value', 2), ('text', "test2")])]
     resp = widget(lambda r: {'item': data})(self.json_request)
     self.assertJSONEqual(
         ('{"item": [{"value": 1, "text": "test1"}, '
          '{"value": 2, "text": "test2"}]}'),
         resp.content.decode('utf8'))
Пример #16
0
 def test_3tuples(self):
     widget = pie_chart(lambda r: [(1, "one", "00112233"),
             (2, "two", "44556677"), (3, "three", "8899aabb")])
     resp = widget(self.request)
     self.assertEqual('{"item": ['
             '{"value": 1, "label": "one", "colour": "00112233"}, '
             '{"value": 2, "label": "two", "colour": "44556677"}, '
             '{"value": 3, "label": "three", "colour": "8899aabb"}]}',
             resp.content)
Пример #17
0
 def test_list_dict(self):
     widget = list_widget(lambda r:
         [{"label": {"name": "test1", "color": "#FFFFFF"}, "title": {"text": "test1title", "highlight": False}, "description": "test1desc"},
         {"label": {"name": "test2", "color": "#AAAAAA"}, "title": {"text": "test2title", "highlight": True}, "description": "test2desc"}])
     resp = widget(self.request)
     self.assertEqual('{"item": ['
         '{"title": {"text": "test1title", "highlight": false}, "description": "test1desc", "label": {"color": "#FFFFFF", "name": "test1"}}, '
         '{"title": {"text": "test2title", "highlight": true}, "description": "test2desc", "label": {"color": "#AAAAAA", "name": "test2"}}]}',
         resp.content)
Пример #18
0
 def test_funnel_sorting(self):
     sortable_data = self.funnel_data
     sortable_data.update({
         'sort': True
     })
     widget = funnel(lambda r: sortable_data)
     resp = widget(self.request)
     self.assertEqual('{"item": [{"value": 100, "label": "step 1"}, '
                 '{"value": 50, "label": "step 2"}], "type": "reverse", '
                 '"percentage": "hide"}', resp.content)
 def test_3tuples(self):
     data = [(1, "one", "00112233"),
             (2, "two", "44556677"), (3, "three", "8899aabb")]
     widget = pie_chart(lambda r: data)
     resp = widget(self.request)
     self.assertJSONEqual(
         ('{"item": ['
          '{"value": 1, "label": "one", "colour": "00112233"}, '
          '{"value": 2, "label": "two", "colour": "44556677"}, '
          '{"value": 3, "label": "three", "colour": "8899aabb"}]}'),
         resp.content.decode('utf8'))
 def test_list_tuples(self):
     data = [("test1", TEXT_NONE),
             ("test2", TEXT_INFO),
             ("test3", TEXT_WARN)]
     widget = text_widget(lambda r: data)
     resp = widget(self.request)
     self.assertJSONEqual(
         ('{"item": [{"text": "test1", "type": 0}, '
          '{"text": "test2", "type": 2}, '
          '{"text": "test3", "type": 1}]}'),
         resp.content.decode('utf8'))
 def test_funnel(self):
     widget = funnel(lambda r: self.funnel_data)
     resp = widget(self.request)
     content = json.loads(resp.content.decode('utf8'))
     expected = {
         'type': 'reverse',
         'percentage': 'hide',
         'item': [
             {'value': 50, 'label': 'step 2'},
             {'value': 100, 'label': 'step 1'},
         ],
     }
     self.assertEqual(content, expected)
Пример #22
0
 def test_funnel(self):
     widget = funnel(lambda r: self.funnel_data)
     resp = widget(self.request)
     json = simplejson.loads(resp.content)
     data = {
         'type': 'reverse',
         'percentage': 'hide',
         'item': [
             {'value': 50, 'label': 'step 2'},
             {'value': 100, 'label': 'step 1'},
         ],
     }
     self.assertEqual(json, data)
Пример #23
0
 def test_funnel_sorting(self):
     sortable_data = self.funnel_data
     sortable_data.update({
         'sort': True
     })
     widget = funnel(lambda r: sortable_data)
     resp = widget(self.request)
     content = json.loads(resp.content)
     expected = {
         'type': 'reverse',
         'percentage': 'hide',
         'item': [
             {'value': 100, 'label': 'step 1'},
             {'value': 50, 'label': 'step 2'},
         ],
     }
     self.assertEqual(content, expected)
Пример #24
0
 def test_bullet_minimal(self):
     """Minimal set of parameters. Some values are computed by the decorator."""
     widget = bullet(lambda r: self.bullet_data_minimal)
     resp = widget(self.request)
     # Parse
     data = simplejson.loads(resp.content)
     # Alias for readability
     item = data['item']
     # Tests
     self.assertEqual(data['orientation'], 'horizontal')
     self.assertEqual(item['label'], "Some label")
     self.assertEqual(item['axis']['point'], [0, 200, 400, 600, 800, 1000])
     self.assertEqual(item['measure']['current']['start'], 0)
     self.assertEqual(item['measure']['current']['end'], 500)
     self.assertEqual(item['comparative']['point'], 600)
     self.assertEqual(item['range']['red']['start'], 0)
     self.assertEqual(item['range']['red']['end'], 332)
     self.assertEqual(item['range']['amber']['start'], 333)
     self.assertEqual(item['range']['amber']['end'], 666)
     self.assertEqual(item['range']['green']['start'], 667)
     self.assertEqual(item['range']['green']['end'], 1000)
Пример #25
0
    def test_auto_scale(self):
        bullet_data = self.bullet_data_minimal.copy()
        bullet_data['auto_scale'] = True
        widget = bullet(lambda r: bullet_data)

        resp = widget(self.request)
        # Parse
        data = simplejson.loads(resp.content)
        # Alias for readability
        item = data['item']
        # Tests
        self.assertEqual(data['orientation'], 'horizontal')
        self.assertEqual(item['label'], "Some label")
        self.assertEqual(item['axis']['point'], [0, 0.2, 0.4, 0.6, 0.8, 1.0])
        self.assertEqual(item['measure']['current']['start'], 0)
        self.assertEqual(item['measure']['current']['end'], 0.5)
        self.assertEqual(item['comparative']['point'], 0.6)
        self.assertEqual(item['range']['red']['start'], 0)
        self.assertEqual(item['range']['red']['end'], .33)
        self.assertEqual(item['range']['amber']['start'], .33)
        self.assertEqual(item['range']['amber']['end'], .67)
        self.assertEqual(item['range']['green']['start'], .67)
        self.assertEqual(item['range']['green']['end'], 1.0)
Пример #26
0
 def test_values(self):
     widget = line_chart(lambda r: ([1, 2, 3],))
     resp = widget(self.request)
     self.assertEqual('{"item": [1, 2, 3], "settings": {}}', resp.content)
Пример #27
0
 def test_scalars(self):
     widget = pie_chart(lambda r: [1, 2, 3])
     resp = widget(self.request)
     self.assertEqual(
         '{"item": [{"value": 1}, {"value": 2}, {"value": 3}]}',
         resp.content)
Пример #28
0
 def test_scalars(self):
     widget = pie_chart(lambda r: [1, 2, 3])
     resp = widget(self.request)
     self.assertEqual(
             '{"item": [{"value": 1}, {"value": 2}, {"value": 3}]}',
             resp.content)
Пример #29
0
 def test_scalar_json(self):
     resp = widget(lambda r: "test")(self.json_request)
     self.assertEqual('"test"', resp.content)
Пример #30
0
 def test_single_value_as_dictionary_with_prefix(self):
     widget = number_widget(lambda r: [{'value': 10, 'prefix': '$'}])
     resp = widget(self.request)
     json = '{"item": [{"prefix": "$", "value": 10}]}'
     self.assertEqual(json, resp.content)
Пример #31
0
 def test_dict_json(self):
     resp = widget(lambda r: SortedDict([('a', 1), ('b', 2)]))(
         self.json_request)
     self.assertEqual('{"a": 1, "b": 2}', resp.content)
Пример #32
0
 def test_missing_api_key(self):
     self.settings_manager.set(GECKOBOARD_API_KEY='abc')
     req = HttpRequest()
     resp = widget(lambda r: "test")(req)
     self.assertTrue(isinstance(resp, HttpResponseForbidden), resp)
     self.assertEqual('Geckoboard API key incorrect', resp.content)
Пример #33
0
 def test_two_values_as_dictionary(self):
     widget = number_widget(lambda r: [{'value': 10}, {'value': 9}])
     resp = widget(self.request)
     json = '{"item": [{"value": 10}, {"value": 9}]}'
     self.assertEqual(json, resp.content)
Пример #34
0
 def test_scalars(self):
     widget = geck_o_meter(lambda r: (2, 1, 3))
     resp = widget(self.request)
     self.assertEqual(
         '{"item": 2, "max": {"value": 3}, '
         '"min": {"value": 1}}', resp.content)
Пример #35
0
 def test_tuples(self):
     widget = geck_o_meter(lambda r: (2, (1, "min"), (3, "max")))
     resp = widget(self.request)
     self.assertEqual(
         '{"item": 2, "max": {"value": 3, "text": "max"}, '
         '"min": {"value": 1, "text": "min"}}', resp.content)
Пример #36
0
 def test_dict_list_json(self):
     resp = widget(lambda r: {'item': [SortedDict([('value', 1),
             ('text', "test1")]), SortedDict([('value', 2), ('text',
                     "test2")])]})(self.json_request)
     self.assertEqual('{"item": [{"value": 1, "text": "test1"}, '
             '{"value": 2, "text": "test2"}]}', resp.content)
Пример #37
0
 def test_values(self):
     widget = line_chart(lambda r: ([1, 2, 3], ))
     resp = widget(self.request)
     self.assertEqual('{"item": [1, 2, 3], "settings": {}}', resp.content)
Пример #38
0
 def test_tuples(self):
     widget = pie_chart(lambda r: [(1, ), (2, ), (3, )])
     resp = widget(self.request)
     self.assertEqual(
         '{"item": [{"value": 1}, {"value": 2}, {"value": 3}]}',
         resp.content)
Пример #39
0
 def test_scalars(self):
     widget = rag_widget(lambda r: (10, 5, 1))
     resp = widget(self.request)
     self.assertEqual(
         '{"item": [{"value": 10}, {"value": 5}, {"value": 1}]}',
         resp.content)
Пример #40
0
 def test_json_get(self):
     req = HttpRequest()
     req.GET['format'] = '2'
     resp = widget(lambda r: "test")(req)
     self.assertEqual('"test"', resp.content)
Пример #41
0
 def test_json_get(self):
     req = HttpRequest()
     resp = widget(format="json")(lambda r: "test")(req)
     self.assertEqual('"test"', resp.content)
     self.assertEqual(resp._headers['content-type'],
                      ('Content-Type', 'application/json'))
Пример #42
0
 def test_xml_post(self):
     req = HttpRequest()
     req.POST['format'] = '1'
     resp = widget(lambda r: "test")(req)
     self.assertEqual('<?xml version="1.0" ?><root>test</root>',
                      resp.content)
Пример #43
0
 def test_two_values_and_parameter(self):
     widget = number_widget(absolute='true')(lambda r: [10, 9])
     resp = widget(self.request)
     json = '{"item": [{"value": 10}, {"value": 9}], "absolute": "true"}'
     self.assertEqual(json, resp.content)
Пример #44
0
 def test_singe_value(self):
     widget = number_widget(lambda r: [10])
     resp = widget(self.request)
     self.assertEqual('{"item": [{"value": 10}]}', resp.content)
Пример #45
0
 def test_list_xml(self):
     resp = widget(lambda r: {'list': [1, 2, 3]})(self.xml_request)
     self.assertEqual(
         '<?xml version="1.0" ?><root><list>1</list>'
         '<list>2</list><list>3</list></root>', resp.content)
Пример #46
0
 def test_string(self):
     widget = text_widget(lambda r: "test message")
     resp = widget(self.request)
     self.assertEqual('{"item": [{"text": "test message", "type": 0}]}',
                      resp.content)
Пример #47
0
 def test_dict_xml(self):
     resp = widget(lambda r: SortedDict([('a', 1), ('b', 2)]))(
         self.xml_request)
     self.assertEqual('<?xml version="1.0" ?><root><a>1</a><b>2</b></root>',
                      resp.content)
Пример #48
0
 def test_list_json(self):
     resp = widget(lambda r: {'list': [1, 2, 3]})(self.json_request)
     self.assertEqual('{"list": [1, 2, 3]}', resp.content)
Пример #49
0
 def test_tuples(self):
     widget = pie_chart(lambda r: [(1, ), (2, ), (3, )])
     resp = widget(self.request)
     self.assertEqual(
             '{"item": [{"value": 1}, {"value": 2}, {"value": 3}]}',
             resp.content)
Пример #50
0
 def test_wrong_format(self):
     req = HttpRequest()
     resp = widget(format="csv")(lambda r: "test")(req)
     self.assertEqual('<?xml version="1.0" ?><root>test</root>',
             resp.content)
     self.assertEqual(resp._headers['content-type'], ('Content-Type', 'application/xml'))
Пример #51
0
 def test_scalar_xml(self):
     resp = widget(lambda r: "test")(self.xml_request)
     self.assertEqual('<?xml version="1.0" ?><root>test</root>',
                      resp.content)
Пример #52
0
 def test_scalars(self):
     widget = geck_o_meter(lambda r: (2, 1, 3))
     resp = widget(self.request)
     self.assertEqual('{"item": 2, "max": {"value": 3}, '
             '"min": {"value": 1}}', resp.content)
Пример #53
0
 def test_x_axis(self):
     widget = line_chart(lambda r: ([1, 2, 3],
             ["first", "last"]))
     resp = widget(self.request)
     self.assertEqual('{"item": [1, 2, 3], '
             '"settings": {"axisx": ["first", "last"]}}', resp.content)
Пример #54
0
 def test_list(self):
     widget = text_widget(lambda r: ["test1", "test2"])
     resp = widget(self.request)
     self.assertEqual(
         '{"item": [{"text": "test1", "type": 0}, '
         '{"text": "test2", "type": 0}]}', resp.content)
Пример #55
0
 def test_json_parameter_get(self):
     req = HttpRequest()
     req.GET['format'] = '2'
     resp = widget(lambda r: "test")(req)
     self.assertEqual('"test"', resp.content)
     self.assertEqual(resp._headers['content-type'], ('Content-Type', 'application/json'))
Пример #56
0
 def test_encrypted_xml_get(self):
     req = HttpRequest()
     req.GET['format'] = '1'
     self.assertRaises(ValueError,
                       widget(encrypted=True)(lambda r: "test"), req)
Пример #57
0
 def test_x_axis(self):
     widget = line_chart(lambda r: ([1, 2, 3], ["first", "last"]))
     resp = widget(self.request)
     self.assertEqual(
         '{"item": [1, 2, 3], '
         '"settings": {"axisx": ["first", "last"]}}', resp.content)
Пример #58
0
 def test_two_values(self):
     widget = number_widget(lambda r: [10, 9])
     resp = widget(self.request)
     self.assertEqual('{"item": [{"value": 10}, {"value": 9}]}',
                      resp.content)