grafana-toolbox / grafana-client

Python client library for accessing the Grafana HTTP API.
MIT License
101 stars 28 forks source link

Add support for Grafana library elements #168

Closed amotl closed 5 months ago

amotl commented 5 months ago

About

This patch adds support for Grafana's Library Elements, by @dameiss-tibco. Thanks!

References

amotl commented 5 months ago

Dear @Ousret, could you have a look what might be going on here? I guess it might be about some unfortunate interaction with the request mocker again. The quickest repro is:

python -m unittest -vvv -k test_get_library_element_by_name_notfound

Problem


======================================================================
ERROR: test_get_library_element_by_name_notfound (test.elements.test_libraryelement.LibraryElementTestCase.test_get_library_element_by_name_notfound)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/amo/dev/panodata/sources/grafana-client/.venv/lib/python3.11/site-packages/requests_mock/mocker.py", line 317, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/test/elements/test_libraryelement.py", line 720, in test_get_library_element_by_name_notfound
    self.grafana.libraryelement.get_library_element_by_name(LibraryElementTestCase.MissingPanelName)
  File "/Users/amo/dev/panodata/sources/grafana-client/grafana_client/elements/libraryelement.py", line 37, in get_library_element_by_name
    return self.client.GET(get_element_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/grafana_client/client.py", line 198, in __request_runner
    r = self.s.request(
        ^^^^^^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/.venv/lib/python3.11/site-packages/niquests/sessions.py", line 539, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/.venv/lib/python3.11/site-packages/requests_mock/mocker.py", line 185, in _fake_send
    return _original_send(session, request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/.venv/lib/python3.11/site-packages/niquests/sessions.py", line 1189, in send
    r._promise.set_parameter("niquests_is_stream", stream)
    ^^^^^^^^^^
  File "/Users/amo/dev/panodata/sources/grafana-client/.venv/lib/python3.11/site-packages/niquests/models.py", line 1028, in __getattribute__
    return super().__getattribute__(item)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Response' object has no attribute '_promise'

-- https://github.com/panodata/grafana-client/actions/runs/8480351660/job/23235924117?pr=168#step:7:509