Add test coverate for grafana.py
Previous to this we actually didn't install our requests dependency. So grafyaml actually didn't work :( Now we have basic coverage with mock. Change-Id: I771ea12e444ea851d76983df75f69d1569653f9d Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
a04ac20eaa
commit
29c17b9d23
@ -5,4 +5,5 @@
|
|||||||
oslo.config>=1.11.0
|
oslo.config>=1.11.0
|
||||||
oslo.log>=1.0.0,<1.1.0
|
oslo.log>=1.0.0,<1.1.0
|
||||||
PyYAML>=3.1.0
|
PyYAML>=3.1.0
|
||||||
|
requests
|
||||||
voluptuous>=0.7
|
voluptuous>=0.7
|
||||||
|
@ -7,6 +7,7 @@ hacking<0.11,>=0.10.0
|
|||||||
coverage>=3.6
|
coverage>=3.6
|
||||||
discover
|
discover
|
||||||
python-subunit>=0.0.18
|
python-subunit>=0.0.18
|
||||||
|
requests-mock>=0.6.0
|
||||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||||
oslosphinx>=2.2.0 # Apache-2.0
|
oslosphinx>=2.2.0 # Apache-2.0
|
||||||
oslotest>=1.2.0 # Apache-2.0
|
oslotest>=1.2.0 # Apache-2.0
|
||||||
|
46
tests/test_grafana.py
Normal file
46
tests/test_grafana.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Copyright 2015 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from requests_mock.contrib import fixture as rm_fixture
|
||||||
|
from testtools import TestCase
|
||||||
|
|
||||||
|
from grafana_dashboards import grafana
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseGrafana(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestCaseGrafana, self).setUp()
|
||||||
|
self.apikey = 'eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk'
|
||||||
|
self.url = 'http://localhost'
|
||||||
|
self.grafana = grafana.Grafana(self.url, self.apikey)
|
||||||
|
|
||||||
|
def test_create_dashboard(self):
|
||||||
|
mock_requests = self.useFixture(rm_fixture.Fixture())
|
||||||
|
mock_requests.post('/api/dashboards/db')
|
||||||
|
data = {
|
||||||
|
"dashboard": {
|
||||||
|
"title": "New dashboard",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.grafana.create_dashboard(data)
|
||||||
|
self.assertEqual(mock_requests.call_count, 1)
|
||||||
|
headers = mock_requests.last_request.headers
|
||||||
|
self._test_headers(headers)
|
||||||
|
|
||||||
|
def _test_headers(self, headers):
|
||||||
|
self.assertIn('Authorization', headers)
|
||||||
|
self.assertEqual(headers['Authorization'], 'Bearer %s' % self.apikey)
|
||||||
|
self.assertIn('Content-Type', headers)
|
||||||
|
self.assertEqual(headers['Content-Type'], 'application/json')
|
Loading…
Reference in New Issue
Block a user