Created
December 17, 2013 12:08
-
-
Save jtomasek/8003963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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