Exemplo n.º 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()))
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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()))
Exemplo n.º 5
0
def status(name,id):
  post = Post.find_by_id(id)
  if post:
    if post.user.username == name:
      return bottle.template('single',username=post.user.username,tweet=post,page='single',
                                    logged=user_is_logged())
  return bottle.HTTPError(code=404,message='tweet not found')
    def list_posts(self, order, start, end):
        """
        Lists posts in a period of time, ordering the results according to the constraints defined by the parameters of the function
        
        Args:
            order (datetime): How the posts must be ordered. Options are 'ups' (number of upvotes) or 'comments' number of comments
            start (datetime): The start of the period 
            end (datetime): The end of the period 
                
        Returns:
            [List(Post)]: List of Posts ordered accordingly
        """

        try:
            order_clause = DbPost.comments.desc(
            ) if order == 'comments' else DbPost.ups.desc()
            db_posts = DbPost.select().where(DbPost.created.between(
                start, end)).order_by(order_clause)
            return [
                Post(title=p.title,
                     ups=p.ups,
                     comments=p.comments,
                     created=p.created,
                     author=p.author.name) for p in db_posts
            ]
        except Exception as e:
            raise Exception('error listing post')
Exemplo n.º 7
0
def status(name, id):
    post = Post.find_by_id(id)
    if post:
        if post.user.username == name:
            return bottle.template('single',
                                   username=post.user.username,
                                   tweet=post,
                                   page='single',
                                   logged=user_is_logged())
    return bottle.HTTPError(code=404, message='tweet not found')
Exemplo n.º 8
0
def status(auth, name,id):
  post = Post.find_by_id(id)
  if post:
    if post.user.username == name:
      if auth != None:
        return bottle.template('single',username=post.user.username,tweet=post,page='single',
                                      logged=user_is_logged(),viewer=auth.username)
      else:
        return bottle.template('single',username=post.user.username,tweet=post,page='single',
                                      logged=user_is_logged(),viewer="")
  return bottle.HTTPError(code=404,message='tweet not found')  
Exemplo n.º 9
0
    def execute(self, request):
        response = Response()
        try:
            for post in [p['data'] for p in request.endpoint_data['data']['children']]:
                user_id = self.user_repo.add_user(User(name = post['author'], ups = post['ups'], comments = post['num_comments']))
                created_time = datetime.fromtimestamp(post['created_utc'], tz = pytz.timezone(request.timezone))
                self.post_repo.add_post(Post(title = post['title'], ups = post['ups'], comments = post['num_comments'], created = created_time, author = user_id))
            return response

        except Exception as e:
            response.add_exception_error(e)
            return response
Exemplo n.º 10
0
def status(name, id):
    user = User.find_by_username(name)
    if user:
        post = Post.find_by_id(user.id + ':' + id)
    else:
        post = None
    if post:
        if post.user.username == name:
            return bottle.template('single',
                                   username=post.user.username,
                                   tweet=post,
                                   page='single',
                                   logged=user_is_logged())
    return bottle.HTTPError(code=404, message='tweet not found')
Exemplo n.º 11
0
def status(auth, name, id):
    post = Post.find_by_id(id)
    if post:
        if post.user.username == name:
            if auth != None:
                return bottle.template('single',
                                       username=post.user.username,
                                       tweet=post,
                                       page='single',
                                       logged=user_is_logged(),
                                       viewer=auth.username)
            else:
                return bottle.template('single',
                                       username=post.user.username,
                                       tweet=post,
                                       page='single',
                                       logged=user_is_logged(),
                                       viewer="")
    return bottle.HTTPError(code=404, message='tweet not found')
Exemplo n.º 12
0
def post(user):
    content = bottle.request.POST['content']
    Post.create(user, content)
    bottle.redirect('/home')
Exemplo n.º 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()))
Exemplo n.º 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)
Exemplo n.º 15
0
def post(user):
  content = bottle.request.POST['content']
  Post.create(user, content)
  bottle.redirect('/home')
Exemplo n.º 16
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()))
Exemplo n.º 17
0
def post(user):
    try:
        content = bottle.request.POST['content']
        Post.create(user, content)
    except KeyError, e:
        pass
Exemplo n.º 18
0
def post(user):
  try:
    content = bottle.request.POST['content']
    Post.create(user, content)
  except KeyError, e:
    pass
Exemplo n.º 19
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)