Exemple #1
0
 def test_dispatch_post_to_followers(self):
   user_to_follow = User.create('anonymous','password')
   me = User.create(self.params['username'],self.params['password'])
   me.follow(user_to_follow)
   Post.create(user_to_follow,self.params['post'])
   self.assertEqual(1,len(me.timeline()))
   self.assertEqual(1,len(me.timeline()))
Exemple #2
0
 def test_dispatch_post_to_followers(self):
     user_to_follow = User.create('anonymous', 'password')
     me = User.create(self.params['username'], self.params['password'])
     me.follow(user_to_follow)
     Post.create(user_to_follow, self.params['post'])
     self.assertEqual(1, len(me.timeline()))
     self.assertEqual(1, len(me.timeline()))
Exemple #3
0
 def test_create_user(self):
   user = User.create(self.params['username'],self.params['password'])
   self.assertEqual(self.params['username'], user.username)
   self.assertEqual(settings.SALT + self.params['password'], user.password)
   self.assertEqual(1,user.id)
   self.assertEqual(0,len(user.followees))
   self.assertEqual(0,len(user.followers))
   self.assertEqual(0,len(user.posts()))
   self.assertEqual(0,len(user.mentions()))
   self.assertEqual(0,len(user.timeline()))
   
   user = User.create(self.params['username'],self.params['password'])
   self.assertEqual(None,user)
Exemple #4
0
 def test_create_user(self):
   user = User.create(self.params['username'],self.params['password'])
   self.assertEqual(self.params['username'], user.username)
   self.assertEqual(settings.SALT + self.params['password'], user.password)
   self.assertEqual(1,user.id)
   self.assertEqual(0,len(user.followees))
   self.assertEqual(0,len(user.followers))
   self.assertEqual(0,len(user.posts()))
   self.assertEqual(0,len(user.mentions()))
   self.assertEqual(0,len(user.timeline()))
   
   user = User.create(self.params['username'],self.params['password'])
   self.assertEqual(None,user)
Exemple #5
0
 def test_follow(self):
   user_to_follow = User.create('anonymous','password')
   me = User.create(self.params['username'],self.params['password'])
   me.follow(user_to_follow)
   self.assertEqual(1,len(me.followees))
   self.assertEqual(1,len(user_to_follow.followers))
   self.assertEqual(0,len(me.followers))
   self.assertEqual(0,len(user_to_follow.followees))
   
   self.assertEqual(True,me.following(user_to_follow))
   
   me.stop_following(user_to_follow)
   self.assertEqual(0,len(me.followees))
   self.assertEqual(0,len(user_to_follow.followers))
   self.assertEqual(False,me.following(user_to_follow))
Exemple #6
0
    def test_follow(self):
        user_to_follow = User.create('anonymous', 'password')
        me = User.create(self.params['username'], self.params['password'])
        me.follow(user_to_follow)
        self.assertEqual(1, len(me.followees))
        self.assertEqual(1, len(user_to_follow.followers))
        self.assertEqual(0, len(me.followers))
        self.assertEqual(0, len(user_to_follow.followees))

        self.assertEqual(True, me.following(user_to_follow))

        me.stop_following(user_to_follow)
        self.assertEqual(0, len(me.followees))
        self.assertEqual(0, len(user_to_follow.followers))
        self.assertEqual(False, me.following(user_to_follow))
Exemple #7
0
 def test_post_find_by_id(self):
   user = User.create(self.params['username'],self.params['password'])
   Post.create(user,self.params['post'])
   post_found = Post.find_by_id(1)
   self.assertEqual(1,post_found.id)
   self.assertEqual(user.id,int(post_found.user_id)) #shouldn't need int()
   self.assertEqual(self.params['username'],post_found.user.username)
Exemple #8
0
 def test_user_find_by_name(self):
   user = User.create(self.params['username'],self.params['password'])
   user_found = User.find_by_username(self.params['username'])
   self.assertEqual(user.id,user_found.id)
   self.assertEqual(self.params['username'],user_found.username)
   user_not_found = User.find_by_username('not_found')
   self.assertEqual(None,user_not_found)
Exemple #9
0
 def test_user_find_by_name(self):
     user = User.create(self.params['username'], self.params['password'])
     user_found = User.find_by_username(self.params['username'])
     self.assertEqual(user.id, user_found.id)
     self.assertEqual(self.params['username'], user_found.username)
     user_not_found = User.find_by_username('not_found')
     self.assertEqual(None, user_not_found)
Exemple #10
0
def sign_up():
    if 'name' in bottle.request.POST and 'password' in bottle.request.POST:
        name = bottle.request.POST['name']
        if name not in reserved_usernames.split():
            password = bottle.request.POST['password']

            attributes = {}
            if 'firstName' in bottle.request.POST:
                attributes['firstName'] = bottle.request.POST['firstName']

            if 'lastName' in bottle.request.POST:
                attributes['lastName'] = bottle.request.POST['lastName']

            if 'greeting' in bottle.request.POST:
                attributes['greeting'] = bottle.request.POST['greeting']

            user = User.create(name, password, attributes)
            if user:
                sess = Session(bottle.request, bottle.response)
                sess['id'] = user.id
                sess.save()
                bottle.redirect('/home')
        return bottle.template('login',
                               page='login',
                               error_login=False,
                               error_signup=True,
                               logged=False)
Exemple #11
0
 def test_post_find_by_id(self):
   user = User.create(self.params['username'],self.params['password'])
   Post.create(user,self.params['post'])
   post_found = Post.find_by_id(1)
   self.assertEqual(1,post_found.id)
   self.assertEqual(user.id,int(post_found.user_id)) #shouldn't need int()
   self.assertEqual(self.params['username'],post_found.user.username)
Exemple #12
0
def sign_up():
  if 'name' in bottle.request.POST and 'password' in bottle.request.POST:
    name = bottle.request.POST['name']
    if name not in reserved_usernames.split():
      password = bottle.request.POST['password']
      user = User.create(name,password)
      if user:
        sess=Session(bottle.request,bottle.response)
        sess['id'] = user.id
        sess.save()
        bottle.redirect('/home')
    return bottle.template('login',page='login',error_login=False,error_signup=True,logged=False)
Exemple #13
0
 def test_create_post_with_mention(self):
   user = User.create(self.params['username'],self.params['password'])
   content_with_mention = self.params['post'] + '@' + self.params['username']
   Post.create(user,content_with_mention)
   self.assertEqual(1,len(user.mentions()))
Exemple #14
0
 def test_create_post(self):
   user = User.create(self.params['username'],self.params['password'])
   Post.create(user,self.params['post'])
   self.assertEqual(1,len(user.posts()))
   self.assertEqual(1,user.posts()[0].id)
   self.assertEqual(self.params['post'],user.posts()[0].content)
Exemple #15
0
 def test_create_post_with_mention(self):
     user = User.create(self.params['username'], self.params['password'])
     content_with_mention = self.params['post'] + '@' + self.params[
         'username']
     Post.create(user, content_with_mention)
     self.assertEqual(1, len(user.mentions()))
Exemple #16
0
 def test_create_post(self):
     user = User.create(self.params['username'], self.params['password'])
     Post.create(user, self.params['post'])
     self.assertEqual(1, len(user.posts()))
     self.assertEqual(1, user.posts()[0].id)
     self.assertEqual(self.params['post'], user.posts()[0].content)