Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5110d3

Browse files
committed
Add 🐅s for schema caching.
1 parent ebccd14 commit b5110d3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
A module to test functionality related to *using* the graph reference.
3+
4+
"""
5+
from __future__ import absolute_import
6+
7+
from plotly import exceptions, files, graph_reference as gr, tools, utils
8+
from plotly.tests.utils import PlotlyTestCase
9+
10+
11+
class TestGraphReferenceCaching(PlotlyTestCase):
12+
13+
def set_graph_reference(self, graph_reference):
14+
if files.check_file_permissions():
15+
utils.save_json_dict(files.GRAPH_REFERENCE_FILE, graph_reference)
16+
17+
def test_get_graph_reference_outdated(self):
18+
19+
# if the hash of the current graph reference doesn't match the hash of
20+
# the graph reference a Plotly server has, we should update!
21+
22+
outdated_graph_reference = {'real': 'old'}
23+
self.set_graph_reference(outdated_graph_reference)
24+
graph_reference = gr.get_graph_reference()
25+
self.assertNotEqual(graph_reference, outdated_graph_reference)
26+
27+
def test_get_graph_reference_bad_request_local_copy(self):
28+
29+
# if the request fails (mocked by using a bad url here) and a local
30+
# copy of the graph reference exists, we can just use that.
31+
32+
tools.set_config_file(plotly_api_domain='api.am.not.here.ly')
33+
local_graph_reference = {'real': 'local'}
34+
self.set_graph_reference(local_graph_reference)
35+
graph_reference = gr.get_graph_reference()
36+
self.assertEqual(graph_reference, local_graph_reference)
37+
38+
def test_get_graph_reference_bad_request_no_copy(self):
39+
40+
# if we don't have a graph reference we *have* to error, no choice :(
41+
42+
tools.set_config_file(plotly_api_domain='api.am.not.here.ly')
43+
empty_graph_reference = {} # set it to a false-y value.
44+
self.set_graph_reference(empty_graph_reference)
45+
with self.assertRaisesRegexp(exceptions.PlotlyError, 'schema'):
46+
gr.get_graph_reference()

0 commit comments

Comments
 (0)