Exemple #1
0
    def test_paging_newest(self):
        """
    Test that we can page through the quotes in 
    the order that they were added.
    """
        user = users.User('*****@*****.**')
        for i in range(models.PAGE_SIZE):
            quoteid = models.add_quote('This is a test.', user)
            self.assertNotEqual(quoteid, None)
        quotes, next = models.get_quotes_newest()
        self.assertEqual(len(quotes), models.PAGE_SIZE)
        self.assertEqual(next, None)

        quoteid = models.add_quote('This is a test.', user)
        self.assertNotEqual(quoteid, None)

        quotes, next = models.get_quotes_newest()

        self.assertEqual(len(quotes), models.PAGE_SIZE)
        self.assertNotEqual(next, None)

        quotes, next = models.get_quotes_newest(next)
        self.assertEqual(len(quotes), 1)
        self.assertEqual(next, None)

        # Cleanup
        models.del_quote(quoteid, user)
        quotes, next = models.get_quotes_newest()
        for q in quotes:
            models.del_quote(q.key().id(), user)
Exemple #2
0
    def test_add_quote(self):
        """
    Add and remove quotes from the system.
    """
        user = users.User('*****@*****.**')
        quoteid = models.add_quote('This is a test.', user)
        time.sleep(1.1)
        quoteid2 = models.add_quote('This is a test2.', user)
        self.assertNotEqual(quoteid, None)
        self.assertNotEqual(quoteid, 0)

        # Get the added quotes by creation order
        quotes, next = models.get_quotes_newest()
        self.assertEqual(quotes[0].key().id(), quoteid2)
        self.assertEqual(models.get_quote(quoteid2).key().id(), quoteid2)

        self.assertEqual(len(quotes), 2)

        # Remove one quote
        models.del_quote(quoteid2, user)

        quotes, next = models.get_quotes_newest()
        self.assertEqual(quotes[0].key().id(), quoteid)
        self.assertEqual(len(quotes), 1)

        # Remove last remaining quote
        models.del_quote(quoteid, user)
        quotes, next = models.get_quotes_newest()
        self.assertEqual(len(quotes), 0)
Exemple #3
0
    def test_del_quote_perms(self):
        """
    Permissions of removing quotes.
    """
        user = users.User('*****@*****.**')
        user2 = users.User('*****@*****.**')
        quoteid = models.add_quote('This is a test.', user)

        # Get the added quotes by creation order
        quotes, next = models.get_quotes_newest()
        self.assertEqual(quotes[0].key().id(), quoteid)
        self.assertEqual(len(quotes), 1)

        # Remove one quote, should fail to remove the quote
        models.del_quote(quoteid, user2)

        # Confirm the quote is still in the system
        quotes, next = models.get_quotes_newest()
        self.assertEqual(quotes[0].key().id(), quoteid)
        self.assertEqual(len(quotes), 1)

        # Remove one remaining quote
        models.del_quote(quoteid, user)
        quotes, next = models.get_quotes_newest()
        self.assertEqual(len(quotes), 0)
  def test_paging_newest(self):
    """
    Test that we can page through the quotes in 
    the order that they were added.
    """
    user = users.User('*****@*****.**')
    for i in range(models.PAGE_SIZE):
      quoteid = models.add_quote('This is a test.', user)
      self.assertNotEqual(quoteid, None)
    quotes, next = models.get_quotes_newest()
    self.assertEqual(len(quotes), models.PAGE_SIZE)
    self.assertEqual(next, None)

    quoteid = models.add_quote('This is a test.', user)
    self.assertNotEqual(quoteid, None)
    
    quotes, next = models.get_quotes_newest()
    
    self.assertEqual(len(quotes), models.PAGE_SIZE)
    self.assertNotEqual(next, None)
    
    quotes, next = models.get_quotes_newest(next)
    self.assertEqual(len(quotes), 1)
    self.assertEqual(next, None)

    # Cleanup    
    models.del_quote(quoteid, user)
    quotes, next = models.get_quotes_newest()
    for q in quotes:
      models.del_quote(q.key().id(), user)
  def test_del_quote_perms(self):
    """
    Permissions of removing quotes.
    """
    user = users.User('*****@*****.**')
    user2 = users.User('*****@*****.**')
    quoteid = models.add_quote('This is a test.', user)

    # Get the added quotes by creation order
    quotes, next = models.get_quotes_newest()
    self.assertEqual(quotes[0].key().id(), quoteid)
    self.assertEqual(len(quotes), 1)
    
    # Remove one quote, should fail to remove the quote
    models.del_quote(quoteid, user2)

    # Confirm the quote is still in the system
    quotes, next = models.get_quotes_newest()
    self.assertEqual(quotes[0].key().id(), quoteid)
    self.assertEqual(len(quotes), 1)

    # Remove one remaining quote    
    models.del_quote(quoteid, user)
    quotes, next = models.get_quotes_newest()
    self.assertEqual(len(quotes), 0)
  def test_add_quote(self):
    """
    Add and remove quotes from the system.
    """
    user = users.User('*****@*****.**')
    quoteid = models.add_quote('This is a test.', user)
    time.sleep(1.1)
    quoteid2 = models.add_quote('This is a test2.', user)
    self.assertNotEqual(quoteid, None)
    self.assertNotEqual(quoteid, 0)
    
    # Get the added quotes by creation order
    quotes, next = models.get_quotes_newest()
    self.assertEqual(quotes[0].key().id(), quoteid2)
    self.assertEqual(models.get_quote(quoteid2).key().id(), quoteid2)

    self.assertEqual(len(quotes), 2)
    
    # Remove one quote
    models.del_quote(quoteid2, user)

    quotes, next = models.get_quotes_newest()
    self.assertEqual(quotes[0].key().id(), quoteid)
    self.assertEqual(len(quotes), 1)
    

    # Remove last remaining quote    
    models.del_quote(quoteid, user)
    quotes, next = models.get_quotes_newest()
    self.assertEqual(len(quotes), 0)
