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_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 #3
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 #4
0
 def test_render_with_specific_list(self):
     Dashboard.add_dashboard([User])
     User.set_display_fields(["name", "email", "options"])
     myuser = User()
     try:
         html = myuser.html()
     except Exception as e:
         self.fail("Error while generating html: " + str(e))
Example #5
0
 def test_render_new_user(self):
     Dashboard.add_dashboard([User])
     myuser = User()
     myuser["keytype"]["test1"] = "test1"
     myuser["keytype"]["test2"] = "test2"
     try:
         html = myuser.html()
     except Exception as e:
         self.fail("Error while generating html: " + str(e))
Example #6
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 #7
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 #8
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 #9
0
 def test_dbref(self):
     Dashboard.add_dashboard([User, Group])
     group = connection.Group()
     group["name"] = "sampleGroup"
     group["creation_date"] = datetime.utcnow()
     group.save()
     user = connection.User()
     user["name"] = "sampleUser"
     user["email"] = "*****@*****.**"
     user["groups"] = [group]
     user.save()
     assert group["_id"] == user["groups"][0]["_id"]
Example #10
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 #11
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 #12
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 #13
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 #14
0
 def test_objectdbref(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["groupRef"] = group["_id"]
     renderer = User.get_renderer("groupRef")
     assert renderer.is_object_id == True
     renderer.set_reference(Group)
     user.save()
     assert group["_id"] == user["groupRef"]
     assert isinstance(user["groupRef"], ObjectId)
Example #15
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"]
Example #16
0
    def setUp(self):
        self.config = testing.setUp()

        Dashboard.__klasses = []
        collection = connection.User.find()
        for a_user in collection:
            a_user.delete()
        collection = connection.Group.find()
        for a_group in collection:
            a_group.delete()
        collection = connection.Types1.fetch()
        for a_type in collection:
            a_type.delete()
        collection = connection.Types2.fetch()
        for a_type in collection:
            a_type.delete()


        Dashboard.add_dashboard([User, Group, Types1, Types2])

        a_group = connection.Group()
        a_group["name"] = "sampleGroup"
        a_group["creation_date"] = datetime.utcnow()
        a_group.save()

        user1 = connection.User()
        user1['name'] = "Mike"
        user1['email'] = "*****@*****.**"
        user1['groups'] = [a_group]
        user1.save()

        user2 = connection.User()
        user2['name'] = "Mike"
        user2['email'] = "*****@*****.**"
        user2['groups'] = [a_group]
        user2.save()

        user3 = connection.User()
        user3['name'] = "John"
        user3['email'] = "*****@*****.**"
        user3['groups'] = [a_group]
        user3.save()
Example #17
0
 def test_instantiate_from_klasses(self):
     Dashboard.add_dashboard([User])
     myuser = Annotation.klasses()[0]()
     assert isinstance(myuser, User)
Example #18
0
 def test_add_to_dashboard(self):
     Dashboard.add_dashboard([User])
     assert User in Annotation.klasses()
Example #19
0
import group
from group import Group
from supergroup import SuperGroup
import mfpyramid.dashboard
from mfpyramid.dashboard import Dashboard
from mf.db_conn import DbConn
from mf.annotation import Annotation
from mf.renderer import SimpleReferenceRenderer
import pymongo
from mongokit import Document, Connection, ObjectId
from datetime import datetime
import logging

connection = Connection()
connection.register([User, Group, SuperGroup])
Dashboard.set_connection(connection)


class TestDashboard(unittest.TestCase):
    def setUp(self):
        Dashboard.__klasses = []
        collection = connection.User.find()
        for user in collection:
            user.delete()
        collection = connection.Group.find()
        for group in collection:
            group.delete()

    def test_add_to_dashboard(self):
        Dashboard.add_dashboard([User])
        assert User in Annotation.klasses()
Example #20
0
 def test_inheritance(self):
     Dashboard.add_dashboard([User])
     sgroup = connection.SuperGroup()
     sgroup["name"] = "sampleGroup"
     sgroup["creation_date"] = datetime.utcnow()
     sgroup.save()