Skip to content

Commit 3ac9366

Browse files
Daniel Holthdjc
authored andcommitted
add rudimentary test for loader
1 parent 06bec55 commit 3ac9366

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

couchdb/loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
23
"""
34
Load design documents from the filesystem into a dict.
45
Subset of couchdbkit/couchapp functionality.

couchdb/tests/_loader/_id

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_design/loader
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function(doc, req) { return true; }

couchdb/tests/_loader/language

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
javascript

couchdb/tests/_loader/views/a/map.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function(doc) {
2+
emit(doc.property_to_index);
3+
}

couchdb/tests/loader.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2016 Daniel Holth
4+
# All rights reserved.
5+
#
6+
# This software is licensed as described in the file COPYING, which
7+
# you should have received as part of this distribution.
8+
9+
import unittest
10+
import os.path
11+
12+
from couchdb import loader
13+
from couchdb.tests import testutil
14+
15+
expected = {
16+
'_id': u'_design/loader',
17+
'filters': {'filter': u'function(doc, req) { return true; }'},
18+
'language': u'javascript',
19+
'views': {'a': {'map': u'function(doc) {\n emit(doc.property_to_index);\n}'}}}
20+
21+
class LoaderTestCase(unittest.TestCase):
22+
23+
def test_loader(self):
24+
directory = os.path.join(os.path.dirname(__file__), '_loader')
25+
doc = loader.load_design_doc(directory, strip_files=True)
26+
self.assertEqual(doc, expected)
27+
28+
29+
def suite():
30+
suite = unittest.TestSuite()
31+
suite.addTest(unittest.makeSuite(LoaderTestCase))
32+
return suite
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main(defaultTest='suite')

0 commit comments

Comments
 (0)