def test_OpenPortal(self): self.assertSimple( OpenPortal('foo', 'ore', 'joe'), { 'action': 'openportal', 'subject': 'foo', 'ore': 'ore', 'portal_user': '******' })
def usedPortal(self): self.world = World(MagicMock()) self.place = self.world.create('place') self.ore = self.world.create('ore') self.bot = self.world.create('bot') self.lander = self.world.create('lander') Move(self.ore['id'], self.place['id']).execute(self.world) OpenPortal(self.bot['id'], self.ore['id'], self.lander['id']).execute(self.world) UsePortal(self.lander['id'], self.ore['id']).execute(self.world)
def test_open(self): """ You can open a portal on from some ore. """ world = World(MagicMock()) ore = world.create('ore') bot = world.create('bot') OpenPortal(bot['id'], ore['id'], 'user').execute(world) self.assertEqual( ore['portal_user'], 'user', "Should set the portal " "user to the id of the user that can use the portal") self.assertEqual(ore['kind'], 'portal')
def test_openerDies(self): """ If the opener dies before the portal is used, the portal reverts to ore. """ world = World(MagicMock()) ore = world.create('ore') bot = world.create('bot') OpenPortal(bot['id'], ore['id'], 'user').execute(world) # it is death to move to the void Move(bot['id'], None).execute(world) self.assertEqual(ore['kind'], 'ore') self.assertNotIn('portal_user', ore)
def test_portal_user_noMatch(self): """ It is NotAllowed to use a portal with a portal_user different than the thing trying to use the portal. """ world = World(MagicMock()) place = world.create('place') ore = world.create('ore') bot = world.create('bot') lander = world.create('lander') imposter = world.create('imposter') Move(ore['id'], place['id']).execute(world) OpenPortal(bot['id'], ore['id'], lander['id']).execute(world) self.assertRaises(NotAllowed, UsePortal(imposter['id'], ore['id']).execute, world)
def test_subject(self): self.assertEqual(OpenPortal('foo', 'bar', 'baz').subject(), 'foo')
def test_emitters(self): self.assertEqual( OpenPortal('me', 'ore', 'user').emitters(), ['me', 'user'])
def test_IAction(self): verifyObject(IAction, OpenPortal('me', 'ore', 'user'))
def test_OpenPortal(self): self.assertSimple(OpenPortal('foo', 'ore', 'joe'), 'foo used ore to open a portal for joe')