Merge lp:~methanal-developers/methanal/broken-autoitemview into lp:methanal

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Tristan Seligmann
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~methanal-developers/methanal/broken-autoitemview
Merge into: lp:methanal
Diff against target: 140 lines (+65/-10)
2 files modified
methanal/test/test_view.py (+62/-8)
methanal/view.py (+3/-2)
To merge this branch: bzr merge lp:~methanal-developers/methanal/broken-autoitemview
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+17941@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'methanal/test/test_view.py'
2--- methanal/test/test_view.py 2009-10-20 13:43:25 +0000
3+++ methanal/test/test_view.py 2010-01-23 15:15:24 +0000
4@@ -561,6 +561,8 @@
5 """
6 Tests for L{methanal.view.ItemViewBase}.
7 """
8+ viewType = view.ItemViewBase
9+
10 def setUp(self):
11 self.store = Store()
12 self.item = TestItem(store=self.store)
13@@ -568,9 +570,9 @@
14
15 def test_createWithItem(self):
16 """
17- Create an ItemViewBase with an axiom Item instance.
18+ Create an item view with an axiom Item instance.
19 """
20- iv = view.ItemViewBase(item=self.item)
21+ iv = self.viewType(item=self.item)
22 self.assertIdentical(iv.store, self.store)
23 self.assertIdentical(iv.itemClass, type(self.item))
24 self.assertIdentical(iv.original, self.item)
25@@ -578,27 +580,79 @@
26
27 def test_createWithItemClass(self):
28 """
29- Create an ItemViewBase with an axiom Item type and store, an exception
30+ Create an item view with an axiom Item type and store, an exception
31 is raised if the C{store} parameter is not given.
32 """
33- iv = view.ItemViewBase(itemClass=type(self.item), store=self.store)
34+ iv = self.viewType(itemClass=type(self.item), store=self.store)
35 self.assertIdentical(iv.store, self.store)
36 self.assertIdentical(iv.itemClass, type(self.item))
37 self.assertIdentical(iv.original, type(self.item))
38
39- self.assertRaises(ValueError,
40- view.ItemViewBase, itemClass=type(self.item))
41+ self.assertRaises(ValueError, self.viewType, itemClass=type(self.item))
42
43
44 def test_customModelFactory(self):
45 """
46- Creating an ItemViewBase subclass with a custom model factory.
47+ Creating an item view subclass with a custom model factory.
48 """
49 class TestModel(ItemModel):
50 pass
51
52- class CustomItemView(view.ItemViewBase):
53+ class CustomItemView(self.viewType):
54 modelFactory = TestModel
55
56 iv = CustomItemView(item=self.item)
57 self.assertTrue(isinstance(iv.model, TestModel))
58+
59+
60+
61+class ItemViewTests(ItemViewBaseTests):
62+ """
63+ Tests for L{methanal.view.ItemView}.
64+ """
65+ viewType = view.ItemView
66+
67+ def test_invoke(self):
68+ """
69+ Invoking an item view will set the attributes on the underlying item to
70+ the invoked values for the available inputs.
71+ """
72+ iv = self.viewType(item=self.item)
73+ # Without inputs, invoking the item view won't do anything.
74+ view.TextInput(parent=iv, name='foo')
75+ view.CheckboxInput(parent=iv, name='bar')
76+ iv.invoke({'foo': u'hello',
77+ 'bar': False})
78+
79+ item = iv.item
80+ self.assertIdentical(item, self.item)
81+ self.assertEquals(item.foo, u'hello')
82+ self.assertEquals(item.bar, False)
83+
84+
85+ def test_invokeWithItemClass(self):
86+ """
87+ Invoking an item view, without a concrete underlying item, will create
88+ the item, with the invoked values, when invoked.
89+ """
90+ iv = self.viewType(
91+ store=self.store, itemClass=type(self.item), switchInPlace=True)
92+ self.assertIdentical(iv.item, None)
93+ # Without inputs, invoking the item view won't do anything.
94+ view.TextInput(parent=iv, name='foo')
95+ view.CheckboxInput(parent=iv, name='bar')
96+ iv.invoke({'foo': u'hello',
97+ 'bar': False})
98+
99+ item = iv.item
100+ self.assertNotIdentical(item, None)
101+ self.assertEquals(item.foo, u'hello')
102+ self.assertEquals(item.bar, False)
103+
104+
105+
106+class AutoItemViewTests(ItemViewTests):
107+ """
108+ Tests for L{methanal.view.AutoItemView}.
109+ """
110+ viewType = view.AutoItemView
111
112=== modified file 'methanal/view.py'
113--- methanal/view.py 2009-10-24 13:12:53 +0000
114+++ methanal/view.py 2010-01-23 15:15:24 +0000
115@@ -6,7 +6,7 @@
116
117 from twisted.python.components import registerAdapter
118
119-from axiom.attributes import text, integer, timestamp
120+from axiom.attributes import text, integer, timestamp, boolean
121
122 from nevow.page import renderer
123 from nevow.athena import expose
124@@ -1046,7 +1046,7 @@
125 @type env: C{dict}
126 @param env: Additional parameters to pass when creating inputs
127 """
128- super(AutoItemView, **kw)
129+ super(AutoItemView, self).__init__(**kw)
130
131 if env is None:
132 env = {}
133@@ -1057,6 +1057,7 @@
134
135
136 _inputTypes = {
137+ boolean: lambda env: CheckboxInput,
138 text: lambda env: TextInput,
139 integer: lambda env: IntegerInput,
140 timestamp: lambda env:

Subscribers

People subscribed via source and target branches