diff --git a/.travis.yml b/.travis.yml index 7ed2682..168115d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ python: install: - pip install -r requirements.txt script: -- pytest +- pytest -vv --cov=./ --cov-report=xml +- codecov - make clean docs dist deploy: provider: pypi @@ -15,6 +16,4 @@ deploy: on: tags: true distributions: sdist bdist_wheel - repo: ohmrefresh/GrafanaSnapshot -after_success: - - codecov \ No newline at end of file + repo: ohmrefresh/GrafanaSnapshot \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5909609..6cc2408 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ python-dotenv pytest grafana_api codecov +pytest-cov requests_mock diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index fb3b5bd..ed5e74b 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -61,6 +61,60 @@ def test_generate(self, m): results = grafana.generate(tags="test_tag", time_from=1563183710618, time_to=1563185212275) self.assertEqual(len(results), 1) + @requests_mock.Mocker() + def test_generate_with_expire(self, m): + m.get( + "http://localhost:3000/api/search?tag=test_tag", + json=[ + { + "id": 163, + "uid": "cIBgcSjkk", + "title": "Folder", + "url": "/dashboards/f/000000163/folder", + "type": "dash-folder", + "tags": [], + "isStarred": 'false', + "uri": "db/folder" + } + ] + ) + m.get( + "http://localhost:3000/api/dashboards/uid/cIBgcSjkk", + json={ + "dashboard": { + "id": 1, + "uid": "cIBgcSjkk", + "title": "Production Overview", + "tags": ["templated"], + "timezone": "browser", + "schemaVersion": 16, + "version": 0, + "time": { + "from": "now-15m", + "to": "now" + } + }, + "meta": { + "isStarred": 'false', + "url": "/d/cIBgcSjkk/production-overview", + "slug": "production-overview" + } + } + ) + m.post( + "http://localhost:3000/api/snapshots", + json={ + "deleteKey": "XXXXXXX", + "deleteUrl": "myurl/api/snapshots.py-delete/XXXXXXX", + "key": "YYYYYYY", + "url": "myurl/dashboard/snapshot/YYYYYYY" + }, + ) + + grafana = GenerateSnapshot(auth="xxxxx", port=3000, host="localhost", protocol="http") + results = grafana.generate(tags="test_tag", time_from=1563183710618, time_to=1563185212275, expires=500) + self.assertEqual(len(results), 1) + if __name__ == "__main__": import xmlrunner