Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Mar 20, 2024
1 parent 19d3906 commit c92ad80
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/test_selenium/test_corpus_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
from app import db
from tests.test_selenium.base import TestBase
from tests.fixtures import PLAINTEXT_CORPORA
from selenium.webdriver.support.select import Select
import csv
import os

from flask import Flask, request, Response
from multiprocessing import Process
from selenium.webdriver.support.wait import WebDriverWait


class TestCorpusRegistration(TestBase):
""" Test creation of Corpus """
Expand Down Expand Up @@ -627,7 +632,6 @@ def test_lemmatization_service(self):
"""
Test that a user can create a corpus and that this corpus has its data well recorded
"""

# Click register menu link
self.driver_find_element_by_id("new_corpus_link").click()
self.driver.implicitly_wait(15)
Expand All @@ -641,7 +645,6 @@ def test_lemmatization_service(self):
self.assertEqual(details[0].is_displayed(), False, "Nothing should be displayed by default")

# Select a lemmatizer
from selenium.webdriver.support.select import Select
s = Select(self.driver_find_elements_by_css_selector("#language-model")[0])
s.select_by_visible_text("Dummy lemmatizer")
self.assertEqual(details[0].is_displayed(), True, "Something should be displayed")
Expand All @@ -652,9 +655,7 @@ def test_lemmatization_service(self):
self.assertEqual(details[0].is_displayed(), False, "Nothing should be now")

def test_lemmatization_service_runs(self):
from flask import Flask, request, Response
from threading import Thread

# Create a second fixture app
app = Flask("fixture")

@app.route("/lemma", methods=["POST"])
Expand All @@ -670,9 +671,9 @@ def lemmatizing():
'Access-Control-Allow-Origin': "*"
}
)

thread = Thread(target=app.run, daemon=True, kwargs=dict(host="localhost", port="4567"))
thread.start()
# Start it
second_app = Process(target=app.run, daemon=True, kwargs=dict(host="localhost", port="4567"))
second_app.start()

self.driver_find_element_by_id("new_corpus_link").click()
self.driver.implicitly_wait(15)
Expand All @@ -681,18 +682,19 @@ def lemmatizing():
self.driver_find_element_by_id("corpusName").send_keys("Test")
self.writeMultiline(self.driver_find_element_by_id("tokens"), "Je suis")

from selenium.webdriver.support.select import Select
# Select the lemmatizer
s = Select(self.driver_find_elements_by_css_selector("#language-model")[0])
s.select_by_index(1)
self.driver.implicitly_wait(5)

# Lemmatize
self.driver_find_element_by_id("submit-model").click()

from selenium.webdriver.support.wait import WebDriverWait

# Wait
wait = WebDriverWait(self.driver, timeout=5)
wait.until(lambda x: self.driver_find_element_by_id("tokens-success").is_displayed())

# Check results
self.assertEqual(
self.driver_find_element_by_id("tokens").get_property("value").split("\n"),
["token\tlemma", "Je\t0", "suis\t1"]
Expand All @@ -704,4 +706,5 @@ def lemmatizing():
"Lemmatization happened"
)

thread.join(1)
# Kill second app
second_app.terminate()

0 comments on commit c92ad80

Please sign in to comment.