Esempio n. 1
0
def test_batch__primary_key_constraint(create_batch_db, db_session):
    db_session.add(batch.Batch(id=1000, name="a", project_id="GDC-MISC"))
    db_session.commit()

    with pytest.raises(exc.IntegrityError, match=r"batch_pk"):
        db_session.add(
            batch.Batch(id=1000, name="b", project_id="GDC-INTERNAL"))
        db_session.commit()
Esempio n. 2
0
def test_batches(create_batch_db, db_session):
    b1 = batch.Batch(name="a", project_id="GDC-MISC")
    b2 = batch.Batch(name="b", project_id="GDC-INTERNAL")
    db_session.add(b1)
    db_session.add(b2)
    db_session.commit()

    yield (b1, b2)
Esempio n. 3
0
def test_batch__defaults_unique_ids(create_batch_db, db_session):
    db_session.add(batch.Batch(name="a", project_id="GDC-MISC"))
    db_session.add(batch.Batch(name="b", project_id="GDC-MISC"))
    db_session.commit()

    first = db_session.query(batch.Batch).filter(batch.Batch.name == "a").one()
    second = db_session.query(
        batch.Batch).filter(batch.Batch.name == "b").one()
    assert first.id is not None
    assert second.id is not None
    assert first.id != second.id
Esempio n. 4
0
def test_batches_with_members(create_batch_db, db_session):
    b1 = batch.Batch(name="a", project_id="GDC-MISC")
    b2 = batch.Batch(name="b", project_id="GDC-INTERNAL")
    db_session.add(b1)
    db_session.add(b2)
    db_session.commit()

    b1.members.append(batch.BatchMembership(node_id="node_1"))
    b1.members.append(batch.BatchMembership(node_id="node_2"))
    b2.members.append(batch.BatchMembership(node_id="node_3"))
    b2.members.append(batch.BatchMembership(node_id="node_4"))
    db_session.commit()

    yield (b1, b2)
Esempio n. 5
0
def test_batch__repr():
    b = batch.Batch(
        id=1000,
        name="a",
        project_id="GDC-MISC",
        status="CLOSED",
        created_datetime=datetime.datetime(
            year=2021,
            month=1,
            day=18,
            hour=9,
            minute=30,
            second=10,
            microsecond=123,
            tzinfo=pytz.utc,
        ),
        updated_datetime=datetime.datetime(
            year=2021,
            month=1,
            day=18,
            hour=9,
            minute=30,
            second=10,
            microsecond=123,
            tzinfo=pytz.utc,
        ),
    )
    expected = "<Batch(id='1000', name='a', project_id='GDC-MISC', status='CLOSED', created_datetime='2021-01-18T09:30:10.000123+00:00', updated_datetime='2021-01-18T09:30:10.000123+00:00')>"
    assert repr(b) == expected
Esempio n. 6
0
def test_batch__updates(create_batch_db, db_session):
    b = batch.Batch(name="a", project_id="GDC-MISC")
    db_session.add(b)
    db_session.commit()
    b.project_id = "GDC-INTERNAL"
    db_session.commit()

    updated_b = db_session.query(
        batch.Batch).filter(batch.Batch.name == "a").one()
    assert updated_b.project_id == "GDC-INTERNAL"
    assert updated_b.updated_datetime > updated_b.created_datetime
Esempio n. 7
0
def test_batch__status_values(create_batch_db, db_session, status, expected):
    with pytest.raises(ValueError, match=r"{}".format(expected)):
        db_session.add(
            batch.Batch(name="a", project_id="GDC-MISC", status=status))
        db_session.commit()
Esempio n. 8
0
def test_batch__default_status(create_batch_db, db_session):
    db_session.add(batch.Batch(name="a", project_id="GDC-MISC"))
    db_session.commit()
    b = db_session.query(batch.Batch).filter(batch.Batch.name == "a").one()
    assert b.status == "OPEN"
Esempio n. 9
0
def test_batch__default_datetimes(create_batch_db, db_session, attribute):
    db_session.add(batch.Batch(name="a", project_id="GDC-MISC"))
    db_session.commit()
    b = db_session.query(batch.Batch).filter(batch.Batch.name == "a").one()
    date = getattr(b, attribute)
    assert date is not None
Esempio n. 10
0
def test_batch__to_json(contents, expected):
    b = batch.Batch(**contents)

    assert b.to_json() == expected
Esempio n. 11
0
def test_batch__required_fields(create_batch_db, db_session, contents):
    with pytest.raises(exc.IntegrityError,
                       match=r"violates not-null constraint"):
        db_session.add(batch.Batch(**contents))
        db_session.commit()