From 648a4b5aac41f966d2c98effb67043651f9dc6b5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 18 Jan 2016 16:21:00 -0500 Subject: [PATCH] For tests, also disable the API key. This is the API key that was seeing high usage. --- CHANGES.rst | 4 ++++ wolframalpha/test_client.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2db98ef..3fa5474 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,10 @@ removed and will be de-activated. Users must register for their own key at the `Wolfram|Alpha developer web site `_. +Additionally, the tests now no longer bundle a hard-coded API +key. Instead, to run the tests, one must supply a +``WOLFRAMALPHA_API_KEY`` environment variable. + 1.4 === diff --git a/wolframalpha/test_client.py b/wolframalpha/test_client.py index 17b05b7..c017d6f 100644 --- a/wolframalpha/test_client.py +++ b/wolframalpha/test_client.py @@ -2,15 +2,28 @@ from __future__ import unicode_literals +import os + import pytest import wolframalpha -app_id = 'Q59EW4-7K8AHE858R' -"App ID for testing this project. Please don't use for other apps." -def test_basic(): - client = wolframalpha.Client(app_id) +@pytest.fixture +def API_key(): + """ + To run the tests fully, the environment must be configured + with a WOLFRAMALPHA_API_KEY environment variable. Otherwise, + skip them. + """ + try: + return os.environ['WOLFRAMALPHA_API_KEY'] + except KeyError: + pytest.skip("Need WOLFRAMALPHA_API_KEY in environment") + + +def test_basic(API_key): + client = wolframalpha.Client(API_key) res = client.query('30 deg C in deg F') assert len(res.pods) > 0 results = list(res.results)