Example #1
0
 def test_bind_user(self):
     Dashboard.add_dashboard([User])
     request = [("User[name]", "sample"), ("User[email]", "*****@*****.**")]
     user = User()
     user.bind_form(request)
     assert user["name"] == "sample"
     assert user["email"] == "*****@*****.**"
Example #2
0
 def test_bind_user_array(self):
     Dashboard.add_dashboard([User])
     request = [("User[array][0]", "test1"), ("User[array][1]", "test2"), ("User[array][3]", "test3")]
     user = User()
     user.bind_form(request)
     assert len(user["array"]) == 3
     assert user["array"][0] == "test1"
Example #3
0
 def test_bind_user_dict(self):
     Dashboard.add_dashboard([User])
     request = [("User[options][tags]", "sample")]
     user = User()
     user.bind_form(request)
     print str(user)
     assert user["options"]["tags"] == "sample"
Example #4
0
    def test_bind_custom(self):
        Dashboard.add_dashboard([User])
        from mf.renderer import TextRenderer
        from user import CustomStatus

        assert isinstance(User.get_renderer("custom"), TextRenderer) == True
        request = [("User[custom]", "one")]
        user = User()
        user.bind_form(request)
        print "custom= " + str(user)
        assert user["custom"] == CustomStatus.unserialize("one")
Example #5
0
 def test_bind_user_IS_operator(self):
     Dashboard.add_dashboard([User])
     request = [("User[name]", "sample"), ("User[alist]", "one")]
     user = User()
     user.bind_form(request)
     assert user["name"] == "sample"
     assert user["alist"] == "one"
     request = [("User[name]", "sample"), ("User[alist]", "four")]
     user = User()
     res = user.bind_form(request)
     assert "alist" in res
     assert user["alist"] is not "four"
Example #6
0
 def test_bind_user_generic_dict(self):
     Dashboard.add_dashboard([User])
     request = [
         ("User[name]", "sample"),
         ("User[email]", "*****@*****.**"),
         ("User[keytype][test1]", "test1"),
         ("User[keytype][test2]", "test2"),
     ]
     user = User()
     user.bind_form(request)
     assert user["keytype"]["test1"] == "test1"
     assert user["keytype"]["test2"] == "test2"
Example #7
0
 def test_bind_multi_array2(self):
     Dashboard.add_dashboard([User])
     request = [
         ("User[multi][1][name]", "name2"),
         ("User[multi][0][role]", "role1"),
         ("User[multi][0][name]", "name1"),
         ("User[multi][1][role]", "role2"),
     ]
     user = User()
     user.bind_form(sorted(request))
     assert len(user["multi"]) == 2
     assert user["multi"][0]["role"] == "role1"
Example #8
0
 def test_user_bind_save_get(self):
     Dashboard.add_dashboard([User])
     request = [("User[name]", "sample"), ("User[email]", "*****@*****.**")]
     user = connection.User()
     user.bind_form(request)
     user.save()
     collection = DbConn.get_db("User")
     filter = {}
     filter["_id"] = user["_id"]
     obj = collection.find_one(filter)
     assert obj["name"] == "sample"
     assert obj["email"] == "*****@*****.**"
Example #9
0
 def test_bind_with_dbref(self):
     Dashboard.add_dashboard([User])
     group = connection.Group()
     group["name"] = "sampleGroup"
     group["creation_date"] = datetime.utcnow()
     group.save()
     request = [("User[groups][0]", str(group["_id"]))]
     user = connection.User()
     user["name"] = "sampleUser"
     user["email"] = "*****@*****.**"
     user.save()
     user.bind_form(request)
     user.save()
     assert group["_id"] == user["groups"][0]["_id"]
Example #10
0
    def test_bind_multi_array3(self):
        Dashboard.add_dashboard([User])
        group = connection.Group()
        group["name"] = "sampleGroup"
        group["creation_date"] = datetime.utcnow()
        group.save()

        request = [("User[multi2][0][group]", str(group["_id"])), ("User[multi2][0][role]", "role1")]
        renderer = User.get_renderer("multi2.group")
        renderer.set_reference(Group)

        user = User()
        user.bind_form(sorted(request))
        assert len(user["multi2"]) == 1
        assert user["multi2"][0]["role"] == "role1"
        assert user["multi2"][0]["group"] == group["_id"]
Example #11
0
    def test_bind_multi_array4(self):
        Dashboard.add_dashboard([User])
        group = connection.Group()
        group["name"] = "sampleGroup"
        group["creation_date"] = datetime.utcnow()
        group.save()

        request = [("User[multi2][0][group]", str(group["_id"])), ("User[multi2][0][role]", "role1")]
        renderer = SimpleReferenceRenderer(User, "group", Group, "multi2")
        renderer.is_object_id = True
        # renderer = User.get_renderer("multi2.group")
        # renderer.set_reference(Group)

        user = User()
        user.bind_form(sorted(request))
        print str(User.get_renderer("multi2.group").__class__.__name__)
        assert len(user["multi2"]) == 1
        assert user["multi2"][0]["role"] == "role1"
        assert user["multi2"][0]["group"] == group["_id"]