Browse Source

Added unit tests for new RSS related controller methods.

Setting separator to empty for a few more Rss_item elements.
Dan Helfman 10 years ago
parent
commit
ea87c273f9
2 changed files with 117 additions and 3 deletions
  1. 115
    1
      controller/test/Test_notebooks.py
  2. 2
    2
      view/Rss_item.py

+ 115
- 1
controller/test/Test_notebooks.py View File

@@ -1,5 +1,4 @@
1 1
 import cherrypy
2
-import cgi
3 2
 import urllib
4 3
 from nose.tools import raises
5 4
 from urllib import quote
@@ -709,6 +708,121 @@ class Test_notebooks( Test_controller ):
709 708
     user = self.database.load( User, self.user.object_id )
710 709
     assert user.storage_bytes == 0
711 710
 
711
+  def test_updates( self ):
712
+    self.login()
713
+
714
+    result = self.http_get(
715
+      "/notebooks/updates/%s?rss&notebook_name=%s" % ( self.notebook.object_id, self.notebook.name ),
716
+      session_id = self.session_id,
717
+    )
718
+
719
+    assert len( result[ u"recent_notes" ] ) == 2
720
+    assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision )
721
+    assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision )
722
+    assert result[ u"notebook_id" ] == self.notebook.object_id
723
+    assert result[ u"notebook_name" ] == self.notebook.name
724
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
725
+
726
+  def test_updates_without_login( self ):
727
+    result = self.http_get(
728
+      "/notebooks/updates/%s?rss&notebook_name=%s" % ( self.notebook.object_id, self.notebook.name ),
729
+    )
730
+
731
+    # still should get the full results even without a login
732
+    assert len( result[ u"recent_notes" ] ) == 2
733
+    assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision )
734
+    assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision )
735
+    assert result[ u"notebook_id" ] == self.notebook.object_id
736
+    assert result[ u"notebook_name" ] == self.notebook.name
737
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
738
+
739
+  def test_updates_without_access( self ):
740
+    self.make_extra_notebooks()
741
+    self.login2()
742
+
743
+    result = self.http_get(
744
+      "/notebooks/updates/%s?rss&notebook_name=%s" % ( self.notebook2.object_id, self.notebook2.name ),
745
+      session_id = self.session_id,
746
+    )
747
+
748
+    # still should get the full results even without access
749
+    assert len( result[ u"recent_notes" ] ) == 0
750
+    assert result[ u"notebook_id" ] == self.notebook2.object_id
751
+    assert result[ u"notebook_name" ] == self.notebook2.name
752
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
753
+
754
+  def test_updates_with_unknown_notebook( self ):
755
+    result = self.http_get(
756
+      "/notebooks/updates/%s?rss&notebook_name=%s" % ( self.unknown_notebook_id, self.notebook.name ),
757
+    )
758
+
759
+    assert u"access" in result[ "body" ][ 0 ]
760
+
761
+  def test_updates_with_incorrect_notebook_name( self ):
762
+    result = self.http_get(
763
+      "/notebooks/updates/%s?rss&notebook_name=%s" % ( self.notebook.object_id, "whee" ),
764
+    )
765
+
766
+    # still produces results even with an incorrect notebook name
767
+    assert len( result[ u"recent_notes" ] ) == 2
768
+    assert result[ u"recent_notes" ][ 0 ] == ( self.note2.object_id, self.note2.revision )
769
+    assert result[ u"recent_notes" ][ 1 ] == ( self.note.object_id, self.note.revision )
770
+    assert result[ u"notebook_id" ] == self.notebook.object_id
771
+    assert result[ u"notebook_name" ] == u"whee"
772
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
773
+
774
+  def test_get_update_link( self ):
775
+    self.login()
776
+
777
+    result = self.http_get(
778
+      "/notebooks/get_update_link?%s" % urllib.urlencode( [
779
+        ( "notebook_id", self.notebook.object_id ),
780
+        ( "notebook_name", self.notebook.name ),
781
+        ( "note_id", self.note.object_id ),
782
+        ( "revision", str( self.note.revision ) ),
783
+      ] ),
784
+      session_id = self.session_id,
785
+    )
786
+
787
+    assert result[ u"notebook_id" ] == self.notebook.object_id
788
+    assert result[ u"notebook_name" ] == self.notebook.name
789
+    assert result[ u"note_id" ] == self.note.object_id
790
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
791
+
792
+  def test_get_update_link_without_login( self ):
793
+    result = self.http_get(
794
+      "/notebooks/get_update_link?%s" % urllib.urlencode( [
795
+        ( "notebook_id", self.notebook.object_id ),
796
+        ( "notebook_name", self.notebook.name ),
797
+        ( "note_id", self.note.object_id ),
798
+        ( "revision", str( self.note.revision ) ),
799
+      ] ),
800
+    )
801
+
802
+    assert result[ u"notebook_id" ] == self.notebook.object_id
803
+    assert result[ u"notebook_name" ] == self.notebook.name
804
+    assert result[ u"note_id" ] == self.note.object_id
805
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
806
+
807
+  def test_get_update_link_without_access( self ):
808
+    self.make_extra_notebooks()
809
+    self.login2()
810
+
811
+    result = self.http_get(
812
+      "/notebooks/get_update_link?%s" % urllib.urlencode( [
813
+        ( "notebook_id", self.notebook2.object_id ),
814
+        ( "notebook_name", self.notebook2.name ),
815
+        ( "note_id", self.note.object_id ),
816
+        ( "revision", str( self.note.revision ) ),
817
+      ] ),
818
+      session_id = self.session_id,
819
+    )
820
+
821
+    assert result[ u"notebook_id" ] == self.notebook2.object_id
822
+    assert result[ u"notebook_name" ] == self.notebook2.name
823
+    assert result[ u"note_id" ] == self.note.object_id
824
+    assert result[ u"https_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ]
825
+
712 826
   def test_load_note( self ):
713 827
     self.login()
714 828
 

+ 2
- 2
view/Rss_item.py View File

@@ -5,8 +5,8 @@ class Rss_item( Item ):
5 5
   def __init__( self, title, link, description, date, guid ):
6 6
     Item.__init__(
7 7
       self,
8
-      Title( title ),
9
-      Link( link ),
8
+      Title( title, separator = u"" ),
9
+      Link( link, separator = u"" ),
10 10
       Description( description ),
11 11
       Dc_date( date ),
12 12
       # if we don't set the separator to empty, Node inserts newlines when the guid gets too long.