~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/clusterrpc/tests/test_architecture.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for `list_supported_architectures`."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = []
 
16
 
 
17
 
 
18
from collections import OrderedDict
 
19
 
 
20
from maasserver.clusterrpc import architecture
 
21
from maasserver.testing.factory import factory
 
22
from maasserver.testing.testcase import MAASServerTestCase
 
23
 
 
24
 
 
25
class TestListSupportedArchitectures(MAASServerTestCase):
 
26
 
 
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([
 
31
            {
 
32
                'architectures': [
 
33
                    {'name': arch, 'description': description},
 
34
                ],
 
35
            },
 
36
        ])
 
37
        choices = architecture.list_supported_architectures()
 
38
        self.assertEqual(OrderedDict([(arch, description)]), choices)
 
39
 
 
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([
 
43
            {'architectures': [
 
44
                {'name': arch1, 'description': arch1},
 
45
                {'name': arch3, 'description': arch3},
 
46
                ]},
 
47
            {'architectures': [
 
48
                {'name': arch2, 'description': arch2},
 
49
                {'name': arch3, 'description': arch3},
 
50
                ]},
 
51
        ])
 
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)
 
56
 
 
57
    def test_returns_empty_list_if_there_are_no_node_groups(self):
 
58
        self.assertEqual(
 
59
            OrderedDict(), architecture.list_supported_architectures())
 
60
 
 
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([
 
64
            {'architectures': [
 
65
                {'name': arch, 'description': factory.make_name('desc')}
 
66
                for arch in architectures
 
67
                ]},
 
68
        ])
 
69
        self.assertEqual(
 
70
            sorted(architectures),
 
71
            architecture.list_supported_architectures().keys())