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_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_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_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_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])