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 testGetFlyToLinkWithGoodData(self):
   self.assertEqual(entities._GetFlyToLink(42, 'abc'), '#id42;abc')
   self.assertEqual(entities._GetFlyToLink(42, 'abc', 'def'), 'def')
   link_template = 'a' + settings.BALLOON_LINK_PLACEHOLDER + 'b'
   self.assertEqual(entities._GetFlyToLink(42, 'abc', link_template), 'aid42b')