Merge lp://qastaging/~rick-rickspencer3/desktopcouch/couchwidgetfixandtests into lp://qastaging/desktopcouch

Proposed by Rick Spencer
Status: Merged
Approved by: Elliot Murphy
Approved revision: 39
Merged at revision: not available
Proposed branch: lp://qastaging/~rick-rickspencer3/desktopcouch/couchwidgetfixandtests
Merge into: lp://qastaging/desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~rick-rickspencer3/desktopcouch/couchwidgetfixandtests
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Review via email: mp+10432@code.qastaging.launchpad.net

Commit message

added unit tests for couchwidget, and then fixed bug #412266

To post a comment you must log in.
Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

There are two changes here:
1. I added unit tests for CouchWidget, with two initial tests to ensure that CouchWidget is set up correctly.
2. I fixed bug #41226 - though I suspect there are similar bugs that I will find when I build out the unit tests.

Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

There are two changes here:
1. I added unit tests for CouchWidget, with two initial tests to ensure that CouchWidget is set up correctly.
2. I fixed bug #41226 - though I suspect there are similar bugs that I will find when I build out the unit tests.

Revision history for this message
Elliot Murphy (statik) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/couchwidget.py'
2--- desktopcouch/records/couchwidget.py 2009-08-18 23:05:18 +0000
3+++ desktopcouch/records/couchwidget.py 2009-08-19 23:01:09 +0000
4@@ -67,7 +67,7 @@
5 def headings(self, headings):
6 self.__headings = headings
7 if self.record_type != None:
8- self.__populate_treeview()(self.record_type)
9+ self.__populate_treeview()
10
11 @property
12 def editable(self):
13@@ -119,7 +119,7 @@
14
15 def __populate_treeview(self):
16 #if the database is not set up, just return
17- if self.__db == None:
18+ if self.__db == None or self.__headings == None:
19 return
20
21 #refresh the model structure
22
23=== added file 'desktopcouch/records/tests/test_couchwidget.py'
24--- desktopcouch/records/tests/test_couchwidget.py 1970-01-01 00:00:00 +0000
25+++ desktopcouch/records/tests/test_couchwidget.py 2009-08-19 23:01:09 +0000
26@@ -0,0 +1,94 @@
27+# Copyright 2009 Canonical Ltd.
28+#
29+# This file is part of desktopcouch.
30+#
31+# desktopcouch is free software: you can redistribute it and/or modify
32+# it under the terms of the GNU Lesser General Public License version 3
33+# as published by the Free Software Foundation.
34+#
35+# desktopcouch is distributed in the hope that it will be useful,
36+# but WITHOUT ANY WARRANTY; without even the implied warranty of
37+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+# GNU Lesser General Public License for more details.
39+#
40+# You should have received a copy of the GNU Lesser General Public License
41+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
42+#
43+# Authors: Rick Spencer <rick.spencer@canonical.com>
44+
45+"""Tests for the couchwidget object"""
46+
47+from testtools import TestCase
48+from desktopcouch.records.server import CouchDatabase
49+from desktopcouch.records.couchwidget import CouchWidget
50+
51+class TestCouchWidget(TestCase):
52+ """Test the CouchWidget functionality"""
53+ def setUp(self):
54+ self.dbname = "couch_widget_test"
55+ self.record_type = "test_record_type"
56+
57+ def test_headings_first(self):
58+ #create a test widget with test database values
59+ cw = CouchWidget()
60+ cw.database = self.dbname
61+
62+ #allow editing
63+ cw.editable = True
64+
65+ #create headers/keys
66+ cw.headings = ["Key1","Key2","Key3","Key4"]
67+
68+ #set the record_type for the TreeView
69+ #it will not populate without this value being set
70+ cw.record_type = self.record_type
71+
72+ #create a row with all four columns set
73+ cw.append_row(["val1","val2","val3","val4"])
74+
75+ #create a row with only the second column set
76+ cw.append_row(["","val2"])
77+
78+ #create an empty row (which will not be saved until the user edits it)
79+ cw.append_row([])
80+
81+ self.assertEqual(cw.record_type, self.record_type)
82+ self.__delete_db()
83+
84+ def test_record_type_first(self):
85+ #create a test widget with test database values
86+ cw = CouchWidget()
87+ cw.database = self.dbname
88+
89+ #allow editing
90+ cw.editable = True
91+
92+ #set the record_type for the TreeView
93+ #it will not populate without this value being set
94+ cw.record_type = self.record_type
95+
96+ #create headers/keys
97+ cw.headings = ["Key1","Key2","Key3","Key4"]
98+
99+ #create a row with all four columns set
100+ cw.append_row(["val1","val2","val3","val4"])
101+
102+ #create a row with only the second column set
103+ cw.append_row(["","val2"])
104+
105+ #create an empty row (which will not be saved until the user edits it)
106+ cw.append_row([])
107+
108+ self.assertEqual(cw.record_type, self.record_type)
109+ self.__delete_db()
110+
111+ def tearDown(self):
112+ """tear down each test"""
113+ self.__delete_db()
114+ #delete the database
115+
116+ def __delete_db(self):
117+ db = CouchDatabase(self.dbname, create=True)
118+ del db._server[self.dbname]
119+
120+

Subscribers

People subscribed via source and target branches