Exemple #1
0
def test_change_karma(mock_filled_db_session, test_changes, mock_slack_api_call):
    session = db_session.create_session()
    pre_change_karma = session.query(KarmaUser).get(test_changes[1]).karma_points

    karma = Karma(test_changes[0], test_changes[1], test_changes[2])
    karma.change_karma(test_changes[3])

    post_change = session.query(KarmaUser).get(test_changes[1]).karma_points
    assert post_change == (pre_change_karma + test_changes[3])
    session.close()
Exemple #2
0
 def test_change_karma_bot_self(self):
     karma = Karma('bob', 'karmabot')
     assert karma.change_karma(2) == "Thanks @bob for the extra karma, my karma is 2 now"
     karma = Karma('tim', 'karmabot')
     assert karma.change_karma(3) == "Thanks @tim for the extra karma, my karma is 5 now"
     karma = Karma('julian', 'karmabot')
     assert karma.change_karma(-3) == "Not cool @julian lowering my karma to 2, but you are probably right, I will work harder next time"
Exemple #3
0
def test_change_karma(mock_filled_db_session, test_changes):
    session = db_session.create_session()
    pre_change_karma = session.query(KarmaUser).get(
        test_changes[1]).karma_points

    karma = Karma(test_changes[0], test_changes[1])
    karma.change_karma(test_changes[2])

    session.commit()
    post_change = session.query(KarmaUser).get(test_changes[1]).karma_points
    assert post_change == (pre_change_karma + test_changes[2])
Exemple #4
0
def test_change_karma_exceptions(mock_filled_db_session):
    with pytest.raises(RuntimeError):
        karma = Karma("ABC123", "XYZ123", "CHANNEL42")
        karma.change_karma("ABC")

    with pytest.raises(ValueError):
        karma = Karma("ABC123", "ABC123", "CHANNEL42")
        karma.change_karma(2)
Exemple #5
0
def test_change_karma_bot_self(mock_filled_db_session):
    karma = Karma("ABC123", KARMABOT_ID, "CHANNEL42")
    assert (karma.change_karma(2) ==
            "Thanks pybob for the extra karma, my karma is 12 now")

    karma = Karma("EFG123", KARMABOT_ID, "CHANNEL42")
    assert (karma.change_karma(3) ==
            "Thanks Julian Sequeira for the extra karma, my karma is 15 now")

    karma = Karma("ABC123", KARMABOT_ID, "CHANNEL42")
    assert (
        karma.change_karma(-3) ==
        "Not cool pybob lowering my karma to 12, but you are probably right, I will work harder next time"
    )
Exemple #6
0
def test_create_karma_user(mock_empty_db_session, mock_slack_api_call):
    karma = Karma("ABC123", "XYZ123", "CHANNEL42")
    assert karma.giver.username == "pybob"
    assert karma.receiver.username == "clamytoe"

    first = db_session.create_session().query(KarmaUser).get("ABC123")
    second = db_session.create_session().query(KarmaUser).get("XYZ123")

    assert first.username == "pybob"
    assert second.username == "clamytoe"
Exemple #7
0
 def test_change_karma(self):
     assert_raises(ValueError, Karma, 'bob', 'bob')
     karma = Karma('bob', 'tim')
     assert_raises(RuntimeError, karma.change_karma, 'string')
     karma = Karma('bob', 'tim')
     assert karma.change_karma(4) == "tim's karma increased to 4"
     assert karmas.get('tim') == 4
     assert karma.change_karma(2) == "tim's karma increased to 6"
     assert karmas.get('tim') == 6
     assert karma.change_karma(-1) == "tim's karma decreased to 5"
     assert karmas.get('tim') == 5
     msg = "tim's karma increased to 10 (= max increase of {})".format(MAX_POINTS)
     assert karma.change_karma(MAX_POINTS + 3) == msg
     assert karmas.get('tim') == 5 + MAX_POINTS
     msg = "tim's karma decreased to 5 (= max decrease of {})".format(MAX_POINTS)
     prev_score = karmas.get('tim')  # 10
     assert karma.change_karma(-12) == msg
     assert karmas.get('tim') == prev_score - MAX_POINTS  # 5
Exemple #8
0
def test_change_karma_msg(mock_filled_db_session):
    karma = Karma("ABC123", "XYZ123", "CHANNEL42")
    assert karma.change_karma(4) == "clamytoe's karma increased to 424"

    karma = Karma("EFG123", "ABC123", "CHANNEL42")
    assert karma.change_karma(-3) == "pybob's karma decreased to 389"
Exemple #9
0
 def test_change_karma_exceptions(self):
     karma = Karma('bob', 'tim')
     assert_raises(RuntimeError, karma.change_karma, 'string')
     karma = Karma('bob', 'bob')
     assert_raises(ValueError, karma.change_karma, 1)