From 71d218d3b08766a0bba066080d0d8fc3bd3705a8 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 14 Mar 2014 16:36:20 +0100 Subject: [PATCH] Some tests --- test.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..87bc196 --- /dev/null +++ b/test.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# mojo, a Python library for implementing document based databases +# Copyright (C) 2013-2014 by Javier Sancho Fernandez +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import mojo.MySQL +import unittest + +class TestSequenceFunctions(unittest.TestCase): + def setUp(self): + self.cmojo = mojo.MySQL.Connection(host="localhost", user="mojo") + + def test_simple_transaction(self): + self.cmojo.test.t1.insert({'a': 'this is a test', 'b': [1, 2, 3]}) + self.assertEqual(self.cmojo.test.t1.count(), 1) + self.cmojo.rollback() + self.assertEqual(self.cmojo.test.t1.count(), 0) + + def test_saving_lists(self): + doc_id = self.cmojo.test.t1.insert({'a': [1, 2, 3]}) + self.assertEqual(self.cmojo.test.t1.find({'a': 2}).next()['_id'], doc_id) + self.assertEqual(self.cmojo.test.t1.find({'a': [1, 2, 3]}).next()['_id'], doc_id) + + def test_saving_dictionaries(self): + doc_id = self.cmojo.test.t1.insert({'a': {'b': {'c': 10}}}) + self.assertEqual(self.cmojo.test.t1.find({'a': {'b': {'c': 10}}}).next()['_id'], doc_id) + self.assertEqual(self.cmojo.test.t1.find({'a.b': {'c': 10}}).next()['_id'], doc_id) + self.assertEqual(self.cmojo.test.t1.find({'a.b.c': 10}).next()['_id'], doc_id) + + def tearDown(self): + self.cmojo.rollback() + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) + unittest.TextTestRunner(verbosity=2).run(suite) -- 2.39.2