예제 #1
0
def test_get_report():
    author = factories.User()
    reporter = factories.User()
    db.Session.add(author)
    db.Session.add(reporter)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    translation = tran_models.Translation(page=p, language=l, group=g)
    db.Session.add(translation)
    db.Session.flush()

    report = reports_models.Report(translation, author, reporter)
    db.Session.add(report)
    db.Session.flush()

    assert reports_models.Report.get_report(translation, author,
                                            reporter) == report
예제 #2
0
def test_get_by_id_when_id_does_exist():
    """
        This should return a vote for a given composite id: page_id, language_id, group_id, author_id, voter_id.
    """
    score = 5
    author = factories.User()
    voter = factories.User()
    db.Session.add(author)
    db.Session.add(voter)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    vote = votes_models.Vote(score, p, l, g, author, voter)
    db.Session.add(vote)
    db.Session.flush()

    assert votes_models.Vote.get_by_id(p.id, l.id, g.id, author.id,
                                       voter.id) == vote
예제 #3
0
def test_get_vote():
    """
        This should get a vote for a given author, voter, group, language, and page.
    """
    score = 5
    author = factories.User()
    voter = factories.User()
    db.Session.add(author)
    db.Session.add(voter)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    vote = votes_models.Vote(score, p, l, g, author, voter)
    db.Session.add(vote)

    db.Session.flush()

    assert votes_models.Vote.get_vote(p, l, g, author, voter) == vote
예제 #4
0
def test_init():
    """
        This should add a vote to a database session for a given author, voter, group, language, and page.
    """
    score = 5
    author = factories.User()
    voter = factories.User()
    db.Session.add(author)
    db.Session.add(voter)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    vote = votes_models.Vote(score, p, l, g, author, voter)
    db.Session.add(vote)
    db.Session.flush()

    assert vote.score == score
    assert vote.page_id == p.id
    assert vote.language_id == l.id
    assert vote.group_id == g.id
    assert vote.author_id == author.id
    assert vote.voter_id == voter.id
