~ubuntu-branches/ubuntu/wily/pymongo/wily-proposed

« back to all changes in this revision

Viewing changes to test/test_dbref.py

  • Committer: Package Import Robot
  • Author(s): Federico Ceratto
  • Date: 2015-04-26 22:43:13 UTC
  • mfrom: (24.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20150426224313-0hga2jphvf0rrmfe
Tags: 3.0.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2014 MongoDB, Inc.
 
1
# Copyright 2009-2015 MongoDB, Inc.
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
15
15
"""Tests for the dbref module."""
16
16
 
17
17
import pickle
18
 
import unittest
19
18
import sys
20
19
sys.path[0:0] = [""]
21
20
 
22
21
from bson.dbref import DBRef
23
22
from bson.objectid import ObjectId
24
 
from bson.py3compat import b
 
23
from bson.py3compat import u
 
24
from test import unittest
25
25
 
26
26
from copy import deepcopy
27
27
 
37
37
        self.assertRaises(TypeError, DBRef, None, a)
38
38
        self.assertRaises(TypeError, DBRef, "coll", a, 5)
39
39
        self.assertTrue(DBRef("coll", a))
40
 
        self.assertTrue(DBRef(u"coll", a))
41
 
        self.assertTrue(DBRef(u"coll", 5))
42
 
        self.assertTrue(DBRef(u"coll", 5, "database"))
 
40
        self.assertTrue(DBRef(u("coll"), a))
 
41
        self.assertTrue(DBRef(u("coll"), 5))
 
42
        self.assertTrue(DBRef(u("coll"), 5, "database"))
43
43
 
44
44
    def test_read_only(self):
45
45
        a = DBRef("coll", ObjectId())
60
60
        self.assertEqual(repr(DBRef("coll",
61
61
                                    ObjectId("1234567890abcdef12345678"))),
62
62
                         "DBRef('coll', ObjectId('1234567890abcdef12345678'))")
63
 
        self.assertEqual(repr(DBRef(u"coll",
 
63
        self.assertEqual(repr(DBRef(u("coll"),
64
64
                              ObjectId("1234567890abcdef12345678"))),
65
65
                         "DBRef(%s, ObjectId('1234567890abcdef12345678'))"
66
 
                         % (repr(u'coll'),)
 
66
                         % (repr(u('coll')),)
67
67
                        )
68
68
        self.assertEqual(repr(DBRef("coll", 5, foo="bar")),
69
69
                         "DBRef('coll', 5, foo='bar')")
76
76
        obj_id = ObjectId("1234567890abcdef12345678")
77
77
 
78
78
        self.assertEqual(DBRef('foo', 5), DBRef('foo', 5))
79
 
        self.assertEqual(DBRef("coll", obj_id), DBRef(u"coll", obj_id))
 
79
        self.assertEqual(DBRef("coll", obj_id), DBRef(u("coll"), obj_id))
80
80
        self.assertNotEqual(DBRef("coll", obj_id),
81
 
                            DBRef(u"coll", obj_id, "foo"))
 
81
                            DBRef(u("coll"), obj_id, "foo"))
82
82
        self.assertNotEqual(DBRef("coll", obj_id), DBRef("col", obj_id))
83
83
        self.assertNotEqual(DBRef("coll", obj_id),
84
 
                            DBRef("coll", ObjectId(b("123456789011"))))
 
84
                            DBRef("coll", ObjectId(b"123456789011")))
85
85
        self.assertNotEqual(DBRef("coll", obj_id), 4)
86
86
        self.assertEqual(DBRef("coll", obj_id, "foo"),
87
 
                         DBRef(u"coll", obj_id, "foo"))
 
87
                         DBRef(u("coll"), obj_id, "foo"))
88
88
        self.assertNotEqual(DBRef("coll", obj_id, "foo"),
89
 
                            DBRef(u"coll", obj_id, "bar"))
 
89
                            DBRef(u("coll"), obj_id, "bar"))
90
90
 
91
91
        # Explicitly test inequality
92
92
        self.assertFalse(DBRef('foo', 5) != DBRef('foo', 5))
93
 
        self.assertFalse(DBRef("coll", obj_id) != DBRef(u"coll", obj_id))
 
93
        self.assertFalse(DBRef("coll", obj_id) != DBRef(u("coll"), obj_id))
94
94
        self.assertFalse(DBRef("coll", obj_id, "foo") !=
95
 
                         DBRef(u"coll", obj_id, "foo"))
 
95
                         DBRef(u("coll"), obj_id, "foo"))
96
96
 
97
97
    def test_kwargs(self):
98
98
        self.assertEqual(DBRef("coll", 5, foo="bar"),