def test_character_negative_votes_starting_count(self): """Each Character starst with 0 negative votes from CharacterVote.""" player = make_player() toon = Character( name='CMainToon', server=0, role=0, powerset=0, player=player) toon.save() self.assertEqual(0, toon.negative_votes)
def test_character_negative_votes_count_updates(self): """Each Character's negative_votes updates after new CharacterVote.""" player = make_player() toon = Character( name='DMainToon', server=0, role=0, powerset=0, player=player) toon.save() alt_toon = Character( name='BAltToon', server=0, role=1, powerset=1, player=player) alt_toon.save() vote = CharacterVote(character=alt_toon, voter=toon, vote=0) vote.save() self.assertEqual(1, alt_toon.negative_votes)
def test_character_name_unique_per_server(self): """Characters should have unique names per server.""" name = "Dusktrike" toon = Character(name=name, server=0, player=make_player(), role=1, powerset=2) # save() is required for this test, so toon 1 is persistent. toon.save() self.assertEqual(name, toon.name) second_toon = Character(name=name, server=0, player=make_player(), role=0, powerset=1) with self.assertRaises(IntegrityError) as err: second_toon.save() expected_message = "columns server, name are not unique" self.assertEqual(expected_message, err.exception.message)
def test_mission_has_lfg_requests(self): """A Mission should be associated with its LFGRequests.""" player = make_player() toon = Character( name='Scarlet Letter', server=0, role=0, powerset=0, player=player) toon.save() location = Location(name='Someplace') location.save() mission = Mission(name='FooMissionBar', location=location) mission.save() lfg = LFGRequest(character=toon, mission=mission) lfg.save() expected_requests = [lfg] actual_requests = list(mission.requests.all()) self.assertEqual(expected_requests, actual_requests)
def test_character_has_lfg_requests(self): """A Character should be associated with his/her LFGRequests.""" player = make_player() toon = Character( name='Duskstrike', server=0, role=0, powerset=0, player=player) toon.save() location = Location(name='Somewhere') location.save() mission = Mission(name='FooMission', location=location) mission.save() lfg = LFGRequest(character=toon, mission=mission) lfg.save() expected_requests = [lfg] actual_requests = list(toon.requests.all()) self.assertEqual(expected_requests, actual_requests)
def test_character_votes(self): """One character can create a positive vote for another.""" player = make_player() toon = Character( name='MyMainToon', server=0, role=0, powerset=0, player=player) toon.save() alt_toon = Character( name='MyAltToon', server=0, role=1, powerset=1, player=player) alt_toon.save() vote = CharacterVote(character=alt_toon, voter=toon, vote=1) vote.save() # First, confirm expected behavior for the person voted for. votes_for = alt_toon.votes_for.all() self.assertIn(vote, votes_for) self.assertEqual(1, votes_for[0].vote) self.assertEqual(alt_toon, votes_for[0].character) # Finally, confirm expected behavior for the person who voted. votes_by = toon.votes_by.all() self.assertIn(vote, votes_by) self.assertEqual(1, votes_by[0].vote) self.assertEqual(toon, votes_by[0].voter)