Exemple #7
0
  def get(self, section):
    """Retrieve a feed"""
    user = None
    if section == 'recent':    
      quotes, next = models.get_quotes_newest()
    elif section == 'popular':
      quotes, next = models.get_quotes()
    else:
      self.response.set_status(404, 'Not Found')
      return      

    template_values = create_template_dict(user, quotes, section.capitalize())
    template_file = os.path.join(os.path.dirname(__file__), 'templates/atom_feed.xml')    
    self.response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
    self.response.out.write(template.render(template_file, template_values))
Exemple #8
0
  def get(self, section):
    """Retrieve a feed"""
    user = None
    if section == 'recent':    
      quotes, next = models.get_quotes_newest()
    elif section == 'popular':
      quotes, next = models.get_quotes()
    else:
      self.response.set_status(404, 'Not Found')
      return      

    template_values = create_template_dict(user, quotes, section.capitalize())
    template_file = os.path.join(os.path.dirname(__file__), 'templates/atom_feed.xml')    
    self.response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
    self.response.out.write(template.render(template_file, template_values))
Exemple #9
0
  def get(self):
    """Retrieve an HTML page of the most recently added quotes."""
    user = users.get_current_user()
    offset = self.request.get('offset')
    page = int(self.request.get('p', '0'))
    logging.info('Latest offset = %s' % offset)
    if not offset:
      offset = None
    quotes, next = models.get_quotes_newest(offset)
    if next:
      nexturi = '?offset=%s&p=%d' % (next, page+1)
    else:
      nexturi = None

    template_values = create_template_dict(user, quotes, 'Recent', nexturi, prevuri=None, page=page)
    template_file = os.path.join(os.path.dirname(__file__), 'templates/recent.html')    
    self.response.out.write(template.render(template_file, template_values))
Exemple #10
0
  def get(self):
    """Retrieve an HTML page of the most recently added quotes."""
    user = users.get_current_user()
    offset = self.request.get('offset')
    page = int(self.request.get('p', '0'))
    logging.info('Latest offset = %s' % offset)
    if not offset:
      offset = None
    quotes, next = models.get_quotes_newest(offset)
    if next:
      nexturi = '?offset=%s&p=%d' % (next, page+1)
    else:
      nexturi = None

    template_values = create_template_dict(user, quotes, 'Recent', nexturi, prevuri=None, page=page)
    template_file = os.path.join(os.path.dirname(__file__), 'templates/recent.html')    
    self.response.out.write(template.render(template_file, template_values))