def test_paradigm_from_full_page_and_api(client: Client):
    """
    The paradigm returned from the full details page and the API endpoint should
    contain the exact same information.
    """
    lemma_text = "wâpamêw"
    paradigm_size = "full"

    wordform = Wordform.objects.get(text=lemma_text)
    assert wordform.lemma == wordform, "this test requires a lemma"

    # Get standalone page:
    response = client.get(
        reverse("cree-dictionary-index-with-lemma", args=[lemma_text]),
        {"paradigm-size": paradigm_size},
    )
    assert response.status_code == HTTPStatus.OK
    standalone_html = response.content.decode("UTF-8")
    assert lemma_text in standalone_html

    # Get fragment from API request:
    response = client.get(
        reverse("cree-dictionary-paradigm-detail"),
        {
            "lemma-id": wordform.id,
            "paradigm-size": paradigm_size,
        },
    )
    assert response.status_code == HTTPStatus.OK
    html_fragment = response.content.decode("UTF-8")
    assert lemma_text in html_fragment

    assertInHTML(html_fragment, standalone_html)
Exemple #2
0
def test_search(query, tsuutina, english, search_by_query):
    """
    Test an ordinary search.
    """
    res = search_by_query(query)
    page = res.content.decode("UTF-8")
    assertInHTML(f"<li> {escape_html(english)}", page)
    print(page)
    assertInHTML(f'<dfn lang="srs">{escape_html(tsuutina)}', page)
Exemple #3
0
def test_search_empty_lang(search_by_query):
    query = "dog"

    res = search_by_query(query, lang="")
    page = res.content.decode("UTF-8")

    tsuutina = "tłích'ā"
    assertInHTML(f'<dfn lang="srs"> {escape_html(tsuutina)}', page)

    tsuutina = "dóghà"
    assertInHTML(f'<dfn lang="srs"> {escape_html(tsuutina)}', page)
def test_definition_link(db, orthography: str, wordform: str):
    """
    Test that it's in a link and the orthography is correct.
    """
    request = HttpRequest()
    request.COOKIES["orth"] = orthography
    context = RequestContext(request, {})
    template = Template(
        "{% load creedictionary_extras %}" '{% definition_link "wâpamêw" %}'
    )
    rendered = template.render(context)
    assert rendered.startswith("<a")
    assert rendered.endswith("</a>")
    assertInHTML(wordform, rendered)
Exemple #5
0
def test_provide_orthograpy(orth, inner_text):
    context = Context({"wordform": "wâpamêw"})
    template = Template("{% load morphodict_orth %}"
                        "{{ wordform|orth:" + repr(orth) + " }}")

    rendered = template.render(context)
    assertInHTML(
        f"""
        <span lang="cr" data-orth
              data-orth-Latn="wâpamêw"
              data-orth-latn-x-macron="wāpamēw"
              data-orth-Cans="ᐚᐸᒣᐤ">{inner_text}</span>
        """,
        rendered,
    )
Exemple #6
0
def test_relabel_respects_orthography(orth: str, expected: str) -> None:
    """
    Tests that relabelling for nêhiyawêwin respects the current orthography setting.
    """
    assert orth in ORTHOGRAPHY.available

    request = HttpRequest()
    request.COOKIES[ParadigmLabel.cookie_name] = "source_language"
    request.COOKIES[ORTHOGRAPHY.COOKIE_NAME] = orth

    context = RequestContext(request, {"label": RowLabel(TAGS)})
    template = Template("{% load relabelling %} {% relabel label.fst_tags %}")
    rendered = template.render(context)

    assertInHTML(expected, rendered)
Exemple #7
0
def test_retrieve_paradigm(client: Client, lexeme: str, slug_disambiguator,
                           example_forms: str):
    """
    Test going to the lexeme details page with a paradigm.
    """
    query_args = {}
    if slug_disambiguator:
        query_args["slug"] = slug_disambiguator
    wf = Wordform.objects.get(text=lexeme, **query_args)
    url = reverse("cree-dictionary-index-with-lemma", args=[wf.slug])
    response = client.get(url)

    assert response.status_code == 200
    body = response.content.decode("UTF-8")

    assertInHTML(lexeme, body)
    for wordform in example_forms:
        assertInHTML(wordform, body)
def test_produces_correct_markup():
    context = Context({"wordform": "wâpamêw"})
    template = Template("{% load morphodict_orth %}" "{{ wordform|orth:'Latn' }}")

    rendered = template.render(context)
    assert 'lang="cr"' in rendered
    assert 'data-orth-Latn="wâpamêw"' in rendered
    assert 'data-orth-Latn-x-macron="wāpamēw"' in rendered
    assert 'data-orth-Cans="ᐚᐸᒣᐤ"' in rendered
    assertInHTML(
        """
        <span lang="cr" data-orth
              data-orth-Latn="wâpamêw"
              data-orth-latn-x-macron="wāpamēw"
              data-orth-Cans="ᐚᐸᒣᐤ">wâpamêw</span>
        """,
        rendered,
    )
