Пример #1
0
def test_create_opinions(db_conn):
    # Create opinion type
    type_, _ = DataFlagOpinionType.get_or_create(name="test",
                                                 description="blubb",
                                                 metadata={"version": 0})

    # Create revision
    revision, _ = DataRevision.get_or_create(name="test", description="foo")

    with pytest.raises(db.exceptions.ValidationError):
        DataFlagOpinion.create_opinion(
            user,
            time.time(),
            True,
            type_.name,
            "test",
            "0.0.0",
            "2111",
            revision=revision.name,
        )

    with pytest.raises(db.exceptions.ValidationError):
        DataFlagOpinion.create_opinion(
            user,
            time.time(),
            "idontknow",
            type_.name,
            "test",
            "0.0.0",
            "2111",
            revision=revision.name,
        )

    return DataFlagOpinion.create_opinion(
        user,
        time.time(),
        "bad",
        type_.name,
        "test",
        "0.0.0",
        "2111",
        revision=revision.name,
        notes="I really don't know!",
    )
Пример #2
0
def insert(user, lsd, revision, decision, notes):
    if lsd is None:
        return
    user = user.capitalize()
    try:
        existing_decision = (DataFlagOpinion.select(
            DataFlagOpinion.id,
            DataFlagOpinion.decision).join(MediaWikiUser).switch(
                DataFlagOpinion).join(DataRevision).where(
                    MediaWikiUser.user_name == user,
                    DataRevision.name == revision,
                    DataFlagOpinion.lsd == lsd.lsd,
                ).get())
    except DataFlagOpinion.DoesNotExist:
        logger.debug(
            f"Inserting opinion of user {user} for {revision}, {lsd.lsd}: {decision} (notes: '{notes}')"
        )
        opinion_type, _ = DataFlagOpinionType.get_or_create(
            **bondia_dataflagopiniontype)
        revision, _ = DataRevision.get_or_create(name=revision)
        DataFlagOpinion.create_opinion(
            user,
            time(),
            decision,
            opinion_type.name,
            __name__,
            __version__,
            lsd.lsd,
            revision.name,
            notes,
        )
    else:
        # Update the existing opinion
        logger.debug(
            f"Updating opinion of user {user} for {revision}, {lsd.lsd} (ID {existing_decision} "
            f"{existing_decision.id}): {existing_decision.decision} -> {decision} (notes: {notes})"
        )
        existing_decision.decision = decision
        existing_decision.notes = notes
        existing_decision.save()