Merge lp://qastaging/~cmiller/desktopcouch/test-coverage into lp://qastaging/desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 98
Merged at revision: not available
Proposed branch: lp://qastaging/~cmiller/desktopcouch/test-coverage
Merge into: lp://qastaging/desktopcouch
Diff against target: 121 lines (+46/-3)
3 files modified
desktopcouch/records/tests/test_record.py (+22/-1)
desktopcouch/records/tests/test_server.py (+8/-1)
desktopcouch/tests/test_local_files.py (+16/-1)
To merge this branch: bzr merge lp://qastaging/~cmiller/desktopcouch/test-coverage
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Nicola Larosa (community) Approve
Review via email: mp+14968@code.qastaging.launchpad.net

Commit message

Add tests to exercise some code that is previously neglected by tests.

To post a comment you must log in.
Revision history for this message
Nicola Larosa (teknico) wrote :

Again, can we write down somewhere how to run tests on desktopcouch? Thanks.

review: Abstain
Revision history for this message
Nicola Larosa (teknico) wrote :

> Again, can we write down somewhere how to run tests on desktopcouch? Thanks.

And again, it was "trial desktopcouch", sorry for the blackout.

Revision history for this message
Nicola Larosa (teknico) wrote :

Tests pass, more tests is good, all is well.

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Awesome branch!

test_bind_address asks me for access to the keyring, not sure whether that's a problem in this case? Approved, but I'll be available for retesting if this needs to be fixed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/tests/test_record.py'
2--- desktopcouch/records/tests/test_record.py 2009-10-02 23:47:26 +0000
3+++ desktopcouch/records/tests/test_record.py 2009-11-17 22:45:25 +0000
4@@ -24,7 +24,7 @@
5 # pylint does not like relative imports from containing packages
6 # pylint: disable-msg=F0401
7 from desktopcouch.records.record import (Record, RecordDict, MergeableList,
8- record_factory, IllegalKeyException, validate)
9+ record_factory, IllegalKeyException, validate, NoRecordTypeSpecified)
10
11
12 class TestRecords(TestCase):
13@@ -51,6 +51,25 @@
14 }
15 self.record = Record(self.dict)
16
17+ def test_delitem(self):
18+ def f(r):
19+ del r["_id"]
20+ self.assertRaises(KeyError, f, self.record)
21+
22+ del self.record["a"]
23+
24+ def test_iter(self):
25+ self.assertEquals(sorted(list(iter(self.record))),
26+ ['a', 'b', 'record_type', 'subfield', 'subfield_uuid'])
27+
28+ def test_setitem_internal(self):
29+ def f(r):
30+ r["_id"] = "new!"
31+ self.assertRaises(IllegalKeyException, f, self.record)
32+
33+ def test_no_record_type(self):
34+ self.assertRaises(NoRecordTypeSpecified, Record, {})
35+
36 def test_get_item(self):
37 "Does a RecordDict basically wrap a dict properly?"
38 self.assertEqual(self.dict["a"], self.record["a"])
39@@ -67,6 +86,8 @@
40 self.assertEqual(
41 ['a', 'b', 'record_type', 'subfield', 'subfield_uuid'],
42 sorted(self.record.keys()))
43+ self.assertIn("a", self.record)
44+ self.assertNotIn("_id", self.record) # is internal. play dumb.
45
46 def test_application_annotations(self):
47 """Test getting application specific data."""
48
49=== modified file 'desktopcouch/records/tests/test_server.py'
50--- desktopcouch/records/tests/test_server.py 2009-11-17 17:07:41 +0000
51+++ desktopcouch/records/tests/test_server.py 2009-11-17 22:45:25 +0000
52@@ -21,7 +21,7 @@
53
54 from desktopcouch.tests import xdg_cache
55 from desktopcouch.records.server import CouchDatabase
56-from desktopcouch.records.server_base import row_is_deleted
57+from desktopcouch.records.server_base import row_is_deleted, NoSuchDatabase
58 from desktopcouch.records.record import Record
59
60 FAKE_RECORD_TYPE = "http://example.org/test"
61@@ -59,6 +59,9 @@
62 """tear down each test"""
63 del self.database._server[self.dbname]
64
65+ def test_database_not_exists(self):
66+ self.assertRaises(NoSuchDatabase, CouchDatabase, "this-must-not-exist", create=False)
67+
68 def test_get_records_by_record_type_save_view(self):
69 """Test getting mutliple records by type"""
70 records = self.database.get_records(
71@@ -100,6 +103,7 @@
72 def test_record_exists(self):
73 """Test checking whether a record exists."""
74 record = Record({'record_number': 0}, record_type="http://example.com/")
75+ self.assert_(not self.database.record_exists("ThisMustNotExist"))
76 record_id = self.database.put_record(record)
77 self.assert_(self.database.record_exists(record_id))
78 self.database.delete_record(record_id)
79@@ -179,6 +183,9 @@
80
81 self.assertTrue(len(record_ids_we_care_about) == 0, "expected zero")
82
83+ self.assertRaises(KeyError, self.database.get_records,
84+ design_doc="mustNotExist", create_view=False)
85+
86 def test_list_views(self):
87 design_doc = "d"
88 self.assertEqual(self.database.list_views(design_doc), [])
89
90=== modified file 'desktopcouch/tests/test_local_files.py'
91--- desktopcouch/tests/test_local_files.py 2009-09-14 15:56:42 +0000
92+++ desktopcouch/tests/test_local_files.py 2009-11-17 22:45:25 +0000
93@@ -1,8 +1,9 @@
94 """testing desktopcouch/local_files.py module"""
95
96 import testtools
97-from desktopcouch.tests import xdg_cache
98+import desktopcouch.tests
99 import desktopcouch
100+import os
101
102 class TestLocalFiles(testtools.TestCase):
103 """Testing that local files returns the right things"""
104@@ -25,3 +26,17 @@
105 if x.endswith("compulsory-auth.ini")]
106 self.assertTrue(len(ok) > 0)
107
108+ def test_bind_address(self):
109+ desktopcouch.start_local_couchdb.create_ini_file()
110+ desktopcouch.start_local_couchdb.create_ini_file() # Make sure the loader works.
111+
112+ old = desktopcouch.local_files.get_bind_address()
113+ octets = old.split(".")
114+ octets[2] = str((int(octets[2]) + 128) % 256)
115+ new = ".".join(octets)
116+ desktopcouch.local_files.set_bind_address(new)
117+
118+ self.assertEquals(desktopcouch.local_files.get_bind_address(), new)
119+ desktopcouch.local_files.set_bind_address(old)
120+ self.assertEquals(desktopcouch.local_files.get_bind_address(), old)
121+

Subscribers

People subscribed via source and target branches