10373.5.2
by Jelmer Vernooij
Add IProcessorFamilySet.new. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Test Processor and ProcessorFamily features."""
|
|
5 |
||
6 |
from zope.component import getUtility |
|
7 |
||
14600.2.2
by Curtis Hovey
Moved webapp to lp.services. |
8 |
from lp.services.webapp.interfaces import ( |
13387.1.8
by Francis J. Lacoste
Add an IProcessSet |
9 |
DEFAULT_FLAVOR, |
10 |
IStoreSelector, |
|
11 |
MAIN_STORE, |
|
12 |
)
|
|
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
13 |
from lp.soyuz.interfaces.processor import ( |
14 |
IProcessor, |
|
15 |
IProcessorFamily, |
|
16 |
IProcessorFamilySet, |
|
13387.1.8
by Francis J. Lacoste
Add an IProcessSet |
17 |
IProcessorSet, |
18 |
ProcessorNotFound, |
|
19 |
)
|
|
20 |
from lp.testing import ( |
|
21 |
ExpectedException, |
|
13387.1.11
by Francis J. Lacoste
Export processors collection. |
22 |
logout, |
13387.1.8
by Francis J. Lacoste
Add an IProcessSet |
23 |
TestCaseWithFactory, |
24 |
)
|
|
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
25 |
from lp.testing.layers import ( |
26 |
DatabaseFunctionalLayer, |
|
27 |
LaunchpadZopelessLayer, |
|
28 |
)
|
|
14578.4.4
by William Grant
format-imports. |
29 |
from lp.testing.pages import LaunchpadWebServiceCaller |
10373.5.2
by Jelmer Vernooij
Add IProcessorFamilySet.new. |
30 |
|
31 |
||
32 |
class ProcessorFamilyTests(TestCaseWithFactory): |
|
7675.557.10
by Jelmer Vernooij
Some review comments from Muharem. |
33 |
"""Test ProcessorFamily."""
|
10373.5.2
by Jelmer Vernooij
Add IProcessorFamilySet.new. |
34 |
|
35 |
layer = LaunchpadZopelessLayer |
|
36 |
||
37 |
def test_create(self): |
|
7675.557.17
by Jelmer Vernooij
Add docstrings. |
38 |
"""Test adding a new ProcessorFamily."""
|
10373.5.2
by Jelmer Vernooij
Add IProcessorFamilySet.new. |
39 |
family = getUtility(IProcessorFamilySet).new("avr", "Atmel AVR", |
7675.557.7
by Jelmer Vernooij
Add IProcessorFamily.addProcessor. |
40 |
"The Modified Harvard architecture 8-bit RISC processors.") |
10373.5.2
by Jelmer Vernooij
Add IProcessorFamilySet.new. |
41 |
self.assertProvides(family, IProcessorFamily) |
7675.557.7
by Jelmer Vernooij
Add IProcessorFamily.addProcessor. |
42 |
|
43 |
def test_add_processor(self): |
|
7675.557.17
by Jelmer Vernooij
Add docstrings. |
44 |
"""Test adding a new Processor to a ProcessorFamily."""
|
7675.557.7
by Jelmer Vernooij
Add IProcessorFamily.addProcessor. |
45 |
family = getUtility(IProcessorFamilySet).new("avr", "Atmel AVR", |
46 |
"The Modified Harvard architecture 8-bit RISC processors.") |
|
13387.1.20
by Francis J. Lacoste
Lint sucks, but hoover blows. |
47 |
proc = family.addProcessor( |
48 |
"avr2001", "The 2001 AVR", "Fast as light.") |
|
7675.557.7
by Jelmer Vernooij
Add IProcessorFamily.addProcessor. |
49 |
self.assertProvides(proc, IProcessor) |
7675.557.10
by Jelmer Vernooij
Some review comments from Muharem. |
50 |
self.assertEquals(family, proc.family) |
11065.4.1
by Jelmer Vernooij
Add IProcessorFamilySet.getRestricted. |
51 |
|
52 |
def test_get_restricted(self): |
|
53 |
"""Test retrieving all restricted processors."""
|
|
54 |
family_set = getUtility(IProcessorFamilySet) |
|
13387.1.20
by Francis J. Lacoste
Lint sucks, but hoover blows. |
55 |
normal_family = getUtility(IProcessorFamilySet).new( |
56 |
"avr", "Atmel AVR", |
|
11065.4.1
by Jelmer Vernooij
Add IProcessorFamilySet.getRestricted. |
57 |
"The Modified Harvard architecture 8-bit RISC processors.") |
13387.1.20
by Francis J. Lacoste
Lint sucks, but hoover blows. |
58 |
restricted_family = getUtility(IProcessorFamilySet).new( |
59 |
"5051", "5051", "Another small processor family", |
|
60 |
restricted=True) |
|
11065.4.1
by Jelmer Vernooij
Add IProcessorFamilySet.getRestricted. |
61 |
self.assertFalse(normal_family in family_set.getRestricted()) |
62 |
self.assertTrue(restricted_family in family_set.getRestricted()) |
|
13387.1.8
by Francis J. Lacoste
Add an IProcessSet |
63 |
|
64 |
||
65 |
class ProcessorSetTests(TestCaseWithFactory): |
|
66 |
layer = DatabaseFunctionalLayer |
|
67 |
||
68 |
def test_getByName(self): |
|
69 |
processor_set = getUtility(IProcessorSet) |
|
70 |
q1 = self.factory.makeProcessorFamily(name='q1') |
|
71 |
self.assertEquals(q1.processors[0], processor_set.getByName('q1')) |
|
72 |
||
73 |
def test_getByName_not_found(self): |
|
74 |
processor_set = getUtility(IProcessorSet) |
|
75 |
with ExpectedException(ProcessorNotFound, 'No such processor.*'): |
|
76 |
processor_set.getByName('q1') |
|
77 |
||
78 |
def test_getAll(self): |
|
79 |
processor_set = getUtility(IProcessorSet) |
|
80 |
# Make it easy to filter out sample data
|
|
81 |
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
|
82 |
store.execute("UPDATE Processor SET name = 'sample_data_' || name") |
|
83 |
self.factory.makeProcessorFamily(name='q1') |
|
84 |
self.factory.makeProcessorFamily(name='i686') |
|
85 |
self.factory.makeProcessorFamily(name='g4') |
|
86 |
self.assertEquals( |
|
87 |
['g4', 'i686', 'q1'], |
|
88 |
sorted( |
|
89 |
processor.name for processor in processor_set.getAll() |
|
13387.1.20
by Francis J. Lacoste
Lint sucks, but hoover blows. |
90 |
if not processor.name.startswith('sample_data_'))) |
13387.1.11
by Francis J. Lacoste
Export processors collection. |
91 |
|
92 |
||
93 |
class ProcessorSetWebServiceTests(TestCaseWithFactory): |
|
94 |
layer = DatabaseFunctionalLayer |
|
95 |
||
96 |
def setUp(self): |
|
97 |
super(ProcessorSetWebServiceTests, self).setUp() |
|
98 |
self.webservice = LaunchpadWebServiceCaller() |
|
99 |
||
100 |
def test_getByName(self): |
|
101 |
self.factory.makeProcessorFamily(name='transmeta') |
|
102 |
logout() |
|
103 |
||
104 |
processor = self.webservice.named_get( |
|
105 |
'/+processors', 'getByName', name='transmeta', |
|
106 |
api_version='devel', |
|
107 |
).jsonBody() |
|
108 |
self.assertEquals('transmeta', processor['name']) |
|
109 |
||
110 |
def test_default_collection(self): |
|
111 |
# Make it easy to filter out sample data
|
|
112 |
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
|
113 |
store.execute("UPDATE Processor SET name = 'sample_data_' || name") |
|
114 |
self.factory.makeProcessorFamily(name='q1') |
|
115 |
self.factory.makeProcessorFamily(name='i686') |
|
116 |
self.factory.makeProcessorFamily(name='g4') |
|
117 |
||
118 |
logout() |
|
119 |
||
120 |
collection = self.webservice.get( |
|
121 |
'/+processors?ws.size=10', api_version='devel').jsonBody() |
|
122 |
self.assertEquals( |
|
123 |
['g4', 'i686', 'q1'], |
|
124 |
sorted( |
|
13387.1.20
by Francis J. Lacoste
Lint sucks, but hoover blows. |
125 |
processor['name'] for processor in collection['entries'] |
126 |
if not processor['name'].startswith('sample_data_'))) |