def testGetOffsetLink(self):
    mock_entity = MockEntity(6, 16)
    mock_entity.layer.auto_managed = False
    self.mox.StubOutWithMock(pages.template.django.template, 'resolve_variable')
    self.mox.StubOutWithMock(entities, '_GetEntitySiblings')
    self.mox.StubOutWithMock(entities, '_GetFlyToLink')
    dummy_siblings_list = [5, 6, 7, 8, 9, 10]

    pages.template.django.template.resolve_variable(
        '_cache', 'dummy-context').AndReturn('dummy-cache')
    pages.template.django.template.resolve_variable(
        '_link_template', 'dummy-context').AndReturn('dummy-template')
    entities._GetEntitySiblings(mock_entity, 'dummy-cache').AndReturn(
        dummy_siblings_list)
    entities._GetFlyToLink(8, 'balloon', 'dummy-template').AndReturn(
        'dummy-link1')

    pages.template.django.template.resolve_variable(
        '_cache', 'dummy-context').AndReturn('dummy-cache')
    pages.template.django.template.resolve_variable(
        '_link_template', 'dummy-context').AndReturn('dummy-template')
    entities._GetEntitySiblings(mock_entity, 'dummy-cache').AndReturn(
        dummy_siblings_list)
    entities._GetFlyToLink(10, 'balloon', 'dummy-template').AndReturn(
        'dummy-link2')

    self.mox.ReplayAll()

    link = entities._GetOffsetLink('dummy-context', mock_entity, 2, 'balloon')
    self.assertEqual(link, 'dummy-link1')

    link = entities._GetOffsetLink('dummy-context', mock_entity, -2, 'balloon')
    self.assertEqual(link, 'dummy-link2')

    mock_entity.layer.auto_managed = True
    self.assertRaises(ValueError, entities._GetOffsetLink,
                      'dummy-context', mock_entity, -2, 'balloon')
 def testNextLink(self):
   self.mox.StubOutWithMock(entities, '_GetOffsetLink')
   entities._GetOffsetLink('a', 'b', 1, 'balloonFlyto').AndReturn('c')
   self.mox.ReplayAll()
   self.assertEqual(entities.NextLink('a', 'b'), 'c')