Ejemplo n.º 1
0
 def testBasicPublish(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # should exist in user/public db
     theShift = Shift.load(core.connect(SSUser.publicDb(self.fakemary.id)),
                           newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should exist in shiftspace/public db
     theShift = Shift.load(core.connect("shiftspace/public"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should _not_ exist in user/private db
     theShift = Shift.load(core.connect(SSUser.privateDb(self.fakemary.id)),
                           newShift.id)
     self.assertEqual(theShift, None)
Ejemplo n.º 2
0
 def copyTo(self, dbname):
     db = core.connect(dbname)
     copy = self.toDict()
     del copy["_rev"]
     theId = copy["_id"]
     del copy["_id"]
     db[theId] = copy
Ejemplo n.º 3
0
 def copyTo(self, dbname):
     db = core.connect(dbname)
     copy = self.toDict()
     del copy["_rev"]
     theId = copy["_id"]
     del copy["_id"]
     db[theId] = copy
Ejemplo n.º 4
0
 def autocomplete(self, type="user", query=None):
     """
     Helper for autocompletion of user names, group short names,
     and tags.
     """
     import server.models.core
     from server.utils.returnTypes import data
     from server.setup import AutocompleteByUser, AutocompleteByGroup, AutocompleteByTag
     db = core.connect()
     if type == "group":
         view = AutocompleteByGroup
     elif type == "tag":
         view = AutocompleteByTag
     else:
         view = AutocompleteByUser
     result = view(db)
     rows = core.values(result[query:("%sZZZZZZZZZZ" % query)])
     matches = [{
         "_id":
         x["_id"],
         "name":
         x.get("userName") or x.get("shortName") or x.get("string"),
         "gravatar":
         x.get("gravatar"),
         "type":
         x["type"]
     } for x in rows if x["userName"] != "shiftspace"]
     return data(matches)
Ejemplo n.º 5
0
 def testBasicPublish(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # should exist in user/public db
     theShift = Shift.load(core.connect(SSUser.publicDb(self.fakemary.id)), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should exist in master/public db 
     theShift = Shift.load(core.connect("shiftspace/public"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should _not_ exist in user/private db
     theShift = Shift.load(core.connect(SSUser.privateDb(self.fakemary.id)), newShift.id)
     self.assertEqual(theShift, None)
Ejemplo n.º 6
0
 def testUpdate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.update({"summary":"changed!"})
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift.summary, "changed!")
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
Ejemplo n.º 7
0
 def testRead(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift.source.server, newShift.source.server)
     self.assertEqual(theShift.source.database, newShift.source.database)
     self.assertEqual(theShift.createdBy, self.fakemary.id)
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
Ejemplo n.º 8
0
 def testPublishToGroupAndUser(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     json = groupJson()
     json["createdBy"] = self.fakemary.id
     newGroup = Group.create(json)
     newPerm = Permission.create("shiftspace", newGroup.id, self.fakejohn.id, level=1)
     publishData = {
         "dbs": [Group.db(newGroup.id), SSUser.db(self.fakebob.id)]
         }
     newShift.publish(publishData)
     # should exist in subscriber's feed
     db = core.connect("shiftspace/shared")
     theShift = Shift.load(db, newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     newGroup.delete()
     # should exist in shiftspace/shared
     # TODO: inbox if user is peer - David 11/18/09
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
Ejemplo n.º 9
0
 def testPublishToUser(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     publishData = {
         "dbs": [SSUser.db(self.fakejohn.id)]
         }
     newShift.publish(publishData)
     # should exist in user feed
     # TODO: in inbox if peer - David 11/18/09
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
Ejemplo n.º 10
0
def deletedbs():
    """
    Delete the databases, the database path must have been set
    first for this to work.
    """
    from server.models import core
    from server.models.ssuser import SSUser
    from server.models.group import Group

    # delete all core dbs and user and group dbs
    server = core.server()
    [group.delete() for group in core.objects(Group.all(core.connect()))]
    [user.delete() for user in core.objects(SSUser.all(core.connect()))]
    del server["shiftspace/public"]
    del server["shiftspace/shared"]
    del server["shiftspace/messages"]
    del server["shiftspace/master"]
    #[comment.deleteInstance() for comment in core.object(Comment.all(core.connect()))]
    # cleanup, remove any empty folders (left from deleted users
    try:
        fh = open("config/conf.json")
    except:
        print "config/conf.json does not exist. Set the path the database first."
        sys.exit(2)
    conf = json.loads(fh.read())
    if conf.get("dbpath"):
        userdbdir = os.path.join(conf["dbpath"], "user")
        if os.path.exists(userdbdir):
            for file in os.listdir(userdbdir):
                filepath = os.path.join(userdbdir, file)
                if os.path.isdir(filepath):
                    os.rmdir(filepath)
            os.rmdir(userdbdir)
        grpdbdir = os.path.join(conf["dbpath"], "group")
        if os.path.exists(grpdbdir):
            os.rmdir(grpdbdir)
        ssdbdir = os.path.join(conf["dbpath"], "shiftspace")
        if os.path.exists(ssdbdir):
            os.rmdir(ssdbdir)
Ejemplo n.º 11
0
def deletedbs():
    """
    Delete the databases, the database path must have been set
    first for this to work.
    """
    from server.models import core
    from server.models.ssuser import SSUser
    from server.models.group import Group

    # delete all core dbs and user and group dbs
    server = core.server()
    [group.delete() for group in core.objects(Group.all(core.connect()))]
    [user.delete() for user in core.objects(SSUser.all(core.connect()))]
    del server["shiftspace/public"]
    del server["shiftspace/shared"]
    del server["shiftspace/messages"]
    del server["shiftspace/master"]
    #[comment.deleteInstance() for comment in core.object(Comment.all(core.connect()))]
    # cleanup, remove any empty folders (left from deleted users
    try:
        fh = open("config/conf.json")
    except:
        print "config/conf.json does not exist. Set the path the database first."
        sys.exit(2)
    conf = json.loads(fh.read())
    if conf.get("dbpath"):
        userdbdir = os.path.join(conf["dbpath"], "user")
        if os.path.exists(userdbdir):
            for file in os.listdir(userdbdir):
                filepath = os.path.join(userdbdir, file)
                if os.path.isdir(filepath):
                    os.rmdir(filepath)
            os.rmdir(userdbdir)
        grpdbdir = os.path.join(conf["dbpath"], "group")
        if os.path.exists(grpdbdir):
            os.rmdir(grpdbdir)
        ssdbdir = os.path.join(conf["dbpath"], "shiftspace")
        if os.path.exists(ssdbdir):
            os.rmdir(ssdbdir)
Ejemplo n.º 12
0
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     theShift = Shift.create(json)
     self.assertEqual(theShift.type, "shift")
     self.assertEqual(theShift.createdBy, self.fakemary.id)
     self.assertNotEqual(theShift.created, None)
     self.assertEqual(type(theShift.created), datetime.datetime)
     self.assertNotEqual(theShift.modified, None)
     self.assertEqual(type(theShift.modified), datetime.datetime)
     self.assertEqual(theShift.domain, "http://google.com")
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
Ejemplo n.º 13
0
 def testPublishToFollowers(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.fakejohn.follow(self.fakemary)
     fakejohn = SSUser.read(self.fakejohn.id)
     # should be in the list of people fakejohn is following
     self.assertTrue(self.fakemary.id in fakejohn.following())
     # should be in the list of fakemary's followers
     followers = self.fakemary.followers()
     self.assertTrue(self.fakejohn.id in followers)
     newShift.publish({"private":False})
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
Ejemplo n.º 14
0
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # create new comment
     newComment = Comment.create(self.fakejohn.id, newShift.id, "1st comment!")
     # shift comment db should now exist
     self.assertNotEqual(core.connect(Comment.db(newShift.id)), None)
     # shift should have thread
     self.assertTrue(newShift.hasThread())
     # should be a comment count of 1 for shift
     count = newShift.commentCount()
     self.assertEqual(count, 1)
     # should be one message in fakemary's inbox from fakejohn
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     # delete the comment
     # TODO: separate fixture - David
     newComment.delete()
     # delete the thread
     newShift.deleteThread()
Ejemplo n.º 15
0
 def testPublishToGroup(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     json = groupJson()
     json["createdBy"] = self.fakemary.id
     newGroup = Group.create(json)
     # make sure fakemary owns the group
     newPerm = Permission.readByUserAndGroup(self.fakemary.id, newGroup.id)
     self.assertTrue(newPerm.level == 4)
     # create read permission for fakejohn
     newPerm = Permission.create("shiftspace", newGroup.id, self.fakejohn.id, level=1)
     fakejohn = SSUser.read(self.fakejohn.id)
     self.assertTrue(Group.db(newGroup.id) in fakejohn.readable())
     publishData = {
         "dbs": [Group.db(newGroup.id)]
         }
     newShift.publish(publishData)
     # should exists in shiftspace/shared
     db = core.connect("shiftspace/shared")
     theShift = Shift.load(db, newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     newGroup.delete()
Ejemplo n.º 16
0
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # create new comment
     newComment = Comment.create(self.fakejohn.id, newShift.id,
                                 "1st comment!")
     # shift comment db should now exist
     self.assertNotEqual(core.connect(Comment.db(newShift.id)), None)
     # shift should have thread
     self.assertTrue(newShift.hasThread())
     # should be a comment count of 1 for shift
     count = newShift.commentCount()
     self.assertEqual(count, 1)
     # should be one message in fakemary's inbox from fakejohn
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     # delete the comment
     # TODO: separate fixture - David
     newComment.delete()
     # delete the thread
     newShift.deleteThread()
Ejemplo n.º 17
0
 def autocomplete(self, type="user", query=None):
     """
     Helper for autocompletion of user names, group short names,
     and tags.
     """
     import server.models.core
     from server.utils.returnTypes import data
     from server.setup import AutocompleteByUser, AutocompleteByGroup, AutocompleteByTag
     db = core.connect()
     if type == "group":
         view = AutocompleteByGroup
     elif type == "tag":
         view = AutocompleteByTag
     else:
         view = AutocompleteByUser
     result = view(db)
     rows = core.values(result[query:("%sZZZZZZZZZZ" % query)])
     matches = [{"_id": x["_id"],
                 "name": x.get("userName") or x.get("shortName") or x.get("string"),
                 "gravatar": x.get("gravatar"),
                 "type": x["type"]}
                for x in rows if x["userName"] != "shiftspace"]
     return data(matches)
Ejemplo n.º 18
0
 def tearDown(self):
     db = core.connect()
     self.fakemary.delete()
     self.fakejohn.delete()
     self.fakebob.delete()
Ejemplo n.º 19
0
 def setUp(self):
     db = core.connect()
     self.fakemary = SSUser.create(fakemary)
     self.fakejohn = SSUser.create(fakejohn)
     self.fakebob = SSUser.create(fakebob)
     self.root = SSUser.read("shiftspace")
Ejemplo n.º 20
0
 def tearDown(self):
     db = core.connect()
     SSUser.delete(self.fakemary)
     SSUser.delete(self.fakejohn)
     SSUser.delete(self.fakebob)
Ejemplo n.º 21
0
 def tearDown(self):
     db = core.connect()
     self.fakemary.delete()
     self.fakejohn.delete()
     self.fakebob.delete()
Ejemplo n.º 22
0
 def setUp(self):
     db = core.connect()
     self.fakemary = SSUser.create(fakemary)
     self.fakejohn = SSUser.create(fakejohn)
     self.fakebob = SSUser.create(fakebob)
     self.root = SSUser.read("shiftspace")
Ejemplo n.º 23
0
 def delete(self, db=None):
     db = db or core.connect()
     del db[self.id]
Ejemplo n.º 24
0
import server.utils.utils as utils
import server.models.core as core
from server.tests.dummy_data import *
from server.models.ssuser import SSUser
from server.models.shift import Shift
from server.models.group import Group
from server.models.permission import Permission
from server.models.favorite import Favorite
from server.models.comment import Comment
from server.models.follow import Follow
from server.models.message import Message
from server.lucene.lucene_design import LuceneDefinition

def reload_models():
    import server
    for m in [server.models.core,
              server.models.ssuser, 
              server.models.shift, 
              server.models.group, 
              server.models.permission, 
              server.models.favorite, 
              server.models.comment,
              server.models.message,
              server.lucene.lucene_design]:
        reload(m)

db = core.connect()
Ejemplo n.º 25
0
 def updateIn(self, dbname):
     db = core.connect(dbname)
     old = db[self.id]
     copy = self.toDict()
     copy["_rev"] = old["_rev"]
     db[self.id] = copy
Ejemplo n.º 26
0
 def tearDown(self):
     db = core.connect()
     SSUser.delete(self.fakemary)
     SSUser.delete(self.fakejohn)
     SSUser.delete(self.fakebob)
Ejemplo n.º 27
0
 def setUp(self):
     db = core.connect()
     self.fakemary = SSUser.create(fakemary).id
     self.root = SSUser.read("shiftspace").id
Ejemplo n.º 28
0
 def updateIn(self, dbname):
     db = core.connect(dbname)
     old = db[self.id]
     copy = self.toDict()
     copy["_rev"] = old["_rev"]
     db[self.id] = copy
Ejemplo n.º 29
0
import server.utils.utils as utils
import server.models.core as core
from server.tests.dummy_data import *
from server.models.ssuser import SSUser
from server.models.shift import Shift
from server.models.group import Group
from server.models.permission import Permission
from server.models.favorite import Favorite
from server.models.comment import Comment
from server.models.follow import Follow
from server.models.message import Message
from server.lucene.lucene_design import LuceneDefinition


def reload_models():
    import server
    for m in [
            server.models.core, server.models.ssuser, server.models.shift,
            server.models.group, server.models.permission,
            server.models.favorite, server.models.comment,
            server.models.message, server.lucene.lucene_design
    ]:
        reload(m)


db = core.connect()
Ejemplo n.º 30
0
 def delete(self, db=None):
     db = db or core.connect()
     del db[self.id]
Ejemplo n.º 31
0
 def setUp(self):
     db = core.connect()
     self.fakemary = SSUser.create(fakemary).id
     self.root = SSUser.read("shiftspace").id