Beispiel #1
0
 def test_json_parsing_minimal_input(self):
     md = common.json_to_metric_data('{"name": "testname", "value": 13}')
     self.assertIsInstance(md.name, str)
     self.assertEquals(md.name, "testname")
     self.assertEquals(md.points[0].value, 13)
     self.assertIsNone(md.start_time)
     self.assertIsNone(md.points[0].fields)
Beispiel #2
0
 def test_json_parsing_minimal_input(self):
   md = common.json_to_metric_data('{"name": "testname", "value": 13}')
   self.assertIsInstance(md.name, str)
   self.assertEquals(md.name, "testname")
   self.assertEquals(md.value, 13)
   self.assertIsNone(md.start_time)
   self.assertIsNone(md.fields)
Beispiel #3
0
 def test_json_parsing_with_start_time(self):
     md = common.json_to_metric_data('{"name": "testname", "value": 13, '
                                     '"start_time": 1234}')
     self.assertIsInstance(md.name, str)
     self.assertEquals(md.name, "testname")
     self.assertEquals(md.points[0].value, 13)
     self.assertEquals(md.start_time, 1234)
     self.assertIsNone(md.points[0].fields)
Beispiel #4
0
 def test_json_parsing_with_start_time(self):
   md = common.json_to_metric_data('{"name": "testname", "value": 13, '
                                   '"start_time": 1234}')
   self.assertIsInstance(md.name, str)
   self.assertEquals(md.name, "testname")
   self.assertEquals(md.value, 13)
   self.assertEquals(md.start_time, 1234)
   self.assertIsNone(md.fields)
Beispiel #5
0
 def test_json_parsing_with_fields(self):
   md = common.json_to_metric_data('{"name": "testname", "value": 13, '
                                   '"myfield": "mystring", "otherfield": 42}')
   self.assertIsInstance(md.name, str)
   self.assertEquals(md.name, "testname")
   self.assertEquals(md.value, 13)
   self.assertIsNone(md.start_time)
   self.assertEquals(md.fields, {'myfield': 'mystring', 'otherfield': 42})
Beispiel #6
0
 def test_json_parsing_base64(self):
   json_str = ('{"name": "testname", "value": 13, '
               '"myfield": "mystring", "otherfield": 42}')
   json_base64 = base64.b64encode(json_str)
   md = common.json_to_metric_data(json_base64)
   self.assertIsInstance(md.name, str)
   self.assertEquals(md.name, "testname")
   self.assertEquals(md.points[0].value, 13)
   self.assertIsNone(md.start_time)
   self.assertEquals(md.points[0].fields,
                     {'myfield': 'mystring', 'otherfield': 42})
Beispiel #7
0
 def test_json_parsing_with_fields(self):
     md = common.json_to_metric_data(
         '{"name": "testname", "value": 13, '
         '"myfield": "mystring", "otherfield": 42}')
     self.assertIsInstance(md.name, str)
     self.assertEquals(md.name, "testname")
     self.assertEquals(md.points[0].value, 13)
     self.assertIsNone(md.start_time)
     self.assertEquals(md.points[0].fields, {
         'myfield': 'mystring',
         'otherfield': 42
     })
Beispiel #8
0
 def test_json_parsing_base64(self):
     json_str = ('{"name": "testname", "value": 13, '
                 '"myfield": "mystring", "otherfield": 42}')
     json_base64 = base64.b64encode(json_str)
     md = common.json_to_metric_data(json_base64)
     self.assertIsInstance(md.name, str)
     self.assertEquals(md.name, "testname")
     self.assertEquals(md.points[0].value, 13)
     self.assertIsNone(md.start_time)
     self.assertEquals(md.points[0].fields, {
         'myfield': 'mystring',
         'otherfield': 42
     })
Beispiel #9
0
 def test_json_parsing_bad_string(self):
     with self.assertRaises(ValueError):
         common.json_to_metric_data('}')
Beispiel #10
0
 def test_json_parsing_with_missing_value(self):
     with self.assertRaises(KeyError):
         common.json_to_metric_data(
             '{"name": "test/name", "start_time": 1234}')
Beispiel #11
0
 def test_json_parsing_invalid_json(self):
     with self.assertRaises(ValueError):
         common.json_to_metric_data('{"blah:')
Beispiel #12
0
 def test_json_parsing_bad_string(self):
   self.assertIsNone(common.json_to_metric_data('}'))
Beispiel #13
0
 def test_json_parsing_invalid_json(self):
   self.assertIsNone(common.json_to_metric_data('{"blah:'))
Beispiel #14
0
 def test_json_parsing_invalid_base64_2(self):
   # 'blah' does NOT raise TypeError in base64.b64decode
   self.assertIsNone(common.json_to_metric_data('blah'))
Beispiel #15
0
 def test_json_parsing_invalid_base64_1(self):
   # 'bd' raises TypeError in base64.b64decode
   self.assertIsNone(common.json_to_metric_data('bd'))
Beispiel #16
0
 def test_json_parsing_with_missing_value(self):
   with self.assertRaises(KeyError):
     common.json_to_metric_data('{"name": "test/name", "start_time": 1234}')
Beispiel #17
0
 def test_json_parsing_invalid_base64_2(self):
     # 'blah' does NOT raise TypeError in base64.b64decode
     with self.assertRaises(ValueError):
         common.json_to_metric_data('blah')
Beispiel #18
0
 def test_json_parsing_with_missing_value(self):
   self.assertIsNone(common.json_to_metric_data(
       '{"name": "test/name", "start_time": 1234}'))