Ejemplo n.º 1
0
 def test_new_stream_with_composite(self):
     chart = Chart(self.conn)
     composite_formula = 's("my.metric", "*")'
     stream = chart.new_stream(composite=composite_formula)
     self.assertIsNone(stream.metric)
     self.assertIsNone(stream.source)
     self.assertEqual(stream.composite, composite_formula)
Ejemplo n.º 2
0
 def test_save_persists_related_space(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.related_space)
     chart.related_space = 1234
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.related_space)
Ejemplo n.º 3
0
 def test_save_persists_label(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.label)
     chart.label = 'my label'
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertEqual(found.label, 'my label')
Ejemplo n.º 4
0
 def test_save_persists_log_y_axis(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.use_log_yaxis)
     chart.use_log_yaxis = True
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.use_log_yaxis)
Ejemplo n.º 5
0
 def test_save_persists_type(self):
     # Ensure that type gets passed in the payload
     for t in ['stacked', 'bignumber']:
         chart = Chart(self.conn, space_id=self.space.id, type=t)
         chart.save()
         found = self.conn.get_chart(chart.id, self.space.id)
         self.assertEqual(found.type, t)
Ejemplo n.º 6
0
 def test_save_persists_related_space(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.related_space)
     chart.related_space = 1234
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.related_space)
Ejemplo n.º 7
0
 def test_new_stream_with_composite(self):
     chart = Chart(self.conn)
     composite_formula = 's("my.metric", "*")'
     stream = chart.new_stream(composite=composite_formula)
     self.assertIsNone(stream.metric)
     self.assertIsNone(stream.source)
     self.assertEqual(stream.composite, composite_formula)
Ejemplo n.º 8
0
 def test_save_persists_log_y_axis(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.use_log_yaxis)
     chart.use_log_yaxis = True
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.use_log_yaxis)
Ejemplo n.º 9
0
 def test_save_persists_use_last_value(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.use_last_value)
     chart.use_last_value = True
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.use_last_value)
Ejemplo n.º 10
0
 def test_save_persists_label(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.label)
     chart.label = 'my label'
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertEqual(found.label, 'my label')
Ejemplo n.º 11
0
 def test_streams_payload(self):
     streams_payload = [
       {'metric': 'some.metric', 'source': None, 'composite': None},
       {'metric': None, 'source': None, 'composite': 's("other.metric", "sf", {function: "sum"})'}
     ]
     chart = Chart(self.conn, streams=streams_payload)
     self.assertEqual(chart.streams_payload()[0]['metric'], streams_payload[0]['metric'])
Ejemplo n.º 12
0
 def test_save_persists_type(self):
     # Ensure that type gets passed in the payload
     for t in ['stacked', 'bignumber']:
         chart = Chart(self.conn, space_id=self.space.id, type=t)
         chart.save()
         found = self.conn.get_chart(chart.id, self.space.id)
         self.assertEqual(found.type, t)
Ejemplo n.º 13
0
 def test_save_persists_use_last_value(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.use_last_value)
     chart.use_last_value = True
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertTrue(found.use_last_value)
Ejemplo n.º 14
0
 def test_save_chart(self):
     chart = Chart(self.conn, 'test', space_id=self.space.id)
     self.assertFalse(chart.persisted())
     self.assertIsNone(chart.id)
     resp = chart.save()
     self.assertIsInstance(resp, Chart)
     self.assertTrue(chart.persisted())
     self.assertIsNotNone(chart.id)
     self.assertEqual(chart.type, 'line')
Ejemplo n.º 15
0
 def test_get_payload_bignumber(self):
     streams = [{'metric': 'my.metric', 'source': '*'}]
     chart = Chart(self.conn, type='bignumber', streams=streams,
         use_last_value=False)
     payload = chart.get_payload()
     self.assertEqual(payload['name'], chart.name)
     self.assertEqual(payload['type'], chart.type)
     self.assertEqual(payload['streams'], streams)
     self.assertEqual(payload['use_last_value'], chart.use_last_value)
Ejemplo n.º 16
0
 def test_save_chart(self):
     chart = Chart(self.conn, 'test', space_id=self.space.id)
     self.assertFalse(chart.persisted())
     self.assertIsNone(chart.id)
     resp = chart.save()
     self.assertIsInstance(resp, Chart)
     self.assertTrue(chart.persisted())
     self.assertIsNotNone(chart.id)
     self.assertEqual(chart.type, 'line')
Ejemplo n.º 17
0
 def test_get_payload_with_streams_dict(self):
     streams_payload = [
       {'metric': 'some.metric', 'source': None, 'composite': None},
       {'metric': 'another.metric', 'source': None, 'composite': None}
     ]
     chart = Chart(self.conn, type='bignumber', space_id=42, streams=streams_payload)
     chart_payload = chart.get_payload()
     self.assertEqual(chart_payload['streams'][0]['metric'], streams_payload[0]['metric'])
     self.assertEqual(chart_payload['streams'][1]['metric'], streams_payload[1]['metric'])
