Esempio n. 1
0
def project_model_perturbations():

    updated_author = create_author()
    updated_author.email = "*****@*****.**"

    updated_study = create_study("project-1", "study-1")
    updated_study.name = "updated"

    return [
        ({
            "name": "updated"
        }, lambda db: [], does_not_raise()),
        ({
            "description": "updated"
        }, lambda db: [], does_not_raise()),
        (
            {
                "authors": [create_author(), updated_author]
            },
            lambda db: [
                db.query(models.Author.email).count() == 2,
                db.query(author_projects_table).count() == 2,
            ],
            does_not_raise(),
        ),
        # Delete a study.
        (
            {
                "studies": [create_study("project-1", "study-1")]
            },
            lambda db: [db.query(models.Study.id).count() == 1],
            does_not_raise(),
        ),
        # Update a study.
        (
            {
                "studies":
                [updated_study,
                 create_study("project-1", "study-2")]
            },
            lambda db: [db.query(models.Study.id).count() == 2],
            does_not_raise(),
        ),
        # Add a study.
        (
            {
                "studies": [
                    create_study("project-1", f"study-{index + 1}")
                    for index in range(3)
                ]
            },
            lambda db: [db.query(models.Study.id).count() == 3],
            does_not_raise(),
        ),
    ]
Esempio n. 2
0
def test_fail_with_existing(db: Session):

    author = create_author()

    db_author = AuthorCRUD.create(db, author)
    db.add(db_author)
    db.commit()

    author_2 = create_author()
    author_2.name += " 2"

    db_author_2 = AuthorCRUD.create(db, author_2)
    db.add(db_author_2)

    with pytest.raises(IntegrityError):
        db.commit()
Esempio n. 3
0
def test_duplicate_same_commit(db: Session):

    author = create_author()

    db_author = AuthorCRUD.create(db, author)
    db.add(db_author)

    db_author_2 = AuthorCRUD.create(db, author)
    db.add(db_author_2)

    db.commit()

    assert len(AuthorCRUD.read_all(db)) == 1
Esempio n. 4
0
def test_simple_create_read(db: Session):

    author = create_author()

    db_author = AuthorCRUD.create(db, author)
    db.add(db_author)
    db.commit()

    retrieved_authors = AuthorCRUD.read_all(db)

    assert len(retrieved_authors) == 1

    retrieved_author = retrieved_authors[0]

    assert retrieved_author.name == author.name
    assert retrieved_author.email == author.email
    assert retrieved_author.institute == author.institute