Beispiel #1
0
 def test_clears(self):
     """
     Test clear()
     """
     test_son = SON([(1, 100), (2, 200), (3, 300)])
     test_son.clear()
     self.assertFalse(1 in test_son)
     self.assertEqual(0, len(test_son))
     self.assertEqual(0, len(test_son.keys()))
     self.assertEqual({}, test_son.to_dict())
Beispiel #2
0
 def test_clears(self):
     """
     Test clear()
     """
     test_son = SON([(1, 100), (2, 200), (3, 300)])
     test_son.clear()
     self.assertNotIn(1, test_son)
     self.assertEqual(0, len(test_son))
     self.assertEqual(0, len(test_son.keys()))
     self.assertEqual({}, test_son.to_dict())
Beispiel #3
0
 def test_to_dict(self):
     a = SON()
     b = SON([("blah", SON())])
     c = SON([("blah", [SON()])])
     d = SON([("blah", {"foo": SON()})])
     self.assertEqual({}, a.to_dict())
     self.assertEqual({"blah": {}}, b.to_dict())
     self.assertEqual({"blah": [{}]}, c.to_dict())
     self.assertEqual({"blah": {"foo": {}}}, d.to_dict())
     self.assertEqual(dict, a.to_dict().__class__)
     self.assertEqual(dict, b.to_dict()["blah"].__class__)
     self.assertEqual(dict, c.to_dict()["blah"][0].__class__)
     self.assertEqual(dict, d.to_dict()["blah"]["foo"].__class__)
 def test_to_dict(self):
     a1 = SON()
     b2 = SON([("blah", SON())])
     c3 = SON([("blah", [SON()])])
     d4 = SON([("blah", {"foo": SON()})])
     self.assertEqual({}, a1.to_dict())
     self.assertEqual({"blah": {}}, b2.to_dict())
     self.assertEqual({"blah": [{}]}, c3.to_dict())
     self.assertEqual({"blah": {"foo": {}}}, d4.to_dict())
     self.assertEqual(dict, a1.to_dict().__class__)
     self.assertEqual(dict, b2.to_dict()["blah"].__class__)
     self.assertEqual(dict, c3.to_dict()["blah"][0].__class__)
     self.assertEqual(dict, d4.to_dict()["blah"]["foo"].__class__)
 def test_to_dict(self):
     a1 = SON()
     b2 = SON([("blah", SON())])
     c3 = SON([("blah", [SON()])])
     d4 = SON([("blah", {"foo": SON()})])
     self.assertEqual({}, a1.to_dict())
     self.assertEqual({"blah": {}}, b2.to_dict())
     self.assertEqual({"blah": [{}]}, c3.to_dict())
     self.assertEqual({"blah": {"foo": {}}}, d4.to_dict())
     self.assertEqual(dict, a1.to_dict().__class__)
     self.assertEqual(dict, b2.to_dict()["blah"].__class__)
     self.assertEqual(dict, c3.to_dict()["blah"][0].__class__)
     self.assertEqual(dict, d4.to_dict()["blah"]["foo"].__class__)
def tag_sub_val(tag,code,val):
    d = SON(data={'code':code, 'value': val})
    return_data = {
        'datafield': {
            '$elemMatch': {
                'tag': tag,
                'subfield': d.to_dict()
            }
        }
    }
    return return_data
Beispiel #7
0
    def test_to_dict(self):
        a1 = SON()
        b2 = SON([("blah", SON())])
        c3 = SON([("blah", [SON()])])
        d4 = SON([("blah", {"foo": SON()})])
        self.assertEqual({}, a1.to_dict())
        self.assertEqual({"blah": {}}, b2.to_dict())
        self.assertEqual({"blah": [{}]}, c3.to_dict())
        self.assertEqual({"blah": {"foo": {}}}, d4.to_dict())
        self.assertEqual(dict, a1.to_dict().__class__)
        self.assertEqual(dict, b2.to_dict()["blah"].__class__)
        self.assertEqual(dict, c3.to_dict()["blah"][0].__class__)
        self.assertEqual(dict, d4.to_dict()["blah"]["foo"].__class__)

        # Original data unaffected.
        self.assertEqual(SON, d4['blah']['foo'].__class__)