def test_naughty_html():
    """
    Does it escape bad HTML?
    """

    context = Context({"wordform": '<img alt="tâpwêw">'})
    template = Template("{% load morphodict_orth %}" "{{ wordform|orth:'Latn' }}")

    rendered = template.render(context)
    assertInHTML(
        """
        <span lang="cr" data-orth
              data-orth-Latn="&lt;img alt=&quot;tâpwêw&quot;&gt;"
              data-orth-latn-x-macron="&lt;img alt=&quot;tāpwēw&quot;&gt;"
              data-orth-Cans="&lt;img alt=&quot;ᑖᐻᐤ&quot;&gt;">&lt;img alt=&quot;tâpwêw&quot;&gt;</span>
        """,
        rendered,
    )
def test_no_hyphens_in_syllabics():
    """
    Test that trailing hyphens disappear in syllabics.

    See: https://github.com/UAlbertaALTLab/morphodict/issues/314
    """
    context = Context({"wordform": "nôhtê-"})
    template = Template("{% load morphodict_orth %}" "{{ wordform|orth:'Cans' }}")

    rendered = template.render(context)
    assertInHTML(
        f"""
        <span lang="cr" data-orth
              data-orth-Latn="nôhtê-"
              data-orth-latn-x-macron="nōhtē-"
              data-orth-Cans="ᓅᐦᑌ">ᓅᐦᑌ</span>
        """,
        rendered,
    )
def test_cree_example():
    """
    Test the {% cree_example 'like: itwêwin' %} tag.
    """
    request = HttpRequest()
    request.COOKIES["orth"] = "Cans"

    context = RequestContext(request, {"example": "like: wâpamêw"})
    template = Template("{% load creedictionary_extras %}" "{% cree_example example %}")
    rendered = template.render(context)

    assertInHTML(
        f"""
        like: <span lang="cr" data-orth
              data-orth-Latn="wâpamêw"
              data-orth-latn-x-macron="wāpamēw"
              data-orth-Cans="ᐚᐸᒣᐤ">ᐚᐸᒣᐤ</span>
        """,
        rendered,
    )
Exemple #12
0
def test_orth_template_tag(orth, inner_text):
    """
    Test that the {% orth %} tag uses the orthography in the request's cookie.
    """
    request = HttpRequest()
    if orth is not None:
        request.COOKIES["orth"] = orth

    context = RequestContext(request, {"wordform": "wâpamêw"})
    template = Template("{% load morphodict_orth %}" "{% orth wordform %}")
    rendered = template.render(context)

    assertInHTML(
        f"""
        <span lang="cr" data-orth
              data-orth-Latn="wâpamêw"
              data-orth-latn-x-macron="wāpamēw"
              data-orth-Cans="ᐚᐸᒣᐤ">{inner_text}</span>
        """,
        rendered,
    )
Exemple #13
0
def test_search_in_english_only(search_by_query):
    query = "dog"
    tsuutina = "tłích'ā"
    correct_definition = "dog"
    incorrect_definition = "whiskers"

    res = search_by_query(query, lang="eng")
    page = res.content.decode("UTF-8")

    assertInHTML(f'<dfn lang="srs"> {escape_html(tsuutina)}', page)
    assertInHTML(f"<li> {escape_html(correct_definition)}", page)
    assertInHTML(f"<li> {escape_html(incorrect_definition)}", page, count=0)
Exemple #14
0
def test_m2m_entries():
    t1 = Tag.objects.create(name="Tag1")
    t2 = Tag.objects.create(name="Tag2")
    t3 = Tag.objects.create(name="Tag3")

    book = Book.objects.create(
        author=Author.objects.create(first_name="john", last_name="smith"),
        title="john's diary",
    )
    book.tags.add(t1, t2)

    book_v1 = book.versions.last()
    book.reset_version_attrs()

    book.tags.add(t3)
    book.tags.remove(t1)
    book.save()

    book_v2 = book.versions.last()
    data = base_query(page_num=1)
    edit_entries = data["changelog"]["changelog_entries"]
    assert len(edit_entries) == 3

    assert edit_entries[0]["version"]["instance"] == book_v2
    assert len(edit_entries[0]["diffs"]) == 1

    m2m_diff = edit_entries[0]["diffs"][0]
    assert m2m_diff["action"] == "Edited"
    assert m2m_diff["field_name"] == "tags"
    # non-added/removed tag show up without class in both before/after
    assertInHTML("<p class=''>Tag2</p>", m2m_diff["diffed_before"])
    assertInHTML("<p class=''>Tag2</p>", m2m_diff["diffed_after"])

    assertInHTML("<p class='diff_sub'>Tag1</p>", m2m_diff["diffed_before"])
    assertInHTML("<p class='diff_add'>Tag3</p>", m2m_diff["diffed_after"])

    assertInHTML("<p class=''>Tag2</p>", m2m_diff["diffed_combined"])
    assertInHTML("<p class='diff_sub'>Tag1</p>", m2m_diff["diffed_combined"])
    assertInHTML("<p class='diff_add'>Tag3</p>", m2m_diff["diffed_combined"])