예제 #5
0
def test_delete_votes_private_group_multiple_authors_voters():
    """
        This test should add scores for two authors with translations for
        a given page and language and for a public group, Then, it should delete all
        records and as a result return an empty array.
    """
    score_a_1_v_1 = 5
    score_a_1_v_2 = 3

    score_a_2_v_1 = 4
    score_a_2_v_2 = 2

    author1 = factories.User()
    voter1 = factories.User()
    db.Session.add(author1)
    db.Session.add(voter1)

    author2 = factories.User()
    voter2 = factories.User()
    db.Session.add(author2)
    db.Session.add(voter2)

    g = groups_models.Group(name="test-group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    #votes: author_1, voter_1, voter_2
    vote_a_1_v_1 = votes_models.Vote(score_a_1_v_1, p, l, g, author1, voter1)
    db.Session.add(vote_a_1_v_1)
    db.Session.flush()

    vote_a_1_v_2 = votes_models.Vote(score_a_1_v_2, p, l, g, author1, voter2)
    db.Session.add(vote_a_1_v_2)
    db.Session.flush()

    #votes: author_2, voter_1, voter_2
    vote_a_2_v_1 = votes_models.Vote(score_a_2_v_1, p, l, g, author2, voter1)
    db.Session.add(vote_a_2_v_1)
    db.Session.flush()

    vote_a_2_v_2 = votes_models.Vote(score_a_2_v_2, p, l, g, author2, voter2)
    db.Session.add(vote_a_2_v_2)
    db.Session.flush()

    #testing average scores
    assert votes_models.Vote.get_author_scores(
        p, l, g)[0][1] == ((score_a_1_v_1 + score_a_1_v_2) / 2)
    assert votes_models.Vote.get_author_scores(
        p, l, g)[1][1] == ((score_a_2_v_1 + score_a_2_v_2) / 2)

    votes_models.Vote.delete_votes(p, l, g, author1)
    votes_models.Vote.delete_votes(p, l, g, author2)

    assert votes_models.Vote.get_author_scores(p, l, g) == []
예제 #6
0
def test_delete_votes_private_group_single_voter_author():
    """
        This test should add a score for a single author with translations for
        a given page and language and for a private group, Then, it should delete
        the record and as a result return an empty array.
    """
    score = 5
    author = factories.User()
    voter = factories.User()
    db.Session.add(author)
    db.Session.add(voter)

    g = groups_models.Group(name="test-group", creator=factories.User())
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    #vote for a public group
    vote = votes_models.Vote(score, p, l, g, author, voter)
    db.Session.add(vote)

    db.Session.flush()

    assert votes_models.Vote.get_author_scores(p, l, g)[0][1] == score

    votes_models.Vote.delete_votes(p, l, g, author)

    assert votes_models.Vote.get_author_scores(p, l, g) == []
예제 #7
0
def test_get_author_scores_public_group_single_voter_author():
    """
        Method get_author_scores returns avg scores for all authors with translations for a given page, language and group.
        This test should return the value of a single score for a single author
        with translations for a given page and language and for a public group,
    """
    score = 5
    author = factories.User()
    voter = factories.User()
    db.Session.add(author)
    db.Session.add(voter)

    g = groups_models.Group(name="Public", creator=factories.User())
    g.id = -1
    g.pubid = "__world__"
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    #vote for a public group
    vote = votes_models.Vote(score, p, l, g, author, voter)
    db.Session.add(vote)

    db.Session.flush()

    assert votes_models.Vote.get_author_scores(p, l)[0][1] == score
예제 #8
0
def test_admins_does_not_return_non_admin_users():
    non_admins = [factories.User(admin=False) for _ in range(0, 2)]
    db.Session.add_all(non_admins)
    db.Session.add_all([factories.User(admin=True) for _ in range(0, 2)])

    admins = models.User.admins()

    for non_admin in non_admins:
        assert non_admin not in admins
예제 #9
0
def test_staff_members_does_not_return_non_staff_users():
    non_staff = [factories.User(staff=False) for _ in range(0, 2)]
    db.Session.add_all(non_staff)
    db.Session.add_all([factories.User(staff=True) for _ in range(0, 2)])

    staff = models.User.staff_members()

    for non_staff in non_staff:
        assert non_staff not in staff
예제 #10
0
def test_get_author_scores_public_group_multiple_authors_voters():
    """
        This test should return the avg of two scores for two authors
        with translations for a given page and language an for a public group,
    """
    score_a_1_v_1 = 5
    score_a_1_v_2 = 3

    score_a_2_v_1 = 4
    score_a_2_v_2 = 2

    author1 = factories.User()
    voter1 = factories.User()
    db.Session.add(author1)
    db.Session.add(voter1)

    author2 = factories.User()
    voter2 = factories.User()
    db.Session.add(author2)
    db.Session.add(voter2)

    g = groups_models.Group(name="Public", creator=factories.User())
    g.id = -1
    g.pubid = "__world__"
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    #votes: author_1, voter_1, voter_2
    vote_a_1_v_1 = votes_models.Vote(score_a_1_v_1, p, l, g, author1, voter1)
    db.Session.add(vote_a_1_v_1)
    db.Session.flush()

    vote_a_1_v_2 = votes_models.Vote(score_a_1_v_2, p, l, g, author1, voter2)
    db.Session.add(vote_a_1_v_2)
    db.Session.flush()

    #votes: author_2, voter_1, voter_2
    vote_a_2_v_1 = votes_models.Vote(score_a_2_v_1, p, l, g, author2, voter1)
    db.Session.add(vote_a_2_v_1)
    db.Session.flush()

    vote_a_2_v_2 = votes_models.Vote(score_a_2_v_2, p, l, g, author2, voter2)
    db.Session.add(vote_a_2_v_2)
    db.Session.flush()

    #testing average scores
    assert votes_models.Vote.get_author_scores(
        p, l)[0][1] == ((score_a_1_v_1 + score_a_1_v_2) / 2)
    assert votes_models.Vote.get_author_scores(
        p, l)[1][1] == ((score_a_2_v_1 + score_a_2_v_2) / 2)
예제 #11
0
def test_get_report_translation_is_none():
    author = factories.User()
    reporter = factories.User()
    db.Session.add(author)
    db.Session.add(reporter)

    report = reports_models.Report(None, author, reporter)
    db.Session.add(report)
    db.Session.flush()

    assert reports_models.Report.get_report(None, author, reporter) == None
예제 #12
0
def test_staff_members_when_one_staff_member():
    staff_member = factories.User(staff=True)
    db.Session.add(staff_member)

    staff_members = models.User.staff_members()

    assert staff_members == [staff_member]
예제 #13
0
def test_staff_members_when_multiple_staff_members():
    staff_members = [factories.User(staff=True) for _ in range(0, 2)]
    db.Session.add_all(staff_members)

    result = models.User.staff_members()

    assert result == staff_members
예제 #14
0
def test_admins_when_one_admin():
    admin = factories.User(admin=True)
    db.Session.add(admin)

    admins = models.User.admins()

    assert admins == [admin]
예제 #15
0
def test_admins_when_multiple_admins():
    admins = [factories.User(admin=True) for _ in range(0, 2)]
    db.Session.add_all(admins)

    result = models.User.admins()

    assert result == admins
예제 #16
0
def test_get_by_id_when_id_does_not_exist():
    name = "My Hypothesis Group"
    user = factories.User()

    group = models.Group(name=name, creator=user)
    db.Session.add(group)
    db.Session.flush()

    assert models.Group.get_by_id(23) is None
예제 #17
0
def test_repr():
    name = "My Hypothesis Group"
    user = factories.User()

    group = models.Group(name=name, creator=user)
    db.Session.add(group)
    db.Session.flush()

    assert repr(group) == "<Group: my-hypothesis-group>"
예제 #18
0
def test_slug():
    name = "My Hypothesis Group"
    user = factories.User()

    group = models.Group(name=name, creator=user)
    db.Session.add(group)
    db.Session.flush()

    assert group.slug == "my-hypothesis-group"
예제 #19
0
def test_get_by_id_when_id_does_exist(db_session):
    name = "My Hypothesis Group"
    user = factories.User()

    group = models.Group(name=name, creator=user)
    db_session.add(group)
    db_session.flush()

    assert models.Group.get_by_id(group.id) == group
예제 #20
0
def test_get_author_scores_public_group_single_author_multiple_voters():
    """
        Method get_author_scores returns avg scores for all authors with translations for a given page, language and group.
        This test should return the avg of two scores for a single author
        with translations for a given page and language an for a public group,
    """
    ##add record 1
    score1 = 5
    author = factories.User()
    voter1 = factories.User()
    db.Session.add(author)
    db.Session.add(voter1)

    g = groups_models.Group(name="Public", creator=factories.User())
    g.id = -1
    g.pubid = "__world__"
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    #add record 2
    score2 = 3
    voter2 = factories.User()
    db.Session.add(voter2)

    #vote for a public group
    vote1 = votes_models.Vote(score1, p, l, g, author, voter1)
    db.Session.add(vote1)
    db.Session.flush()

    vote2 = votes_models.Vote(score2, p, l, g, author, voter2)
    db.Session.add(vote2)
    db.Session.flush()

    #testing average score for a single author with two votes
    assert votes_models.Vote.get_author_scores(
        p, l)[0][1] == ((score1 + score2) / 2)
예제 #21
0
def test_created_by():
    name_1 = "My first group"
    name_2 = "My second group"
    user = factories.User()

    group_1 = models.Group(name=name_1, creator=user)
    group_2 = models.Group(name=name_2, creator=user)

    db.Session.add(group_1, group_2)
    db.Session.flush()

    assert models.Group.created_by(user).all() == [group_1, group_2]
예제 #22
0
def test_get_page_translations_with_multiple_groups():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l1 = lang_models.Language(name="abc_language_1")
    db.Session.add(l1)

    l2 = lang_models.Language(name="abc_language_2")
    db.Session.add(l2)

    l3 = lang_models.Language(name="abc_language_3")
    db.Session.add(l3)

    g1 = groups_models.Group(name="abc_group_1", creator=factories.User())
    db.Session.add(g1)
    db.Session.flush()

    g2 = groups_models.Group(name="abc_group_2", creator=factories.User())
    db.Session.add(g2)
    db.Session.flush()

    g3 = groups_models.Group(name="Public", creator=factories.User())
    g3.id = -1
    g3.pubid = "__world__"
    db.Session.add(g3)
    db.Session.flush()

    t1 = tran_models.Translation(page=p, language=l1, group=g1)
    t2 = tran_models.Translation(page=p, language=l2, group=g2)
    t3 = tran_models.Translation(page=p, language=l3, group=g3)
    db.Session.add(t1)
    db.Session.add(t2)
    db.Session.add(t3)
    db.Session.flush()

    assert tran_models.Translation.get_page_translations(p) ==  \
           [(l1.id, l1.name, l1.pubid, g1.id),
            (l2.id, l2.name, l2.pubid, g2.id),
            (l3.id, l3.name, l3.pubid, g3.id)]
예제 #23
0
def test_get_all():
    author1 = factories.User()
    author2 = factories.User()
    author3 = factories.User()
    reporter = factories.User()
    db.Session.add(author1)
    db.Session.add(author2)
    db.Session.add(author3)
    db.Session.add(reporter)

    g = groups_models.Group(name="Public", creator=factories.User())
    g.id = -1
    g.pubid = "__world__"
    db.Session.add(g)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)
    db.Session.flush()

    translation = tran_models.Translation(page=p, language=l, group=g)
    db.Session.add(translation)
    db.Session.flush()

    report1 = reports_models.Report(translation, author1, reporter)
    db.Session.add(report1)

    report2 = reports_models.Report(translation, author2, reporter)
    db.Session.add(report2)

    report3 = reports_models.Report(translation, author3, reporter)
    db.Session.add(report3)
    db.Session.flush()

    assert len(reports_models.Report.get_all()) == 3
