Fix bug when passing url and key into grafana
Sadly, our unit tests missed this. Since we didn't actually test the contents of the values. We have now fixed that with some unit tests. Change-Id: Ida72768b51cb579fedb740f54d6f764e14f9d3d0 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
d745eb483f
commit
bec5312d99
@ -29,7 +29,8 @@ class Builder(object):
|
||||
config.get('cache', 'cachedir'),
|
||||
config.getboolean('cache', 'enabled'))
|
||||
self.grafana = Grafana(
|
||||
config.get('grafana', 'apikey'), config.get('grafana', 'url'))
|
||||
url=config.get('grafana', 'url'),
|
||||
key=config.get('grafana', 'apikey'))
|
||||
self.parser = YamlParser()
|
||||
|
||||
def delete_dashboard(self, path):
|
||||
|
@ -33,8 +33,10 @@ class Grafana(object):
|
||||
:type key: str
|
||||
|
||||
"""
|
||||
self.server = url
|
||||
self.auth = None
|
||||
|
||||
base_url = urljoin(url, 'api/dashboards/db/')
|
||||
base_url = urljoin(self.server, 'api/dashboards/db/')
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
'Content-Type': 'application/json',
|
||||
@ -42,8 +44,7 @@ class Grafana(object):
|
||||
# NOTE(pabelanger): Grafana 2.1.0 added basic auth support so now the
|
||||
# api key is optional.
|
||||
if key:
|
||||
session.headers.update({
|
||||
'Authorization': 'Bearer %s' % key,
|
||||
})
|
||||
self.auth = {'Authorization': 'Bearer %s' % key}
|
||||
session.headers.update(self.auth)
|
||||
|
||||
self.dashboard = Dashboard(base_url, session)
|
||||
|
@ -39,6 +39,11 @@ class TestCaseBuilder(TestCase):
|
||||
builder2.delete_dashboard(path)
|
||||
self.assertEqual(mock_grafana.call_count, 1)
|
||||
|
||||
def test_grafana_defaults(self):
|
||||
self.assertEqual(
|
||||
self.builder.grafana.server, 'http://grafana.example.org')
|
||||
self.assertEqual(self.builder.grafana.auth, None)
|
||||
|
||||
@mock.patch('grafana_dashboards.grafana.Dashboard.create')
|
||||
def test_update_dashboard(self, mock_grafana):
|
||||
path = os.path.join(
|
||||
|
Loading…
x
Reference in New Issue
Block a user