def test_pickup(self): player = players.Thief() #If scroll learn it #If weapon equip it - if no weapon equipped and proficient #If armor equip it - if no armor equipped and proficient #Scroll scroll = MockHelper.get_mock_scroll() player.learn_spell = Mock(return_value=True) self.assertTrue(player.pickup(scroll)) player.learn_spell.assert_called_once() #Weapon weapon = MockHelper.get_mock_weapon() weapon.get_modifier_value = Mock(return_value=0) #Not proficient player.character_class.is_weapon_proficient = Mock(return_value=False) self.assertFalse(player.has_weapon_equipped()) self.assertTrue(player.pickup(weapon)) self.assertFalse(player.has_weapon_equipped()) self.assertNotEqual(player.get_equipped_weapon(), weapon) #Proficient player.character_class.is_weapon_proficient = Mock(return_value=True) self.assertFalse(player.has_weapon_equipped()) self.assertTrue(player.pickup(weapon)) self.assertTrue(player.has_weapon_equipped()) self.assertEqual(player.get_equipped_weapon(), weapon) #Already equipped another_weapon = MockHelper.get_mock_weapon() self.assertTrue(player.pickup(another_weapon)) self.assertTrue(player.has_weapon_equipped()) self.assertEqual(player.get_equipped_weapon(), weapon) #Armor myarmor = MockHelper.get_mock_armor() myarmor.get_modifier_value = Mock(return_value=0) #Not proficient player.character_class.is_armor_proficient = Mock(return_value=False) self.assertFalse(player.has_armor_equipped()) self.assertTrue(player.pickup(myarmor)) self.assertFalse(player.has_armor_equipped()) self.assertNotEqual(player.get_equipped_armor(), myarmor) #Proficient player.character_class.is_armor_proficient = Mock(return_value=True) self.assertFalse(player.has_armor_equipped()) self.assertTrue(player.pickup(myarmor)) self.assertTrue(player.has_armor_equipped()) self.assertEqual(player.get_equipped_armor(), myarmor) #Already equipped another_armor = MockHelper.get_mock_armor() self.assertTrue(player.pickup(another_armor)) self.assertTrue(player.has_armor_equipped()) self.assertEqual(player.get_equipped_armor(), myarmor)
def test_equip_armor(self): #Check default armor player = players.Thief() self.assertEqual(player.get_equipped_armor(), player.default_armor) #Equip something that isn't armor fake_armor = Mock() self.assertFalse(player.equip_armor(fake_armor)) #Not carrying good_armor = MockHelper.get_mock_armor() player.is_carrying = Mock(return_value=False) self.assertFalse(player.equip_armor(good_armor)) player.is_carrying.assert_called_once() #Equip Armor player.is_carrying = Mock(return_value=True) self.assertTrue(player.equip_armor(good_armor)) #Equip None, should be default try: player.equip_armor(None) except AttributeError: self.assertTrue(True, 'None is not valid') self.assertEqual(player.get_equipped_armor(), good_armor)
def test_remove_item(self): player = players.Thief() #Not carrying item does nothing #Removing equipped armor resets to default #Removing equipped weapon resets to default #Armor myarmor = MockHelper.get_mock_armor() myarmor.get_modifier_value = Mock(return_value=0) #Nothing to remove self.assertFalse(player.remove_item(myarmor)) #Remove equipped armor player.character_class.is_armor_proficient = Mock(return_value=True) self.assertTrue(player.pickup(myarmor)) self.assertEqual(player.get_equipped_armor(), myarmor) self.assertTrue(player.has_armor_equipped()) self.assertTrue(player.remove_item(myarmor)) self.assertNotEqual(player.get_equipped_armor(), myarmor) self.assertFalse(player.has_armor_equipped()) #Remove equipped weapon weapon = MockHelper.get_mock_weapon() weapon.get_modifier_value = Mock(return_value=0) player.character_class.is_weapon_proficient = Mock(return_value=True) self.assertTrue(player.pickup(weapon)) self.assertTrue(player.has_weapon_equipped()) self.assertEqual(player.get_equipped_weapon(), weapon) self.assertTrue(player.remove_item(weapon)) self.assertNotEqual(player.get_equipped_weapon(), weapon) self.assertFalse(player.has_weapon_equipped())
def test_has_weapon_equipped(self): player = players.Thief() self.assertFalse(player.has_armor_equipped()) armor = MockHelper.get_mock_armor() player.is_carrying = Mock(return_value=True) self.assertTrue(player.equip_armor(armor)) self.assertTrue(player.has_armor_equipped())