Beispiel #8
0
    def test_to_dict(self):
        a1 = SON()
        b2 = SON([("blah", SON())])
        c3 = SON([("blah", [SON()])])
        d4 = SON([("blah", {"foo": SON()})])
        self.assertEqual({}, a1.to_dict())
        self.assertEqual({"blah": {}}, b2.to_dict())
        self.assertEqual({"blah": [{}]}, c3.to_dict())
        self.assertEqual({"blah": {"foo": {}}}, d4.to_dict())
        self.assertEqual(dict, a1.to_dict().__class__)
        self.assertEqual(dict, b2.to_dict()["blah"].__class__)
        self.assertEqual(dict, c3.to_dict()["blah"][0].__class__)
        self.assertEqual(dict, d4.to_dict()["blah"]["foo"].__class__)

        # Original data unaffected.
        self.assertEqual(SON, d4['blah']['foo'].__class__)
Beispiel #9
0
    def test_write_concern(self):
        c = Connection(pair)

        self.assertEqual({}, c.write_concern)
        wc = {"w": 2, "wtimeout": 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 3, "wtimeout": 1000}
        c.write_concern["w"] = 3
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 3}
        del c.write_concern["wtimeout"]
        self.assertEqual(wc, c.write_concern)

        wc = {"w": 3, "wtimeout": 1000}
        c = Connection(w=3, wtimeout=1000)
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 2, "wtimeout": 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)

        db = c.pymongo_test
        self.assertEqual(wc, db.write_concern)
        coll = db.test
        self.assertEqual(wc, coll.write_concern)
        coll.write_concern = {"j": True}
        self.assertEqual({"j": True}, coll.write_concern)
        self.assertEqual(wc, db.write_concern)

        wc = SON([("w", 2)])
        coll.write_concern = wc
        self.assertEqual(wc.to_dict(), coll.write_concern)

        def f():
            c.write_concern = {"foo": "bar"}

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern["foo"] = "bar"

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern = [("foo", "bar")]

        self.assertRaises(ConfigurationError, f)
Beispiel #10
0
    def test_write_concern(self):
        c = Connection(pair)

        self.assertEqual({}, c.write_concern)
        wc = {'w': 2, 'wtimeout': 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 3, 'wtimeout': 1000}
        c.write_concern['w'] = 3
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 3}
        del c.write_concern['wtimeout']
        self.assertEqual(wc, c.write_concern)

        wc = {'w': 3, 'wtimeout': 1000}
        c = Connection(w=3, wtimeout=1000)
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 2, 'wtimeout': 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)

        db = c.test
        self.assertEqual(wc, db.write_concern)
        coll = db.test
        self.assertEqual(wc, coll.write_concern)
        coll.write_concern = {'j': True}
        self.assertEqual({'j': True}, coll.write_concern)
        self.assertEqual(wc, db.write_concern)

        wc = SON([('w', 2)])
        coll.write_concern = wc
        self.assertEqual(wc.to_dict(), coll.write_concern)

        def f():
            c.write_concern = {'foo': 'bar'}

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern['foo'] = 'bar'

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern = [('foo', 'bar')]

        self.assertRaises(ConfigurationError, f)
    def test_write_concern(self):
        c = Connection(pair)

        self.assertEqual({}, c.write_concern)
        wc = {'w': 2, 'wtimeout': 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 3, 'wtimeout': 1000}
        c.write_concern['w'] = 3
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 3}
        del c.write_concern['wtimeout']
        self.assertEqual(wc, c.write_concern)

        wc = {'w': 3, 'wtimeout': 1000}
        c = Connection(w=3, wtimeout=1000)
        self.assertEqual(wc, c.write_concern)
        wc = {'w': 2, 'wtimeout': 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)

        db = c.test
        self.assertEqual(wc, db.write_concern)
        coll = db.test
        self.assertEqual(wc, coll.write_concern)
        coll.write_concern = {'j': True}
        self.assertEqual({'j': True}, coll.write_concern)
        self.assertEqual(wc, db.write_concern)

        wc = SON([('w', 2)])
        coll.write_concern = wc
        self.assertEqual(wc.to_dict(), coll.write_concern)

        def f():
            c.write_concern = {'foo': 'bar'}
        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern['foo'] = 'bar'
        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern = [('foo', 'bar')]
        self.assertRaises(ConfigurationError, f)