diff --git a/plotly/graph_reference.py b/plotly/graph_reference.py index 7e5d0cd6e82..9fb10a03eac 100644 --- a/plotly/graph_reference.py +++ b/plotly/graph_reference.py @@ -15,9 +15,6 @@ from plotly import files, utils -GRAPH_REFERENCE_PATH = '/v2/plot-schema' -GRAPH_REFERENCE_DOWNLOAD_TIMEOUT = 5 # seconds - # For backwards compat, we keep this list of previously known objects. # Moving forward, we only add new trace names. @@ -65,46 +62,16 @@ def get_graph_reference(): """ - Attempts to load local copy of graph reference or makes GET request if DNE. + Load graph reference JSON (aka plot-schema) :return: (dict) The graph reference. :raises: (PlotlyError) When graph reference DNE and GET request fails. """ - default_config = files.FILE_CONTENT[files.CONFIG_FILE] - if files.check_file_permissions(): - graph_reference = utils.load_json_dict(files.GRAPH_REFERENCE_FILE) - config = utils.load_json_dict(files.CONFIG_FILE) - - # TODO: https://github.com/plotly/python-api/issues/293 - plotly_api_domain = config.get('plotly_api_domain', - default_config['plotly_api_domain']) - else: - graph_reference = {} - plotly_api_domain = default_config['plotly_api_domain'] - - sha1 = hashlib.sha1(six.b(str(graph_reference))).hexdigest() - - graph_reference_url = '{}{}?sha1={}'.format(plotly_api_domain, - GRAPH_REFERENCE_PATH, sha1) - - try: - response = requests.get(graph_reference_url, - timeout=GRAPH_REFERENCE_DOWNLOAD_TIMEOUT) - response.raise_for_status() - except requests.exceptions.RequestException: - if not graph_reference: - path = os.path.join('graph_reference', 'default-schema.json') - s = resource_string('plotly', path).decode('utf-8') - graph_reference = json.loads(s) - else: - if six.PY3: - content = str(response.content, encoding='utf-8') - else: - content = response.content - data = json.loads(content) - if data['modified']: - graph_reference = data['schema'] + + path = os.path.join('graph_reference', 'default-schema.json') + s = resource_string('plotly', path).decode('utf-8') + graph_reference = json.loads(s) return utils.decode_unicode(graph_reference) diff --git a/plotly/tests/test_core/test_graph_reference/test_graph_reference.py b/plotly/tests/test_core/test_graph_reference/test_graph_reference.py index 38ac0b872b7..5beab1afc2e 100644 --- a/plotly/tests/test_core/test_graph_reference/test_graph_reference.py +++ b/plotly/tests/test_core/test_graph_reference/test_graph_reference.py @@ -24,29 +24,7 @@ def set_graph_reference(self, graph_reference): if files.check_file_permissions(): utils.save_json_dict(files.GRAPH_REFERENCE_FILE, graph_reference) - @attr('slow') - def test_get_graph_reference_outdated(self): - - # if the hash of the current graph reference doesn't match the hash of - # the graph reference a Plotly server has, we should update! - - outdated_graph_reference = {'real': 'old'} - self.set_graph_reference(outdated_graph_reference) - graph_reference = gr.get_graph_reference() - self.assertNotEqual(graph_reference, outdated_graph_reference) - - def test_get_graph_reference_bad_request_local_copy(self): - - # if the request fails (mocked by using a bad url here) and a local - # copy of the graph reference exists, we can just use that. - - tools.set_config_file(plotly_api_domain='api.am.not.here.ly') - local_graph_reference = {'real': 'local'} - self.set_graph_reference(local_graph_reference) - graph_reference = gr.get_graph_reference() - self.assertEqual(graph_reference, local_graph_reference) - - def test_get_graph_reference_bad_request_no_copy(self): + def test_get_graph_reference(self): # if we don't have a graph reference we load an outdated default @@ -59,29 +37,6 @@ def test_get_graph_reference_bad_request_no_copy(self): graph_reference = gr.get_graph_reference() self.assertEqual(graph_reference, default_graph_reference) - @attr('slow') - def test_default_schema_is_up_to_date(self): - api_domain = files.FILE_CONTENT[files.CONFIG_FILE]['plotly_api_domain'] - graph_reference_url = '{}{}?sha1'.format(api_domain, - gr.GRAPH_REFERENCE_PATH) - response = requests.get(graph_reference_url) - if six.PY3: - content = str(response.content, encoding='utf-8') - else: - content = response.content - schema = json.loads(content)['schema'] - - path = os.path.join('graph_reference', 'default-schema.json') - s = resource_string('plotly', path).decode('utf-8') - default_schema = json.loads(s) - - msg = ( - 'The default, hard-coded plot schema we ship with pip is out of ' - 'sync with the prod plot schema!\n' - 'Run `make update_default_schema` to fix it!' - ) - self.assertEqual(schema, default_schema, msg=msg) - class TestStringToClass(PlotlyTestCase):