Skip to content

Commit

Permalink
ajout test base filtre
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliettejns committed Sep 3, 2024
1 parent dcd28a6 commit 41039bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
11 changes: 4 additions & 7 deletions app/models/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,9 @@ def is_valid(lemma, POS, morph, corpus):
"POS": True,
"morph": True
}

allowed_column = corpus.displayed_columns_by_name
if lemma and "lemma" in allowed_column and allowed_lemma.count():
current_controlList=corpus.control_lists
if lemma and "lemma" in allowed_column and allowed_lemma.count()>=0:
current_controlList = corpus.control_lists
regex_liste = []
if current_controlList:
if current_controlList.filter_metadata:
Expand All @@ -1130,19 +1129,17 @@ def is_valid(lemma, POS, morph, corpus):
regex_liste.append(ControlLists.re_filter_punct)
if current_controlList.filter_numeral:
regex_liste.append(ControlLists.re_filter_numeral)
print(regex_liste)

ignored_by_regex = False

for regex in regex_liste:
if re.match(regex, lemma) is not None:
ignored_by_regex = True

if (
not ignored_by_regex and
ignored_by_regex is False and
corpus.has_custom_dictionary_value("lemma", lemma) is False and
corpus.get_allowed_values("lemma", label=lemma).count() == 0
):

statuses["lemma"] = False

if POS is not None \
Expand Down
20 changes: 19 additions & 1 deletion tests/test_models/test_record.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from app.models import ChangeRecord, WordToken, Corpus, ControlLists, ControlListsUser, CorpusUser
from app.models import ChangeRecord, WordToken, Corpus, ControlLists, ControlListsUser, CorpusUser, Column
from .base import TestModels
import copy


SimilarityFixtures = [
ControlLists(id=1, name="CL Fixture"),
Corpus(id=1, name="Fixtures !", control_lists_id=1),
Column(heading="Lemma", corpus_id=1),
Column(heading="POS", corpus_id=1),
Column(heading="Morph", corpus_id=1),
Column(heading="Similar", corpus_id=1),
WordToken(corpus=1, form="Cil", lemma="celui", left_context="_", right_context="_", label_uniform="celui", morph="smn", POS="p"), # 1
WordToken(corpus=1, form="Cil", lemma="celle", left_context="_", right_context="_", label_uniform="celle", morph="smn", POS="n"), # 2
WordToken(corpus=1, form="Cil", lemma="cil", left_context="_", right_context="_", label_uniform="cil", morph="smn", POS="p"), # 3
Expand Down Expand Up @@ -148,3 +152,17 @@ def test_similar_lemma_double_change(self):
"Change record should be correct"
)
self.assertCountEqual(cr4.changed, ["lemma", "POS"])

def test_filter_allowed_lemma(self):
""" Ensure only similar features are fixed """
self.load_fixtures()
with self.assertRaises(WordToken.ValidityError):
token, change_record = WordToken.update(
user_id=1,
token_id=1, corpus_id=1,
lemma="#", morph="smn", POS="u")

# faire pareil mais avec les filtres de cochés



2 changes: 2 additions & 0 deletions tests/test_selenium/test_token_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,5 @@ def test_correct_delete(self):
history_row = self.driver_find_elements_by_css_selector("tbody tr.history")
self.assertEqual(len(history_row), 1, "There should be one record in the history")



0 comments on commit 41039bd

Please sign in to comment.