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()
def test_change_karma(giver, receiver, channel, amount): with database.session_manager() as session: pre_change_karma = session.query(KarmaUser).get(receiver).karma_points karma = Karma(giver, receiver, channel) karma.change_karma(amount) with database.session_manager() as session: post_change = session.query(KarmaUser).get(receiver).karma_points assert post_change == (pre_change_karma + amount)
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)
def test_change_karma_bot_self(): 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" )
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"
def test_change_karma_msg(): 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"