Skip to content

Commit

Permalink
Update Python versions in tests (#540)
Browse files Browse the repository at this point in the history
* Update tests to remove Python 3.7 and add 3.11-3.12

* Remove python 3.12 tests because `setuptools` was removed from stdlib

* Update tests to account for actual behavior (expired tokens are quietly refreshed)
#538 added these tests and NeonGeckoCom/neon-hana#35 resolved the reason this test previously raised an exception
  • Loading branch information
NeonDaniel authored Jan 14, 2025
1 parent 7c84434 commit 92c7c8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
skill_object_tests:
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, '3.10' ]
python-version: [ 3.8, 3.9, '3.10', '3.11' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
unit_tests:
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']
python-version: [ 3.8, 3.9, '3.10', '3.11' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
29 changes: 18 additions & 11 deletions tests/hana_util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
from time import time, sleep
from unittest.mock import patch


valid_config = {}
valid_headers = {}


class HanaUtilTests(unittest.TestCase):
test_server = "https://hana.neonaialpha.com"
test_server = "https://hana.neonaibeta.com"
test_path = join(dirname(__file__), "hana_test.json")

def tearDown(self) -> None:
Expand Down Expand Up @@ -76,18 +75,26 @@ def test_request_backend(self, config_path):
# Test expired/invalid token
old_token_path = join(dirname(__file__), "outdated_hana_token.json")
copy(old_token_path, self.test_path)
with open(self.test_path, 'r') as f:
old_contents = f.read()
neon_utils.hana_utils._client_config = {}
neon_utils.hana_utils._headers = {}
from neon_utils.hana_utils import ServerException
with self.assertRaises(ServerException):
# Request fails due to invalid token
request_backend("/neon/get_response",
{"lang_code": "en-us",
"utterance": "who are you",
"user_profile": {}}, self.test_server)
# Invalid cached token is removed
self.assertFalse(isfile(self.test_path))

# Request generates an updated token
resp = request_backend("/neon/get_response",
{"lang_code": "en-us",
"utterance": "who are you",
"user_profile": {}}, self.test_server)
self.assertEqual(resp['lang_code'], "en-us")
self.assertIsInstance(resp['answer'], str)

# New token is created at expected path
self.assertTrue(isfile(self.test_path))
with open(self.test_path, 'r') as f:
new_contents = f.read()
self.assertNotEqual(new_contents, old_contents)

# TODO: Test token refresh fails, old token is removed
# TODO: Test invalid route, invalid request data

@patch("neon_utils.hana_utils._get_client_config_path")
Expand Down

0 comments on commit 92c7c8e

Please sign in to comment.