File: test_diagnostics.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (61 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# The MIT License (MIT)
# Copyright (c) Microsoft Corporation. All rights reserved.

import unittest

import pytest

import azure.cosmos.diagnostics as m

_common = {
    'x-ms-activity-id',
    'x-ms-session-token',
    'x-ms-item-count',
    'x-ms-request-quota',
    'x-ms-resource-usage',
    'x-ms-retry-after-ms',
}

_headers = dict(zip(_common, _common))
_headers['other'] = 'other'


@pytest.mark.cosmosEmulator
class TestOldDiagnostics(unittest.TestCase):

    def test_init(self):
        rh = m.RecordDiagnostics()
        assert rh.headers == {}

    def test_headers(self):
        rh = m.RecordDiagnostics()
        rh(_headers, "body")
        assert rh.headers == _headers
        assert rh.headers is not _headers

    def test_headers_case(self):
        rh = m.RecordDiagnostics()
        rh(_headers, "body")
        rh_headers = rh.headers
        for key in rh.headers.keys():
            assert key.upper() in rh_headers
            assert key.lower() in rh_headers

    def test_common_attrs(self):
        rh = m.RecordDiagnostics()
        rh(_headers, "body")
        for name in _common:
            assert rh.headers[name] == name
            attr = name.replace('x-ms-', '').replace('-', '_')
            assert getattr(rh, attr) == name

    def test_other_attrs(self):
        rh = m.RecordDiagnostics()
        rh(_headers, "body")
        assert rh.headers['other'] == 'other'
        with self.assertRaises(AttributeError):
            rh.other


if __name__ == '__main__':
    unittest.main()