class TestBeginner(TestCase): def setUp(self): self.beginner_player = Beginner('User2') def test_attributes_are_set(self): self.assertEqual('User2', self.beginner_player.username) self.assertEqual(50, self.beginner_player.health) def test_set_username_with_empty_string__raises(self): with self.assertRaises(ValueError) as ex: self.beginner_player.username(player=Beginner("")) self.assertEqual("Player's username cannot be an empty string.", str(ex.exception)) def test_set_username(self): player_2 = Beginner("Bil") self.assertEqual("Bil", player_2.username) def test_check_class_name(self): self.assertEqual("Beginner", self.beginner_player.__class__.__name__)
def test_set_new_username_should_change_players_username(self): player = Beginner("Peter") player.username = "******" self.assertEqual(player.username, "George")
def test_set_empty_string_username_should_raise_error(self): player = Beginner("Peter") with self.assertRaises(ValueError): player.username = ""
def test_username_setter(self): beg = Beginner('test') beg.username = '******' self.assertEqual('new', beg.username)
def test_username_raise(self): beg = Beginner('test') with self.assertRaises(ValueError) as ex: beg.username = '' self.assertEqual(str(ex.exception), 'Player\'s username cannot be an empty string.')
def test_username_invalid_data_should_raise_error(self): player = Beginner("Dave") with self.assertRaises(ValueError): player.username = ""
def test_username_valid_data_should_work_correctly(self): player = Beginner("Dave") player.username = "******" self.assertEqual(player.username, "Cool")
def test_username_change(self): a = Beginner("test") a.username = '******' self.assertEqual(a.username, 'new name')