def test_fragment_exists_true(
        database: Database,
        parallel_repository: MongoParallelRepository) -> None:
    fragment = FragmentFactory.build(number=MUSEUM_NUMBER)
    database[FRAGMENTS_COLLECTION].insert_one(FragmentSchema().dump(fragment))

    assert parallel_repository.fragment_exists(MUSEUM_NUMBER) is True
Пример #2
0
def create_context():
    ebl_ai_client = EblAiClient(os.environ["EBL_AI_API"])
    client = MongoClient(os.environ["MONGODB_URI"])
    database = client.get_database(os.environ.get("MONGODB_DB"))
    auth_backend = Auth0Backend(
        decode_certificate(os.environ["AUTH0_PEM"]),
        os.environ["AUTH0_AUDIENCE"],
        os.environ["AUTH0_ISSUER"],
        set_sentry_user,
    )
    cache = create_cache()
    return Context(
        ebl_ai_client=ebl_ai_client,
        auth_backend=auth_backend,
        word_repository=MongoWordRepository(database),
        sign_repository=MongoSignRepository(database),
        public_file_repository=GridFsFileRepository(database, "fs"),
        photo_repository=GridFsFileRepository(database, "photos"),
        folio_repository=GridFsFileRepository(database, "folios"),
        fragment_repository=MongoFragmentRepository(database),
        changelog=Changelog(database),
        bibliography_repository=MongoBibliographyRepository(database),
        text_repository=MongoTextRepository(database),
        annotations_repository=MongoAnnotationsRepository(database),
        lemma_repository=MongoLemmaRepository(database),
        cache=cache,
        parallel_line_injector=ParallelLineInjector(
            MongoParallelRepository(database)),
    )
def test_find_implicit_chapter(
        database: Database,
        parallel_repository: MongoParallelRepository) -> None:
    chapter = ChapterFactory.build(text_id=TEXT_ID)
    database[CHAPTERS_COLLECTION].insert_one(ChapterSchema().dump(chapter))

    assert parallel_repository.find_implicit_chapter(TEXT_ID) == ChapterName(
        chapter.stage, chapter.version, chapter.name)
def test_chapter_exists_true(
        database: Database,
        parallel_repository: MongoParallelRepository) -> None:
    chapter = ChapterFactory.build(
        text_id=TEXT_ID,
        stage=CHAPTER_NAME.stage,
        name=CHAPTER_NAME.name,
    )
    database[CHAPTERS_COLLECTION].insert_one(ChapterSchema().dump(chapter))

    assert parallel_repository.chapter_exists(TEXT_ID, CHAPTER_NAME) is True
def test_find_implicit_chapter_not_found(
    parallel_repository: MongoParallelRepository, ) -> None:
    with pytest.raises(NotFoundError):
        parallel_repository.find_implicit_chapter(TEXT_ID)
def test_chapter_exists_false(
        parallel_repository: MongoParallelRepository) -> None:
    assert parallel_repository.chapter_exists(TEXT_ID, CHAPTER_NAME) is False
def test_fragment_exists_false(
        parallel_repository: MongoParallelRepository) -> None:
    assert parallel_repository.fragment_exists(MUSEUM_NUMBER) is False
def parallel_repository(database: Database) -> MongoParallelRepository:
    return MongoParallelRepository(database)