Skip to content

Commit

Permalink
Updated clex path
Browse files Browse the repository at this point in the history
  • Loading branch information
ciioprof0 committed Aug 18, 2024
1 parent 26a4d40 commit ae897e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ling508/demos/demo_clex_importer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@
}
],
"source": [
"# Run all tests in the test directory (~60 seconds)\n",
"# Run all tests in the test directory (~20 seconds)\n",
"pytest.main([TEST_DIR, VERBOSITY, TRACEBACK])\n"
]
},
Expand Down
28 changes: 25 additions & 3 deletions ling508/tests/test_95_e2e_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

""" End-to-end test for the Flask app """

import os
import time
from multiprocessing import Process
import pytest
from selenium import webdriver
Expand Down Expand Up @@ -41,6 +43,18 @@ def run_flask_app():
"""Start the Flask app in a separate process."""
app.run(debug=False, use_reloader=False)

def wait_for_flask():
"""Wait until the Flask app is responsive."""
for _ in range(10): # Retry 10 times with 1-second intervals
try:
response = requests.get("http://localhost:5000/")
if response.status_code == 200:
return True
except requests.exceptions.ConnectionError:
pass
time.sleep(1)
return False

def test_form_submission(init_driver, test_client):
"""Test the form submission on the Flask app."""
driver = init_driver
Expand All @@ -50,14 +64,22 @@ def test_form_submission(init_driver, test_client):
flask_process.start()

try:
# Ensure Flask app is ready
if not wait_for_flask():
pytest.fail("Flask app did not start within the expected time.")

# Open the form in the browser
driver.get("http://localhost:5000/")

# Wait for the URI field to be present
uri_field = WebDriverWait(driver, 10).until(
uri_field = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.ID, "uri"))
)
uri_field.send_keys("https://raw.githubusercontent.com/ciioprof0/stixd/main/lexicon/test_clex.pl")

# Use a local path to the file within the same repo
# Construct the absolute path to the lexicon file
lexicon_file_path = os.path.join(os.getcwd(), 'lexicon', 'test_clex.pl')
uri_field.send_keys(lexicon_file_path)

# Submit the form
submit_button = driver.find_element(By.TAG_NAME, "button")
Expand All @@ -72,4 +94,4 @@ def test_form_submission(init_driver, test_client):
finally:
# Terminate the Flask server process
flask_process.terminate()
flask_process.join()
flask_process.join()

0 comments on commit ae897e1

Please sign in to comment.