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
6 changes: 3 additions & 3 deletions default.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ ASR_SERVICE_TIMEOUT=30
ASR_LEADING_SILENCE_MS=250
ASR_TRAILING_SILENCE_MS=250

# Verbal flashcards normally require level-3 words. Set to false for experiments
# where participants should receive lower-level words too.
VERBAL_FLASHCARDS_REQUIRE_LEVEL_3=true
# Verbal flashcards include lower-level words by default so newly translated
# article words can be practiced immediately. Set to true to require level 3+.
VERBAL_FLASHCARDS_REQUIRE_LEVEL_3=false

# SMTP Configuration - Use app-specific password for Gmail
SMTP_EMAIL=
Expand Down
42 changes: 21 additions & 21 deletions zeeguu/api/test/test_verbal_flashcards.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,16 @@ def _create_level_3_flashcard(
return bookmark_row


def test_verbal_flashcards_only_returns_level_3_plus_words_by_default(client, monkeypatch):
def test_verbal_flashcards_returns_lower_level_words_by_default(client, monkeypatch):
monkeypatch.delenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", raising=False)
_prepare_bookmark_support()

bookmark = _create_level_3_flashcard(client)
bookmark_id = bookmark.id
bookmark = _set_bookmark_level(bookmark_id, 2)

flashcards = client.get("/verbal_flashcards")
assert flashcards["total"] == 0

bookmark = _set_bookmark_level(bookmark_id, 3)
expected_prompt = bookmark.user_word.meaning.translation.content
expected_answer = bookmark.user_word.meaning.origin.content

flashcards = client.get("/verbal_flashcards")

assert flashcards["total"] == 1
Expand All @@ -152,19 +148,24 @@ def test_verbal_flashcards_only_returns_level_3_plus_words_by_default(client, mo
assert flashcards["flashcards"][0]["answer"] == expected_answer


def test_verbal_flashcards_returns_lower_level_words_when_experiment_override_is_set(client, monkeypatch):
monkeypatch.setenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", "false")
def test_verbal_flashcards_can_require_level_3_with_env_override(client, monkeypatch):
monkeypatch.setenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", "true")
_prepare_bookmark_support()

bookmark = _create_level_3_flashcard(client)
bookmark_id = bookmark.id
bookmark = _set_bookmark_level(bookmark_id, 1)

flashcards = client.get("/verbal_flashcards")

assert flashcards["total"] == 0

bookmark = _set_bookmark_level(bookmark_id, 3)
expected_answer = bookmark.user_word.meaning.origin.content

flashcards = client.get("/verbal_flashcards")

assert flashcards["total"] == 1
assert flashcards["flashcards"][0]["id"] == str(bookmark_id)
assert flashcards["flashcards"][0]["answer"] == expected_answer


Expand Down Expand Up @@ -865,42 +866,41 @@ def test_submit_coerces_invalid_response_time_to_zero(client):
assert exercise.solving_speed == 0


def test_submit_rejects_lower_level_flashcard_by_default(client, monkeypatch):
def test_submit_accepts_lower_level_flashcard_by_default(client, monkeypatch):
monkeypatch.delenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", raising=False)
_prepare_bookmark_support()

bookmark_id = add_one_bookmark(client)
bookmark = _set_bookmark_level(bookmark_id, 1)

response = client.client.post(
client.append_session("/verbal_flashcards/submit"),
response = client.post(
"/verbal_flashcards/submit",
json={
"flashcard_id": str(bookmark_id),
"user_answer": bookmark.user_word.meaning.origin.content,
"is_correct": True,
},
)

assert response.status_code == 404
assert b"Flashcard not found" in response.data
assert response["success"] is True
assert response["flashcard_id"] == str(bookmark_id)


def test_submit_accepts_lower_level_flashcard_during_experiment(client, monkeypatch):
monkeypatch.setenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", "false")
def test_submit_rejects_lower_level_flashcard_when_level_3_override_is_set(client, monkeypatch):
monkeypatch.setenv("VERBAL_FLASHCARDS_REQUIRE_LEVEL_3", "true")
_prepare_bookmark_support()
_set_client_learned_language(client, "da")

bookmark_id = add_one_bookmark(client)
bookmark = _set_bookmark_level(bookmark_id, 1)

response = client.post(
"/verbal_flashcards/submit",
response = client.client.post(
client.append_session("/verbal_flashcards/submit"),
json={
"flashcard_id": str(bookmark_id),
"user_answer": bookmark.user_word.meaning.origin.content,
"is_correct": True,
},
)

assert response["success"] is True
assert response["flashcard_id"] == str(bookmark_id)
assert response.status_code == 404
assert b"Flashcard not found" in response.data
2 changes: 1 addition & 1 deletion zeeguu/core/verbal_flashcards/flashcard_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def requires_level_3_flashcards():
raw_value = os.environ.get(VERBAL_FLASHCARDS_REQUIRE_LEVEL_3_ENV, "true")
raw_value = os.environ.get(VERBAL_FLASHCARDS_REQUIRE_LEVEL_3_ENV, "false")
return raw_value.strip().lower() not in {"0", "false", "no", "off"}


Expand Down
Loading