예제 #24
0
def test_init():
    name = "My Hypothesis Group"
    user = factories.User()

    group = models.Group(name=name, creator=user)
    db.Session.add(group)
    db.Session.flush()

    assert group.id
    assert group.name == name
    assert group.created
    assert group.updated
    assert group.creator == user
    assert group.creator_id == user.id
    assert group.members == [user]
예제 #25
0
def test_get_translation_when_group_is_not_none():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)
    db.Session.flush()

    t = tran_models.Translation(page=p, language=l, group=g)
    db.Session.add(t)
    db.Session.flush()

    assert tran_models.Translation.get_translation(p, l, g) == t
예제 #26
0
def test_get_by_composite_id():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)
    db.Session.flush()

    t = tran_models.Translation(page=p, language=l, group=g)
    db.Session.add(t)
    db.Session.flush()

    assert tran_models.Translation.get_by_composite_id(p.id, l.id, g.id) == t
예제 #27
0
def test_init():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l = lang_models.Language(name="abc_language")
    db.Session.add(l)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)
    db.Session.flush()

    t = tran_models.Translation(page=p, language=l, group=g)
    db.Session.add(t)
    db.Session.flush()

    assert t.page_id == p.id
    assert t.group_id == g.id
    assert t.language_id == l.id
예제 #28
0
def test_get_public_translations_when_do_not_exist():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l1 = lang_models.Language(name="abc_language_1")
    db.Session.add(l1)

    l2 = lang_models.Language(name="abc_language_2")
    db.Session.add(l2)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)
    db.Session.flush()

    t1 = tran_models.Translation(page=p, language=l1, group=g)
    t2 = tran_models.Translation(page=p, language=l2, group=g)
    db.Session.add(t1)
    db.Session.add(t2)
    db.Session.flush()

    assert tran_models.Translation.get_public_translations(p) == []
예제 #29
0
def test_get_page_translations_with_single_group():
    p = pages_models.Page(uri="http://www.annotran_test.com/")
    db.Session.add(p)

    l1 = lang_models.Language(name="abc_language_1")
    db.Session.add(l1)

    l2 = lang_models.Language(name="abc_language_2")
    db.Session.add(l2)

    g = groups_models.Group(name="abc_group", creator=factories.User())
    db.Session.add(g)
    db.Session.flush()

    t1 = tran_models.Translation(page=p, language=l1, group=g)
    t2 = tran_models.Translation(page=p, language=l2, group=g)
    db.Session.add(t1)
    db.Session.add(t2)
    db.Session.flush()

    assert tran_models.Translation.get_page_translations(p) ==  \
           [(l1.id, l1.name, l1.pubid, g.id), (l2.id, l2.name, l2.pubid, g.id)]
예제 #30
0
def test_with_long_name():
    """Should raise ValueError if name longer than 25 characters."""
    with pytest.raises(ValueError):
        models.Group(name="abcdefghijklmnopqrstuvwxyz",
                     creator=factories.User())