def test_view_class(self): """test various methods of instantiation and properties""" ddoc = DesignDocument(mock.Mock(), "_design/tests") view1 = View(ddoc, "view1", map_func=self.map_func, reduce_func=self.reduce_func) view2 = View(ddoc, "view2", map_func=self.map_func) view3 = View(ddoc, "view1", map_func=Code(self.map_func), reduce_func=Code(self.reduce_func)) view4 = View(ddoc, "view1", map_func=Code(self.map_func)) self.assertEqual(view1.map, Code(self.map_func)) self.assertEqual(view1.reduce, Code(self.reduce_func)) self.assertEqual(view2.map, Code(self.map_func)) self.assertEqual(view2.reduce, None) self.assertEqual(view3.map, Code(self.map_func)) self.assertEqual(view3.reduce, Code(self.reduce_func)) self.assertEqual(view4.map, Code(self.map_func)) self.assertEqual(view4.reduce, None) view5 = View(ddoc, "view5") self.assertEqual(view5.map, None) self.assertEqual(view5.reduce, None) view5.map = self.map_func self.assertEqual(view5.map, Code(self.map_func)) view5.reduce = self.reduce_func self.assertEqual(view5.reduce, Code(self.reduce_func))
def test_map_setter(self): """ Test that the map setter works """ ddoc = DesignDocument(self.db, "ddoc001") view = View(ddoc, "view001") self.assertIsNone(view.get("map")) view.map = "function (doc) {\n emit(doc._id, 1);\n}" self.assertEqual(view.get("map"), "function (doc) {\n emit(doc._id, 1);\n}")
def test_map_getter(self): """ Test that the map getter works """ ddoc = DesignDocument(self.db, 'ddoc001') view = View(ddoc, 'view001') self.assertIsNone(view.map) view.map = 'function (doc) {\n emit(doc._id, 1);\n}' self.assertIsInstance(view.map, Code) self.assertEqual(view.map, 'function (doc) {\n emit(doc._id, 1);\n}')
def test_map_setter(self): """ Test that the map setter works """ ddoc = DesignDocument(self.db, 'ddoc001') view = View(ddoc, 'view001') self.assertIsNone(view.get('map')) view.map = 'function (doc) {\n emit(doc._id, 1);\n}' self.assertEqual( view.get('map'), 'function (doc) {\n emit(doc._id, 1);\n}' )