Ejemplo n.º 18
0
 def test_new_stream_with_source(self):
     chart = Chart(self.conn, 'test')
     stream = chart.new_stream('my.metric', 'prod*')
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, 'prod*')
     self.assertEqual(stream.composite, None)
     stream = chart.new_stream(metric='my.metric', source='prod*')
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, 'prod*')
     self.assertEqual(stream.composite, None)
Ejemplo n.º 19
0
 def test_save_persists_min_max(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.min)
     self.assertIsNone(chart.max)
     chart.min = 5
     chart.max = 30
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertEqual(found.min, 5)
     self.assertEqual(found.max, 30)
Ejemplo n.º 20
0
 def test_new_stream_with_source(self):
     chart = Chart(self.conn, 'test')
     stream = chart.new_stream('my.metric', 'prod*')
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, 'prod*')
     self.assertEqual(stream.composite, None)
     stream = chart.new_stream(metric='my.metric', source='prod*')
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, 'prod*')
     self.assertEqual(stream.composite, None)
Ejemplo n.º 21
0
 def test_get_payload_bignumber(self):
     streams = [{'metric': 'my.metric', 'source': '*'}]
     chart = Chart(self.conn,
                   type='bignumber',
                   streams=streams,
                   use_last_value=False)
     payload = chart.get_payload()
     self.assertEqual(payload['name'], chart.name)
     self.assertEqual(payload['type'], chart.type)
     self.assertEqual(payload['streams'], streams)
     self.assertEqual(payload['use_last_value'], chart.use_last_value)
Ejemplo n.º 22
0
 def test_new_stream_defaults(self):
     chart = Chart(self.conn, 'test')
     self.assertEqual(len(chart.streams), 0)
     stream = chart.new_stream('my.metric')
     self.assertIsInstance(stream, Stream)
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, '*')
     self.assertEqual(stream.composite, None)
     # Appends to chart streams
     self.assertEqual(len(chart.streams), 1)
     self.assertEqual(chart.streams[0].metric, 'my.metric')
     # Another way to do the same thing
     stream = chart.new_stream(metric='my.metric')
     self.assertEqual(stream.metric, 'my.metric')
Ejemplo n.º 23
0
 def test_new_stream_defaults(self):
     chart = Chart(self.conn, 'test')
     self.assertEqual(len(chart.streams), 0)
     stream = chart.new_stream('my.metric')
     self.assertIsInstance(stream, Stream)
     self.assertEqual(stream.metric, 'my.metric')
     self.assertEqual(stream.source, '*')
     self.assertEqual(stream.composite, None)
     # Appends to chart streams
     self.assertEqual(len(chart.streams), 1)
     self.assertEqual(chart.streams[0].metric, 'my.metric')
     # Another way to do the same thing
     stream = chart.new_stream(metric='my.metric')
     self.assertEqual(stream.metric, 'my.metric')
Ejemplo n.º 24
0
 def test_streams_payload(self):
     streams_payload = [{
         'metric': 'some.metric',
         'source': None,
         'composite': None
     }, {
         'metric':
         None,
         'source':
         None,
         'composite':
         's("other.metric", "sf", {function: "sum"})'
     }]
     chart = Chart(self.conn, streams=streams_payload)
     self.assertEqual(chart.streams_payload()[0]['metric'],
                      streams_payload[0]['metric'])
Ejemplo n.º 25
0
 def test_get_payload_with_streams_dict(self):
     streams_payload = [{
         'metric': 'some.metric',
         'source': None,
         'composite': None
     }, {
         'metric': 'another.metric',
         'source': None,
         'composite': None
     }]
     chart = Chart(self.conn,
                   type='bignumber',
                   space_id=42,
                   streams=streams_payload)
     chart_payload = chart.get_payload()
     self.assertEqual(chart_payload['streams'][0]['metric'],
                      streams_payload[0]['metric'])
     self.assertEqual(chart_payload['streams'][1]['metric'],
                      streams_payload[1]['metric'])
Ejemplo n.º 26
0
 def test_init_streams_group_functions(self):
     streams_dict = [{
         'metric': 'my.metric',
         'source': '*',
         'group_function': 'sum',
         'summary_function': 'max'
     }]
     chart = Chart(self.conn, streams=streams_dict)
     stream = chart.streams[0]
     self.assertEqual(stream.group_function, 'sum')
     self.assertEqual(stream.summary_function, 'max')
Ejemplo n.º 27
0
 def test_save_persists_min_max(self):
     chart = Chart(self.conn, space_id=self.space.id)
     self.assertIsNone(chart.min)
     self.assertIsNone(chart.max)
     chart.min = 5
     chart.max = 30
     chart.save()
     found = self.conn.get_chart(chart.id, self.space.id)
     self.assertEqual(found.min, 5)
     self.assertEqual(found.max, 30)
