File: test_query.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 (27 lines) | stat: -rw-r--r-- 1,125 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
from azure.loganalytics import LogAnalyticsDataClient
from azure.loganalytics.models import QueryBody
from devtools_testutils import AzureMgmtTestCase

class LogAnalyticsQueryTest(AzureMgmtTestCase):
    def setUp(self):
        super(LogAnalyticsQueryTest, self).setUp()
        self.client = self.create_basic_client(LogAnalyticsDataClient) 

    def test_query(self):
        query = 'Heartbeat | take 10'
        workspace = 'DEMO_WORKSPACE'
        result = self.client.query(workspace, QueryBody(**{'query': query}))
        print(result.tables[0].columns)
        print(result.tables[0].rows[0])
        # All queries should return at least a table.
        self.assertGreaterEqual(len(result.tables), 1)

        # Heartbeat table schema has 29 columns.
        self.assertEqual(len(result.tables[0].columns), 29)

        # The workspace should contain enough data to retrieve 10 rows, as asked
        self.assertEqual(len(result.tables[0].rows), 10)

        # Validate deserialization
        self.assertIs(type(result.tables[0].rows[0][16]), float)
        self.assertIs(type(result.tables[0].rows[0][15]), bool)