Esempio n. 1
0
def cog(bot):
    global vote_manager
    cog = Voting.Voting(bot, db_manager)
    db_manager.db_execute_commit("DROP TABLE Votes")
    db_manager.db_execute_commit("DROP TABLE VoteTargetRoles")
    db_manager.db_execute_commit("DROP TABLE VoteOptions")
    db_manager.db_execute_commit("DROP TABLE VoteSent")
    db_manager.insert_extension("Vote", 0, True, True)
    vote_manager = Voting.VoteManager(db_manager)
    bot.add_cog(cog)
    dpytest.configure(bot)
    print("Tests starting")
    return cog
Esempio n. 2
0
def test_vote_add_option():
    vote = vote_manager.create_vote(111, 222, "Add Option Test")
    vote.add_option(Voting.Option("head", "body", 123))
    assert vote.options[0].head == "head"
    assert vote.options[0].body == "body"
    in_db = db_manager.db_execute_select("SELECT * FROM VoteOptions WHERE opt_id=?", (123,))
    assert in_db
Esempio n. 3
0
def test_vote_remove_role():
    vote = Voting.Vote(111, "Test Vote", 222, 333, db_manager)
    vote.add_role(777)
    vote.remove_role(777)
    assert 777 not in vote.target_roles
    in_db = db_manager.db_execute_select("SELECT * FROM VoteTargetRoles WHERE vote_id=? AND role_id=?", (111, 777))
    assert not in_db
Esempio n. 4
0
def test_vote_remove_option():
    vote = vote_manager.create_vote(111, 222, "Remove Option Test")
    vote.add_option(Voting.Option("head", "body", 123))
    vote.remove_option(0)
    in_db = db_manager.db_execute_select(
        "SELECT * FROM VoteOptions WHERE opt_id=?", (123, ))
    assert not in_db
Esempio n. 5
0
def test_two_way():
    def test_asserts(f, *args, **kwargs):
        try:
            f(*args, **kwargs)
        except AssertionError:
            return
        raise AssertionError

    # test internal asserts don't false positive
    t = Voting.TwoWay({1: 2, 3: 4})
    t2 = Voting.TwoWay({1: 2, 2: 1, 4: 3})
    assert t == t2

    # test an invalid dict cannot be made
    test_asserts(Voting.TwoWay, {1: 2, 2: 3})

    def ta2():
        t = Voting.TwoWay()
        t[1] = 2
        t[2] = 3
        test_asserts(ta2)
Esempio n. 6
0
 def ta2():
     t = Voting.TwoWay()
     t[1] = 2
     t[2] = 3
     test_asserts(ta2)
Esempio n. 7
0
def test_vote_is_ready():
    vote = Voting.Vote(111, "Test Vote", 222, 333, db_manager)
    vote.add_option(Voting.Option(111, "head", "body"))
    assert not vote.is_ready()
    vote.add_option(Voting.Option(122, "head", "body"))
    assert vote.is_ready()
Esempio n. 8
0
def test_option():
    opt = Voting.Option("test", "option", 123456789)
    assert opt.id == 123456789
    assert opt.head == "test"
    assert opt.body == "option"