Ejemplo n.º 28
0
 def test_init_streams_dict(self):
     streams_dict = [{
         'metric': 'my.metric',
         'source': 'blah',
         'composite': None
     }, {
         'metric': 'other.metric',
         'source': '*',
         'composite': None
     }]
     chart = Chart(self.conn, streams=streams_dict)
     self.assertEqual(chart.streams[0].metric, streams_dict[0]['metric'])
     self.assertEqual(chart.streams[0].source, streams_dict[0]['source'])
     self.assertEqual(chart.streams[0].composite,
                      streams_dict[0]['composite'])
     self.assertEqual(chart.streams[1].metric, streams_dict[1]['metric'])
     self.assertEqual(chart.streams[1].source, streams_dict[1]['source'])
     self.assertEqual(chart.streams[1].composite,
                      streams_dict[1]['composite'])
Ejemplo n.º 29
0
 def test_get_space_from_chart(self):
     chart = Chart(self.conn, space_id=self.space.id)
     space = chart.space()
     self.assertIsInstance(space, Space)
     self.assertEqual(space.id, self.space.id)
Ejemplo n.º 30
0
 def test_get_space_from_chart(self):
     chart = Chart(self.conn, space_id=self.space.id)
     space = chart.space()
     self.assertIsInstance(space, Space)
     self.assertEqual(space.id, self.space.id)
Ejemplo n.º 31
0
 def test_chart_is_persisted_if_id_present(self):
     chart = Chart(self.conn, 'test', id=42)
     self.assertTrue(chart.persisted())
     chart = Chart(self.conn, 'test', id=None)
     self.assertFalse(chart.persisted())
Ejemplo n.º 32
0
 def test_chart_is_not_persisted(self):
     chart = Chart('not saved', self.space)
     self.assertFalse(chart.persisted())
Ejemplo n.º 33
0
 def test_get_payload(self):
     chart = Chart(self.conn)
     payload = chart.get_payload()
     self.assertEqual(payload['name'], chart.name)
     self.assertEqual(payload['type'], chart.type)
     self.assertEqual(payload['streams'], chart.streams)
Ejemplo n.º 34
0
 def test_get_payload(self):
     chart = Chart(self.conn)
     payload = chart.get_payload()
     self.assertEqual(payload['name'], chart.name)
     self.assertEqual(payload['type'], chart.type)
     self.assertEqual(payload['streams'], chart.streams)
Ejemplo n.º 35
0
 def test_init_chart_type(self):
     # Debated `chart_type` vs `type`, going with `type`
     self.assertEqual(Chart(self.conn, type='line').type, 'line')
     self.assertEqual(Chart(self.conn, type='stacked').type, 'stacked')
     self.assertEqual(Chart(self.conn, type='bignumber').type, 'bignumber')
Ejemplo n.º 36
0
 def test_init_space_id(self):
     self.assertEqual(Chart(self.conn, space_id=42).space_id, 42)
Ejemplo n.º 37
0
 def test_init_use_log_yaxis(self):
     chart = Chart(self.conn, use_log_yaxis=True)
     self.assertTrue(chart.use_log_yaxis)
Ejemplo n.º 38
0
 def test_init_label(self):
     chart = Chart(self.conn, label='I heart charts')
     self.assertEqual(chart.label, 'I heart charts')
Ejemplo n.º 39
0
 def test_init_min_max(self):
     chart = Chart(self.conn, min=-42, max=100)
     self.assertEqual(chart.min, -42)
     self.assertEqual(chart.max, 100)
Ejemplo n.º 40
0
 def test_chart_is_persisted_if_id_present(self):
     chart = Chart(self.conn, 'test', id=42)
     self.assertTrue(chart.persisted())
     chart = Chart(self.conn, 'test', id=None)
     self.assertFalse(chart.persisted())
Ejemplo n.º 41
0
 def test_init_name(self):
     self.assertIsNone(Chart(self.conn).name)
     self.assertEqual(Chart(self.conn, 'cpu').name, 'cpu')
Ejemplo n.º 42
0
 def test_chart_is_not_persisted(self):
     chart = Chart('not saved', self.space)
     self.assertFalse(chart.persisted())
Ejemplo n.º 43
0
 def test_init_connection(self):
     self.assertEqual(Chart(self.conn).connection, self.conn)
Ejemplo n.º 44
0
 def test_space_attribute(self):
     chart = Chart(self.conn)
     chart._space = self.space
     self.assertEqual(chart._space, self.space)
Ejemplo n.º 45
0
 def test_init_streams_list(self):
     streams_list = [['my.metric', '*', None]]
     chart = Chart(self.conn, streams=streams_list)
     self.assertEqual(chart.streams[0].metric, streams_list[0][0])
Ejemplo n.º 46
0
    def test_init_streams(self):
        self.assertEqual(Chart(self.conn).streams, [])

        s = [Stream('my.metric'), Stream('other.metric')]
        chart = Chart(self.conn, streams=s)
        self.assertEqual(chart.streams, s)
Ejemplo n.º 47
0
 def test_space_attribute(self):
     chart = Chart(self.conn)
     chart._space = self.space
     self.assertEqual(chart._space, self.space)