1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for `list_supported_architectures`."""
6
from __future__ import (
18
from collections import OrderedDict
20
from maasserver.clusterrpc import architecture
21
from maasserver.testing.factory import factory
22
from maasserver.testing.testcase import MAASServerTestCase
25
class TestListSupportedArchitectures(MAASServerTestCase):
27
def test_lists_architecture_choices(self):
28
arch = factory.make_name('arch')
29
description = factory.make_name('description')
30
self.patch(architecture, 'call_clusters').return_value = iter([
33
{'name': arch, 'description': description},
37
choices = architecture.list_supported_architectures()
38
self.assertEqual(OrderedDict([(arch, description)]), choices)
40
def test_merges_results_from_multiple_nodegroups(self):
41
arch1, arch2, arch3 = (factory.make_name('arch') for _ in range(3))
42
self.patch(architecture, 'call_clusters').return_value = iter([
44
{'name': arch1, 'description': arch1},
45
{'name': arch3, 'description': arch3},
48
{'name': arch2, 'description': arch2},
49
{'name': arch3, 'description': arch3},
52
choices = architecture.list_supported_architectures()
53
expected_choices = OrderedDict(
54
(name, name) for name in sorted([arch1, arch2, arch3]))
55
self.assertEqual(expected_choices, choices)
57
def test_returns_empty_list_if_there_are_no_node_groups(self):
59
OrderedDict(), architecture.list_supported_architectures())
61
def test_sorts_results(self):
62
architectures = [factory.make_name('arch') for _ in range(3)]
63
self.patch(architecture, 'call_clusters').return_value = iter([
65
{'name': arch, 'description': factory.make_name('desc')}
66
for arch in architectures
70
sorted(architectures),
71
architecture.list_supported_architectures().keys())