Beispiel #1
0
def test_of_with_record():
    fragment = attr.evolve(
        FRAGMENT,
        record=Record((
            RecordEntry("Not This User", RecordType.REVISION,
                        "2017-06-20T00:00:00.000Z"),
            RecordEntry(
                "Not This User",
                RecordType.HISTORICAL_TRANSLITERATION,
                "2015-06-20/2017-06-20",
            ),
            RecordEntry("Not This User", RecordType.COLLATION,
                        "2017-06-20T00:00:00.000Z"),
            RecordEntry("This User", RecordType.TRANSLITERATION,
                        "2018-06-20T00:00:00.000Z"),
        )),
    )
    matching_lines = (("1. kur", ), )
    assert FragmentInfo.of(fragment, matching_lines) == FragmentInfo(
        FRAGMENT.number,
        FRAGMENT.accession,
        FRAGMENT.script,
        FRAGMENT.description,
        matching_lines,
        "This User",
        "2018-06-20T00:00:00.000Z",
    )
def test_inject_document_in_fragment_infos(fragment_finder, when,
                                           bibliography):
    bibliography_entry = BibliographyEntryFactory.build()
    fragment_1 = FragmentInfo.of(
        FragmentFactory.build(
            number="K.1", references=(ReferenceFactory.build(id="RN.0"), )))
    fragment_2 = FragmentInfo.of(
        FragmentFactory.build(
            number="K.2",
            references=(
                ReferenceFactory.build(id="RN.1"),
                ReferenceFactory.build(id="RN.2"),
            ),
        ))
    fragment_expected_1 = fragment_1.set_references(
        [fragment_1.references[0].set_document(bibliography_entry)])
    fragment_expected_2 = fragment_2.set_references([
        fragment_2.references[0].set_document(bibliography_entry),
        fragment_2.references[1].set_document(bibliography_entry),
    ])
    (when(fragment_finder).search_references("id", "pages").thenReturn(
        [fragment_1, fragment_2]))
    (when(bibliography).find("RN.0").thenReturn(bibliography_entry))
    (when(bibliography).find("RN.1").thenReturn(bibliography_entry))
    (when(bibliography).find("RN.2").thenReturn(bibliography_entry))

    assert fragment_finder.search_references_in_fragment_infos(
        "id", "pages") == [
            fragment_expected_1,
            fragment_expected_2,
        ]
Beispiel #3
0
def test_of():
    matching_lines = (("1. kur", ), )
    assert FragmentInfo.of(FRAGMENT, matching_lines) == FragmentInfo(
        FRAGMENT.number,
        FRAGMENT.accession,
        FRAGMENT.script,
        FRAGMENT.description,
        matching_lines,
        "",
        "",
    )
Beispiel #4
0
def test_of_with_references():
    matching_lines = (("1. kur", ), )
    assert FragmentInfo.of(FRAGMENT_WITH_REFERENCES,
                           matching_lines) == FragmentInfo(
                               FRAGMENT_WITH_REFERENCES.number,
                               FRAGMENT_WITH_REFERENCES.accession,
                               FRAGMENT_WITH_REFERENCES.script,
                               FRAGMENT_WITH_REFERENCES.description,
                               matching_lines,
                               "",
                               "",
                               FRAGMENT_WITH_REFERENCES.references,
                           )
def test_search(fragment_finder, fragment_repository, when):
    fragment = FragmentFactory.build()
    query = fragment.number
    (when(fragment_repository).query_by_fragment_cdli_or_accession_number(
        query).thenReturn([fragment]))

    assert fragment_finder.search(query) == [FragmentInfo.of(fragment)]
