File: test_diagnostics.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 (51 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (2)
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
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'

class BaseUnitTests(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 pytest.raises(AttributeError):
            rh.other