@@ -1738,6 +1738,22 @@ def setUp(self):
17381738 "project" : self .project ,
17391739 "note_links" : [self ._shot ]})
17401740
1741+ # check that if the created_by is a script user, we want to ensure
1742+ # that event log generation is enabled for this user. If it has been
1743+ # disabled, these tests will fail because the activity stream is
1744+ # connected to events. In this case, print a warning to the user
1745+ d = self .sg .find_one ("Shot" ,
1746+ [["id" , "is" , self ._shot ["id" ] ]],
1747+ ["created_by.ApiUser.generate_event_log_entries" ])
1748+
1749+ if d ["created_by.ApiUser.generate_event_log_entries" ] is False :
1750+ # events are turned off! warn the user
1751+ print ("WARNING! Looks like the script user that is running these "
1752+ "tests has got the generate event log entries setting set to "
1753+ "off. This will cause the activity stream tests to fail. "
1754+ "Please enable event log generation for the script user." )
1755+
1756+
17411757 def tearDown (self ):
17421758 batch_data = []
17431759 batch_data .append ({"request_type" : "delete" ,
@@ -1747,7 +1763,7 @@ def tearDown(self):
17471763 batch_data .append ({"request_type" : "delete" ,
17481764 "entity_type" : self ._shot ["type" ],
17491765 "entity_id" : self ._shot ["id" ]
1750- })
1766+ })
17511767 self .sg .batch (batch_data )
17521768
17531769 super (TestActivityStream , self ).tearDown ()
@@ -1827,6 +1843,11 @@ class TestNoteThreadRead(base.LiveTestBase):
18271843
18281844 def setUp (self ):
18291845 super (TestNoteThreadRead , self ).setUp ()
1846+
1847+ # get path to our std attahcment
1848+ this_dir , _ = os .path .split (__file__ )
1849+ self ._thumbnail_path = os .path .abspath (os .path .join (this_dir , "sg_logo.jpg" ))
1850+
18301851
18311852 def _check_note (self , data , note_id , additional_fields ):
18321853
@@ -1853,17 +1874,21 @@ def _check_reply(self, data, reply_id, additional_fields):
18531874 list (expected_fields ))
18541875
18551876 # the reply stream adds an image to the user fields in order
1856- # to include thumbnails for users, so add this in before we compare
1857- reply_data ["user" ]["image" ] = None
1877+ # to include thumbnails for users, so remove this before we compare
1878+ # against the shotgun find data. The image is tested elsewhere.
1879+ del data ["user" ]["image" ]
18581880
18591881 self .assertEqual (reply_data , data )
18601882
18611883 def _check_attachment (self , data , attachment_id , additional_fields ):
1862-
1884+
1885+
1886+
1887+
18631888 # check the expected fields
18641889 expected_fields = set (["created_at" , "created_by" , "id" , "type" ] + additional_fields )
18651890 self .assertEqual (expected_fields , set (data .keys ()))
1866-
1891+
18671892 # check that the data matches the data we get from a find call
18681893 attachment_data = self .sg .find_one ("Attachment" ,
18691894 [["id" , "is" , attachment_id ]],
@@ -1881,6 +1906,29 @@ def test_simple(self):
18811906 # create note
18821907 note = self .sg .create ( "Note" , {"content" : "Test!" , "project" : self .project })
18831908
1909+ # for this test, we check that the replies returned also
1910+ # contain the thumbnail associated with the user doing the
1911+ # reply. For this, make sure that there is a thumbnail
1912+ # associated with the current user
1913+
1914+ d = self .sg .find_one ("Note" ,
1915+ [["id" , "is" , note ["id" ]]],
1916+ ["created_by" , "created_by.ApiUser.image" ])
1917+
1918+ current_thumbnail = d ["created_by.ApiUser.image" ]
1919+
1920+ if current_thumbnail is None :
1921+ # upload thumbnail
1922+ self .sg .upload_thumbnail ("ApiUser" ,
1923+ d ["created_by" ]["id" ],
1924+ self ._thumbnail_path )
1925+
1926+ d = self .sg .find_one ("Note" ,
1927+ [["id" , "is" , note ["id" ]]],
1928+ ["created_by" , "created_by.ApiUser.image" ])
1929+
1930+ current_thumbnail = d ["created_by.ApiUser.image" ]
1931+
18841932 # get thread
18851933 result = self .sg .note_thread_read (note ["id" ])
18861934 self .assertEqual (len (result ), 1 )
@@ -1892,13 +1940,22 @@ def test_simple(self):
18921940 # get thread
18931941 result = self .sg .note_thread_read (note ["id" ])
18941942 self .assertEqual (len (result ), 2 )
1943+
1944+ # now check that the reply thumbnail field matches
1945+ # the uploaded thumbnail. strip off any s3 querystring
1946+ # for the comparison
1947+ reply_thumb = result [1 ]["user" ]["image" ]
1948+ url_obj_a = urlparse .urlparse (current_thumbnail )
1949+ url_obj_b = urlparse .urlparse (reply_thumb )
1950+ self .assertEqual ("%s/%s" % (url_obj_a .netloc , url_obj_a .path ),
1951+ "%s/%s" % (url_obj_b .netloc , url_obj_b .path ),)
1952+
1953+ # and check ther rest of the data
18951954 self ._check_note (result [0 ], note ["id" ], additional_fields = [])
18961955 self ._check_reply (result [1 ], reply ["id" ], additional_fields = [])
18971956
18981957 # now upload an attachment
1899- this_dir , _ = os .path .split (__file__ )
1900- path = os .path .abspath (os .path .join (this_dir , "sg_logo.jpg" ))
1901- attachment_id = self .sg .upload (note ["type" ], note ["id" ], path )
1958+ attachment_id = self .sg .upload (note ["type" ], note ["id" ], self ._thumbnail_path )
19021959
19031960 # get thread
19041961 result = self .sg .note_thread_read (note ["id" ])
@@ -1921,7 +1978,7 @@ def test_complex(self):
19211978 "playlist" ,
19221979 "user" ],
19231980 "Reply" : ["content" ],
1924- "Attachment" : ["local_storage" , " this_file" ]
1981+ "Attachment" : ["this_file" ]
19251982 }
19261983
19271984 # create note
@@ -1945,15 +2002,14 @@ def test_complex(self):
19452002 self ._check_reply (result [1 ], reply ["id" ], additional_fields ["Reply" ])
19462003
19472004 # now upload an attachment
1948- this_dir , _ = os .path .split (__file__ )
1949- path = os .path .abspath (os .path .join (this_dir , "sg_logo.jpg" ))
1950- attachment_id = self .sg .upload (note ["type" ], note ["id" ], path )
1951-
2005+ attachment_id = self .sg .upload (note ["type" ], note ["id" ], self ._thumbnail_path )
2006+
19522007 # get thread
19532008 result = self .sg .note_thread_read (note ["id" ], additional_fields )
19542009 self .assertEqual (len (result ), 3 )
19552010 self ._check_note (result [0 ], note ["id" ], additional_fields ["Note" ])
19562011 self ._check_reply (result [1 ], reply ["id" ], additional_fields ["Reply" ])
2012+
19572013 self ._check_attachment (result [2 ], attachment_id , additional_fields ["Attachment" ])
19582014
19592015class TestTextSearch (base .LiveTestBase ):
0 commit comments