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_name_allows_space(self): """Characters can have names with spaces in them.""" name = "Captain DjangoHacker" player = make_player() toon = Character(name=name, server=0, player=player, role=0, powerset=0) toon.full_clean() self.assertEqual(name, toon.name)
def test_character_player_constraint(self): """Characters should not be created without a player.""" toon = Character(name="Gazorbeam", server=0) with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "This field cannot be null." message_list = err.exception.message_dict.get("player") self.assertEqual(expected_message, message_list[0])
def test_character_name_blank(self): """Characters cannot be created with blank names.""" player = make_player() toon = Character(name="", server=0, player=player) with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "This field cannot be blank." message_list = err.exception.message_dict.get("name") self.assertEqual(expected_message, message_list[0])
def test_character_role_required(self): """You should not be able to create a character without a role.""" player = make_player() toon = Character(name="foobar", player=player) with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "This field cannot be null." message_list = err.exception.message_dict.get("role") self.assertEqual(expected_message, message_list[0])
def test_character_level_min(self): """A Character cannot have a negative level.""" player = make_player() toon = Character(name="UnrealNegativeHero", player=player, server=0) toon.level = -1 with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "Ensure this value is greater than or equal to 0." message_list = err.exception.message_dict.get("level") self.assertEqual(expected_message, message_list[0])
def test_character_level_cap(self): """A Character has a max level of 30.""" player = make_player() toon = Character(name="FakeToon", player=player, server=0) toon.level = 31 with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "Ensure this value is less than or equal to 30." message_list = err.exception.message_dict.get("level") self.assertEqual(expected_message, message_list[0])
def test_character_name_length(self): """Character names cannot be over 75 characters long.""" name = "thisisareaallylongname" "fhenjnndeukabandnjndehbdehbhdbehbdehbhdbjndejnjdnejndjendj" player = make_player() toon = Character(name=name, server=0, player=player) with self.assertRaises(ValidationError) as err: toon.full_clean() expected_message = "Ensure this value has at most 75 characters " "(it has 80)." message_list = err.exception.message_dict.get("name") self.assertEqual(expected_message, message_list[0])
def test_character_update_description(self): """You should be able to update a Character description.""" player = make_player() toon = Character(name="My SuperDude", server=0, player=player) description = """ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.""" toon.description = description self.assertEqual(description, toon.description)
def test_character_udpate_image(self): """Characters should be able to specify an image. This test is for completeness sake. Most of this is hidden away behind the model, admin, or form interactions. """ toon = Character(name="ToonWithImage") img = models.ImageField("toon_with_image.png") toon.image = img self.assertEqual(img, toon.image)
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 add_character(request): """A view for a player to add a character.""" form = None if request.POST: character = Character(player=request.user) form = AddCharacterForm(request.POST, instance=character) if form.is_valid(): character = form.save() character_args = (character.get_server_display(), character.name) return HttpResponseRedirect( reverse('character_profile', args=character_args)) else: form = AddCharacterForm() data = { 'form': form, } return render(request, 'characters/add.html', data)
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_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)
def test_character_update_combat_rating(self): """A Character can have a combat_rating.""" toon = Character(name="Someone") toon.combat_rating = 64 self.assertEqual(64, toon.combat_rating)
def test_character_update_skill_points(self): """A Character can track his skill points.""" toon = Character(name="SomeToon") toon.skill_points = 101 self.assertEqual(101, toon.skill_points)
def test_character_update_league(self): """You should be able to update a Character's league.""" toon = Character() toon.league = "Exobyte Titans" self.assertEqual("Exobyte Titans", toon.league)
def test_character_update_is_main(self): """You should be able to set a Character as your main toon.""" toon = Character() toon.is_main = True self.assertTrue(toon.is_main)
def test_character_update_level(self): """You should be able to update a Character's level.""" toon = Character(name="EvilVillainToon") toon.level = 30 self.assertEqual(30, toon.level)
def test_character_update_lfg(self): """You should be able to update LFG status for a Character.""" toon = Character() toon.lfg = True self.assertTrue(toon.lfg)