Skip to content

Instantly share code, notes, and snippets.

@jtomasek
Created December 17, 2013 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtomasek/8003963 to your computer and use it in GitHub Desktop.
Save jtomasek/8003963 to your computer and use it in GitHub Desktop.
# -*- coding: utf8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core import urlresolvers
from django import http
from mox import IsA # noqa
from mock import MagicMock
from tuskar_ui import api as tuskar
from tuskar_ui.test import helpers as test
INDEX_URL = urlresolvers.reverse('horizon:infrastructure:resources.free'
':index')
RESOURCES_OVERVIEW_URL = urlresolvers.reverse('horizon:infrastructure:'
'resources.overview:index')
class FreeNodesTests(test.BaseAdminViewTests):
def setUp(self):
super(FreeNodesTests, self).setUp()
@test.create_stubs({
tuskar.BaremetalNode: ('list',),
})
def test_index(self):
free_nodes = self.baremetal_nodes.list()
# tuskar.BaremetalNode.list(
# IsA(http.HttpRequest)).AndReturn(free_nodes)
# self.mox.ReplayAll()
tuskar.BaremetalNode.list = MagicMock(return_value=free_nodes)
tuskar.BaremetalNode.list()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(
res, 'infrastructure/resources.free/index.html')
self.assertItemsEqual(res.context['free_nodes_table'].data,
free_nodes)
@test.create_stubs({
tuskar.BaremetalNode: ('list',),
})
def test_index_nodes_list_exception(self):
tuskar.BaremetalNode.list(
IsA(http.HttpRequest)).AndRaise(self.exceptions.tuskar)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertRedirectsNoFollow(res, RESOURCES_OVERVIEW_URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment