From ea87c273f9d99c89aee26da00c27ed02efe5ea1a Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 23 Apr 2008 02:54:59 +0000 Subject: [PATCH] Added unit tests for new RSS related controller methods. Setting separator to empty for a few more Rss_item elements. --- controller/test/Test_notebooks.py | 116 +++++++++++++++++++++++++++++- view/Rss_item.py | 4 +- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index d4b5956..1a5e7ec 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -1,5 +1,4 @@ import cherrypy -import cgi import urllib from nose.tools import raises from urllib import quote @@ -709,6 +708,121 @@ class Test_notebooks( Test_controller ): user = self.database.load( User, self.user.object_id ) assert user.storage_bytes == 0 + def test_updates( self ): + self.login() + + result = self.http_get( + "/notebooks/updates/%s?rss¬ebook_name=%s" % ( self.notebook.object_id, self.notebook.name ), + session_id = self.session_id, + ) + + assert len( result[ u"recent_notes" ] ) == 2 + assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision ) + assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision ) + assert result[ u"notebook_id" ] == self.notebook.object_id + assert result[ u"notebook_name" ] == self.notebook.name + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_updates_without_login( self ): + result = self.http_get( + "/notebooks/updates/%s?rss¬ebook_name=%s" % ( self.notebook.object_id, self.notebook.name ), + ) + + # still should get the full results even without a login + assert len( result[ u"recent_notes" ] ) == 2 + assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision ) + assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision ) + assert result[ u"notebook_id" ] == self.notebook.object_id + assert result[ u"notebook_name" ] == self.notebook.name + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_updates_without_access( self ): + self.make_extra_notebooks() + self.login2() + + result = self.http_get( + "/notebooks/updates/%s?rss¬ebook_name=%s" % ( self.notebook2.object_id, self.notebook2.name ), + session_id = self.session_id, + ) + + # still should get the full results even without access + assert len( result[ u"recent_notes" ] ) == 0 + assert result[ u"notebook_id" ] == self.notebook2.object_id + assert result[ u"notebook_name" ] == self.notebook2.name + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_updates_with_unknown_notebook( self ): + result = self.http_get( + "/notebooks/updates/%s?rss¬ebook_name=%s" % ( self.unknown_notebook_id, self.notebook.name ), + ) + + assert u"access" in result[ "body" ][ 0 ] + + def test_updates_with_incorrect_notebook_name( self ): + result = self.http_get( + "/notebooks/updates/%s?rss¬ebook_name=%s" % ( self.notebook.object_id, "whee" ), + ) + + # still produces results even with an incorrect notebook name + assert len( result[ u"recent_notes" ] ) == 2 + assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision ) + assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision ) + assert result[ u"notebook_id" ] == self.notebook.object_id + assert result[ u"notebook_name" ] == u"whee" + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_get_update_link( self ): + self.login() + + result = self.http_get( + "/notebooks/get_update_link?%s" % urllib.urlencode( [ + ( "notebook_id", self.notebook.object_id ), + ( "notebook_name", self.notebook.name ), + ( "note_id", self.note.object_id ), + ( "revision", str( self.note.revision ) ), + ] ), + session_id = self.session_id, + ) + + assert result[ u"notebook_id" ] == self.notebook.object_id + assert result[ u"notebook_name" ] == self.notebook.name + assert result[ u"note_id" ] == self.note.object_id + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_get_update_link_without_login( self ): + result = self.http_get( + "/notebooks/get_update_link?%s" % urllib.urlencode( [ + ( "notebook_id", self.notebook.object_id ), + ( "notebook_name", self.notebook.name ), + ( "note_id", self.note.object_id ), + ( "revision", str( self.note.revision ) ), + ] ), + ) + + assert result[ u"notebook_id" ] == self.notebook.object_id + assert result[ u"notebook_name" ] == self.notebook.name + assert result[ u"note_id" ] == self.note.object_id + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + + def test_get_update_link_without_access( self ): + self.make_extra_notebooks() + self.login2() + + result = self.http_get( + "/notebooks/get_update_link?%s" % urllib.urlencode( [ + ( "notebook_id", self.notebook2.object_id ), + ( "notebook_name", self.notebook2.name ), + ( "note_id", self.note.object_id ), + ( "revision", str( self.note.revision ) ), + ] ), + session_id = self.session_id, + ) + + assert result[ u"notebook_id" ] == self.notebook2.object_id + assert result[ u"notebook_name" ] == self.notebook2.name + assert result[ u"note_id" ] == self.note.object_id + assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + def test_load_note( self ): self.login() diff --git a/view/Rss_item.py b/view/Rss_item.py index f365816..8de262a 100644 --- a/view/Rss_item.py +++ b/view/Rss_item.py @@ -5,8 +5,8 @@ class Rss_item( Item ): def __init__( self, title, link, description, date, guid ): Item.__init__( self, - Title( title ), - Link( link ), + Title( title, separator = u"" ), + Link( link, separator = u"" ), Description( description ), Dc_date( date ), # if we don't set the separator to empty, Node inserts newlines when the guid gets too long.