def test_search_references(client, fragmentarium, bibliography, user):
    bib_entry_1 = BibliographyEntryFactory.build(id="RN.0", pages="254")
    bib_entry_2 = BibliographyEntryFactory.build(id="RN.1")
    bibliography.create(bib_entry_1, user)
    bibliography.create(bib_entry_2, user)

    fragment = FragmentFactory.build(references=(
        ReferenceFactory.build(id="RN.0", pages="254"),
        ReferenceFactory.build(id="RN.1"),
    ))
    fragmentarium.create(fragment)
    result = client.simulate_get(
        "/fragments",
        params={
            "id": fragment.references[0].id,
            "pages": fragment.references[0].pages
        },
    )

    assert result.status == falcon.HTTP_OK

    fragment_expected = fragment.set_references([
        fragment.references[0].set_document(bib_entry_1),
        fragment.references[1].set_document(bib_entry_2),
    ])
    assert result.json == ApiFragmentInfoSchema(many=True).dump(
        [FragmentInfo.of(fragment_expected)])
    assert "Cache-Control" not in result.headers
Beispiel #7
0
 def search_transliteration(self, query: TransliterationQuery) -> List[FragmentInfo]:
     if query.is_empty():
         return []
     else:
         return [
             FragmentInfo.of(fragment, fragment.get_matching_lines(query))
             for fragment in self._repository.query_by_transliteration(query)
         ]
def test_fragment_search_references(fragment_finder, fragment_repository,
                                    when):
    fragment = FragmentFactory.build(references=(ReferenceFactory(),
                                                 ReferenceFactory()))

    references_id = fragment.references[0].id
    references_pages = fragment.references[0].pages

    (when(fragment_repository).query_by_id_and_page_in_references(
        references_id, references_pages).thenReturn([fragment]))
    assert fragment_finder.search_references(
        references_id, references_pages) == [FragmentInfo.of(fragment)]
def test_search_transliteration(fragment_finder, fragment_repository, when):
    transliterated_fragment = TransliteratedFragmentFactory.build()
    sign_matrix = [["MA", "UD"]]
    query = TransliterationQuery(sign_matrix)
    matching_fragments = [transliterated_fragment]

    (when(fragment_repository).query_by_transliteration(query).thenReturn(
        matching_fragments))

    expected_lines = (("6'. [...] x# mu ta-ma;-tu₂", ), )
    expected = [
        FragmentInfo.of(fragment, expected_lines)
        for fragment in matching_fragments
    ]
    assert fragment_finder.search_transliteration(query) == expected
def test_create_fragment_info_dto():
    lemmatized_fragment = LemmatizedFragmentFactory.build()
    line = "1. kur"
    info = FragmentInfo.of(lemmatized_fragment, ((line, ), ))
    record_entry = lemmatized_fragment.record.entries[0]
    is_transliteration = record_entry.type == RecordType.TRANSLITERATION
    assert ApiFragmentInfoSchema().dump(info) == {
        "number": str(info.number),
        "accession": info.accession,
        "script": info.script,
        "description": info.description,
        "matchingLines": [[line]],
        "editor": record_entry.user if is_transliteration else "",
        "editionDate": record_entry.date if is_transliteration else "",
        "references": [],
    }
def test_find_interesting(fragment_finder, fragment_repository, when):
    fragment = FragmentFactory.build()
    (when(fragment_repository).query_path_of_the_pioneers().thenReturn(
        [fragment]))
    assert fragment_finder.find_interesting() == [FragmentInfo.of(fragment)]
def test_find_random(fragment_finder, fragment_repository, when):
    fragment = FragmentFactory.build()
    (when(fragment_repository).query_random_by_transliterated().thenReturn(
        [fragment]))
    assert fragment_finder.find_random() == [FragmentInfo.of(fragment)]
def expected_fragment_info_dto(fragment, lines=tuple()):
    return ApiFragmentInfoSchema().dump(FragmentInfo.of(fragment, lines))
Beispiel #14
0
def test_of_defaults():
    assert FragmentInfo.of(FRAGMENT).matching_lines == tuple()
 def make_fragment_info(self, data, **kwargs):
     data["matching_lines"] = tuple(map(tuple, data["matching_lines"]))
     return FragmentInfo(**data)