Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ on:
jobs:
license_tests:
uses: neongeckocom/.github/.github/workflows/license_tests.yml@master
with:
packages-exclude: '^(neon-api-proxy|tqdm|attrs).*'
8 changes: 5 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ jobs:
- name: Export credentials
run: |
mkdir -p ~/.local/share/neon
echo ${WOLFRAM_ID} > ~/.local/share/neon/wolfram.txt
echo ${AV_API_KEY} > ~/.local/share/neon/alpha_vantage.txt
echo ${OWM_KEY} > ~/.local/share/neon/owm.txt
echo ${GENERIC_CONTROLLER_CONFIG} > ~/.local/share/neon/credentials.json
env:
WOLFRAM_ID: ${{secrets.wolfram_id}}
AV_API_KEY: ${{secrets.alpha_vantage_key}}
OWM_KEY: ${{secrets.open_weather_map_key}}
GENERIC_CONTROLLER_CONFIG: ${{secrets.generic_controller_config}}
Expand All @@ -62,6 +60,8 @@ jobs:
- name: Test Wolfram API
run: |
pytest tests/test_wolfram_api.py --doctest-modules --junitxml=tests/wolfram-api-test-results.xml
env:
WOLFRAM_APP_ID: ${{secrets.wolfram_id}}
- name: Upload Wolfram API test results
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -104,4 +104,6 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: generic-controller-test-results-${{matrix.python-version}}
path: tests/generic-controller-test-results.xml
path: tests/generic-controller-test-results.xml
env:
WOLFRAM_APP_ID: ${{secrets.wolfram_id}}
6 changes: 4 additions & 2 deletions neon_api_proxy/services/wolfram_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class WolframAPI(CachedAPI):
def __init__(self, api_key: str = None, cache_seconds: int = 3600, **_):
super().__init__("wolfram")
self._api_key = api_key or find_neon_wolfram_key()
if not self._api_key:
LOG.error("No Wolfram|Alpha API key provided!")
self.session.allowable_codes = (200, 501)
self.cache_time = timedelta(seconds=cache_seconds)

Expand All @@ -65,9 +67,9 @@ def _build_query_url(self, query_type: QueryUrl, query_arg: str) -> str:
:return: valid URL to query for a response
"""
if not query_type:
raise ValueError(f"query_type not defined!")
raise ValueError("query_type not defined!")
if not query_arg:
raise ValueError(f"query_url not defined!")
raise ValueError("query_url not defined!")
if not isinstance(query_type, QueryUrl):
raise TypeError(f"Not a QueryUrl: {query_arg}")
if not isinstance(query_arg, str):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cached_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_cached_request(self):
self.assertEqual(res.content, cached.content)

def test_request_no_cache(self):
url = "https://neon.ai"
url = "https://hana.neonaiservices.com/docs"
res = self.api.session.get(url, timeout=10)
with self.api.session.cache_disabled():
cached = self.api.session.get(url, timeout=10)
Expand All @@ -67,7 +67,7 @@ def test_get_with_cache_timeout(self):
self.assertFalse(expired.from_cache)

def test_get_bypass_cache(self):
url = "https://klat.com"
url = "https://hana.neonaibeta.com/docs"
res = self.api.get_with_cache_timeout(url)
self.assertFalse(res.from_cache)
cached = self.api.get_with_cache_timeout(url)
Expand Down
1 change: 1 addition & 0 deletions tests/test_generic_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_owm_forwarding(self):
self.assertIsNotNone(resp)
self.assertEqual(resp['status_code'], 200)

@unittest.skip("Redundant with OWM test")
def test_wolfram_forwarding(self):
resp = self.controller.resolve_query(VALID_WOLFRAM_QUERY)
self.assertIsNotNone(resp)
Expand Down
16 changes: 15 additions & 1 deletion tests/test_wolfram_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def test_handle_query_invalid_query(self):
self.assertEqual(resp["status_code"], -1)

def test_handle_query_invalid_response(self):
# Check that the API key is defined (troubleshooting failures)
self.assertIsInstance(self.api._api_key, str)
self.assertGreater(len(self.api._api_key), 0)
resp = self.api.handle_query(api="short",
query="i like",
units="metric",
Expand All @@ -154,14 +157,19 @@ def test_handle_query_invalid_key(self):

resp = self.api.handle_query(query="how far away is mars")
self.assertIsInstance(resp, dict)
self.assertEqual(resp["status_code"], 403)
# Response code should indicate a 4xx error for a bad request
self.assertGreaterEqual(resp["status_code"], 400)
self.assertLess(resp["status_code"], 500)
self.assertIsInstance(resp["content"], bytes)
self.assertIsInstance(resp["encoding"], str)
self.assertIsInstance(resp["content"].decode(resp["encoding"]), str)

self.api._api_key = valid_key

def test_handle_query_valid_ip(self):
# Check that the API key is defined (troubleshooting failures)
self.assertIsInstance(self.api._api_key, str)
self.assertGreater(len(self.api._api_key), 0)
resp = self.api.handle_query(api="short",
query="how far away is the moon?",
units="metric",
Expand All @@ -178,6 +186,9 @@ def test_handle_query_valid_ip(self):
self.assertEqual(resp, cached)

def test_handle_query_valid_lat_lng(self):
# Check that the API key is defined (troubleshooting failures)
self.assertIsInstance(self.api._api_key, str)
self.assertGreater(len(self.api._api_key), 0)
resp = self.api.handle_query(api="short",
query="how far away is the moon?",
units="metric",
Expand All @@ -190,6 +201,9 @@ def test_handle_query_valid_lat_lng(self):
self.assertIsInstance(resp["content"].decode(resp["encoding"]), str)

def test_handle_query_valid_latlong(self):
# Check that the API key is defined (troubleshooting failures)
self.assertIsInstance(self.api._api_key, str)
self.assertGreater(len(self.api._api_key), 0)
resp = self.api.handle_query(api="short",
query="how far away is the moon?",
units="metric",
Expand Down
Loading