File: disable_test_metrics.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (43 lines) | stat: -rw-r--r-- 2,167 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from azure.applicationinsights import ApplicationInsightsDataClient
from azure.applicationinsights.models import MetricsPostBodySchema, MetricsPostBodySchemaParameters
from devtools_testutils import AzureMgmtTestCase

class ApplicationInsightsMetricsTest(AzureMgmtTestCase):
    def setUp(self):
        super(ApplicationInsightsMetricsTest, self).setUp()
        self.client = self.create_basic_client(ApplicationInsightsDataClient) 
        self.application = 'DEMO_APP'

    def test_metrics_get(self):
        metricId = 'availabilityResults/count'
        result = self.client.metrics.get(self.application, metricId)
        self.assertIsNotNone(result.value)
        props = ['start', 'end']
        for prop in props:
            self.assertTrue(hasattr(result.value, prop))
        noneProps = ['interval', 'segments']
        self.assertIsNotNone(result.value.additional_properties['availabilityResults/count']['sum'])
    
    def test_metrics_get_multiple(self):
        metrics = [
            MetricsPostBodySchema(id='1', parameters=MetricsPostBodySchemaParameters(metric_id='availabilityResults/count', timespan='P2DT12H')),
            MetricsPostBodySchema(id='two', parameters=MetricsPostBodySchemaParameters(metric_id='availabilityResults/duration'))
        ]
        result = self.client.metrics.get_multiple(self.application, metrics)
        self.assertEqual(len(result), 2)
        props = ['start', 'end']
        for prop in props:
            for item in result:
                self.assertTrue(hasattr(item.body.value, prop))
        noneProps = ['interval', 'segments']
        self.assertIsNotNone(result[0].body.value.additional_properties['availabilityResults/count']['sum'])

    def test_metrics_get_metadata(self):
        result = self.client.metrics.get_metadata(self.application)
        props = ['metrics', 'dimensions']
        for prop in props:
            self.assertIsNotNone(result[prop])
        reqProps = ['requests/count', 'users/authenticated']
        for prop in reqProps:
            self.assertIsNotNone(result['metrics'][prop])
        self.assertIsNotNone(result['dimensions']['request/source']['displayName'])