Exemplo n.º 1
0
 def testPagingFeatures(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift1 = Shift.create(json)
     newShift2 = Shift.create(json)
     newShift3 = Shift.create(json)
     fav1 = Favorite.create(self.fakejohn.id, newShift1.id)
     fav2 = Favorite.create(self.fakejohn.id, newShift2.id)
     fav3 = Favorite.create(self.fakejohn.id, newShift3.id)
     favorites = self.fakejohn.favorites(limit=2)
     self.assertEqual(len(favorites), 2)
     fav1.delete()
     fav2.delete()
     fav3.delete()
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def testCanModify(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.assertTrue(self.fakemary.canModify(newShift))
     self.assertTrue(not self.fakejohn.canModify(newShift))
     self.assertTrue(self.root.canModify(newShift))
Exemplo n.º 4
0
 def testSubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # make a comment
     newComment = Comment.create(
         self.fakejohn.id,
         newShift.id,
         "1st comment!",
         subscribe=True
         )
     # check that shift author is subscribed
     subscribers = newShift.subscribers()
     self.assertTrue(self.fakemary.id in subscribers)
     # check that commenter is subscribed
     self.assertTrue(self.fakejohn.id in subscribers)
     # check that there is a message in shift author message db
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "fakejohn just commented on your shift!")
     # check that there is _not_ a message in commenters message db
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Exemplo n.º 5
0
 def testUnsubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # another user makes a comment
     newComment = Comment.create(self.fakebob.id,
                                 newShift.id,
                                 "1st comment!",
                                 subscribe=True)
     # subscribe fakejohn
     self.fakejohn.subscribe(newShift)
     # another user makes another comment
     newComment = Comment.create(self.fakebob.id, newShift.id,
                                 "2nd comment!")
     # check that fakejohn has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text,
                      "fakebob just commented on fakemary's shift!")
     # unsubscribe fakejohn
     self.fakejohn.unsubscribe(newShift)
     newComment = Comment.create(self.fakebob.id, newShift.id,
                                 "3rd comment!")
     # check that fakejohn still only has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     # check that fakemary has two messages
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 3)
     # check that fakebob has no messages
     messages = self.fakebob.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Exemplo n.º 6
0
 def testDelete(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.assertNotEqual(newShift, None)
     newShift.delete()
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift, None)
Exemplo n.º 7
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]
Exemplo n.º 8
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]
Exemplo n.º 9
0
 def create(self):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theData = json.loads(jsonData)
         id = loggedInUser
         theData['createdBy'] = id
         return data(Shift.create(theData))
     else:
         return error("No data for shift.", NoDataError)
Exemplo n.º 10
0
 def create(self):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theData = json.loads(jsonData)
         id = loggedInUser
         theData['createdBy'] = id
         return data(Shift.create(theData))
     else:
         return error("No data for shift.", NoDataError)
Exemplo n.º 11
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)
Exemplo 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]
Exemplo 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)
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def testUnfavorite(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newFavorite = Favorite.create(self.fakejohn.id, newShift.id)
     favorites = self.fakejohn.favorites()
     # user should have 1 favorite
     self.assertEqual(len(favorites), 1)
     # favorite count for that shift should be 1
     count = newShift.favoriteCount()
     self.assertEqual(count, 1)
     newFavorite.delete()
     # user should have 0 favorites
     favorites = self.fakejohn.favorites()
     self.assertEqual(len(favorites), 0)
     # favorite count for that shift should be 0
     count = newShift.favoriteCount()
     self.assertEqual(count, 0)
Exemplo n.º 16
0
 def testUnsubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # another user makes a comment
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "1st comment!",
         subscribe=True
         )
     # subscribe fakejohn
     self.fakejohn.subscribe(newShift)
     # another user makes another comment
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "2nd comment!"
         )
     # check that fakejohn has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "fakebob just commented on fakemary's shift!")
     # unsubscribe fakejohn
     self.fakejohn.unsubscribe(newShift)
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "3rd comment!"
         )
     # check that fakejohn still only has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     # check that fakemary has two messages
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 3)
     # check that fakebob has no messages
     messages = self.fakebob.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Exemplo n.º 17
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)
Exemplo n.º 18
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()
Exemplo n.º 19
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()
Exemplo n.º 20
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()
Exemplo n.º 21
0
 def testSubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # make a comment
     newComment = Comment.create(self.fakejohn.id,
                                 newShift.id,
                                 "1st comment!",
                                 subscribe=True)
     # check that shift author is subscribed
     subscribers = newShift.subscribers()
     self.assertTrue(self.fakemary.id in subscribers)
     # check that commenter is subscribed
     self.assertTrue(self.fakejohn.id in subscribers)
     # check that there is a message in shift author message db
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text,
                      "fakejohn just commented on your shift!")
     # check that there is _not_ a message in commenters message db
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Exemplo n.º 22
0
 def testJoinData(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     # gravatar not a real property, added via Shift.joinData
     self.assertNotEqual(newShift["gravatar"], None)