@@ -1694,40 +1694,46 @@ def test_include_archived_projects(self):
1694
1694
1695
1695
1696
1696
class TestFollow (base .LiveTestBase ):
1697
- def setUp (self ):
1698
- super (TestFollow , self ).setUp ()
1699
- self .sg .update ('HumanUser' , self .human_user ['id' ], {'projects' : [self .project ]})
1700
-
1701
- # As the Follow entity isn't exposed directly, we clear out existing
1702
- # follows for the user before running our tests.
1703
- if self .sg .server_caps .version and self .sg .server_caps .version >= (7 , 0 , 12 ):
1704
- for entity in self .sg .following (self .human_user ):
1705
- self .sg .unfollow (self .human_user , entity )
1706
1697
1707
1698
def test_follow_unfollow (self ):
1708
1699
'''Test follow method'''
1709
1700
1710
1701
if not self .sg .server_caps .version or self .sg .server_caps .version < (5 , 1 , 22 ):
1711
1702
return
1712
1703
1713
- result = self .sg .follow (self .human_user , self .shot )
1714
- assert (result ['followed' ])
1704
+ with self .gen_entity (
1705
+ "HumanUser" ,
1706
+ projects = [self .project ],
1707
+ ) as human_user , self .gen_entity (
1708
+ "Shot" ,
1709
+ project = self .project ,
1710
+ ) as shot :
1711
+ result = self .sg .follow (human_user , shot )
1712
+ assert (result ['followed' ])
1715
1713
1716
- result = self .sg .unfollow (self . human_user , self . shot )
1717
- assert (result ['unfollowed' ])
1714
+ result = self .sg .unfollow (human_user , shot )
1715
+ assert (result ['unfollowed' ])
1718
1716
1719
1717
def test_followers (self ):
1720
1718
'''Test followers method'''
1721
1719
1722
1720
if not self .sg .server_caps .version or self .sg .server_caps .version < (5 , 1 , 22 ):
1723
1721
return
1724
1722
1725
- result = self .sg .follow (self .human_user , self .shot )
1726
- assert (result ['followed' ])
1723
+ with self .gen_entity (
1724
+ "HumanUser" ,
1725
+ projects = [self .project ],
1726
+ ) as human_user , self .gen_entity (
1727
+ "Shot" ,
1728
+ project = self .project ,
1729
+ ) as shot :
1730
+ result = self .sg .follow (human_user , shot )
1731
+ assert (result ['followed' ])
1732
+
1733
+ result = self .sg .followers (shot )
1727
1734
1728
- result = self .sg .followers (self .shot )
1729
- self .assertEqual (1 , len (result ))
1730
- self .assertEqual (self .human_user ['id' ], result [0 ]['id' ])
1735
+ self .assertEqual (1 , len (result ))
1736
+ self .assertEqual (human_user ['id' ], result [0 ]['id' ])
1731
1737
1732
1738
def test_following (self ):
1733
1739
'''Test following method'''
@@ -1736,42 +1742,53 @@ def test_following(self):
1736
1742
warnings .warn ("Test bypassed because SG server used does not support this feature." , FutureWarning )
1737
1743
return
1738
1744
1739
- result = self .sg .follow (self .human_user , self .shot )
1740
- assert (result ['followed' ])
1741
-
1742
- result = self .sg .following (self .human_user )
1743
- self .assertEqual (1 , len (result ))
1744
- self .assertEqual (self .shot ['id' ], result [0 ]['id' ])
1745
-
1746
- result = self .sg .follow (self .human_user , self .task )
1747
- assert (result ['followed' ])
1748
-
1749
- result = self .sg .following (self .human_user )
1750
- self .assertEqual (2 , len (result ))
1751
- result = self .sg .following (self .human_user , entity_type = "Task" )
1752
- self .assertEqual (1 , len (result ))
1753
- result = self .sg .following (self .human_user , entity_type = "Shot" )
1754
- self .assertEqual (1 , len (result ))
1755
-
1756
- shot_project_id = self .sg .find_one ("Shot" ,
1757
- [["id" , "is" , self .shot ["id" ]]],
1758
- ["project.Project.id" ])["project.Project.id" ]
1759
- task_project_id = self .sg .find_one ("Task" ,
1760
- [["id" , "is" , self .task ["id" ]]],
1761
- ["project.Project.id" ])["project.Project.id" ]
1762
- project_count = 2 if shot_project_id == task_project_id else 1
1763
- result = self .sg .following (self .human_user , project = {"type" : "Project" , "id" : shot_project_id })
1764
- self .assertEqual (project_count , len (result ))
1765
- result = self .sg .following (self .human_user , project = {"type" : "Project" , "id" : task_project_id })
1766
- self .assertEqual (project_count , len (result ))
1767
- result = self .sg .following (self .human_user ,
1768
- project = {"type" : "Project" , "id" : shot_project_id },
1769
- entity_type = "Shot" )
1770
- self .assertEqual (1 , len (result ))
1771
- result = self .sg .following (self .human_user ,
1772
- project = {"type" : "Project" , "id" : task_project_id },
1773
- entity_type = "Task" )
1774
- self .assertEqual (1 , len (result ))
1745
+ with self .gen_entity (
1746
+ "HumanUser" ,
1747
+ projects = [self .project ],
1748
+ ) as human_user , self .gen_entity (
1749
+ "Shot" ,
1750
+ project = self .project ,
1751
+ ) as shot , self .gen_entity (
1752
+ "Task" ,
1753
+ project = self .project ,
1754
+ ) as task :
1755
+ result = self .sg .follow (human_user , shot )
1756
+ assert (result ['followed' ])
1757
+
1758
+ result = self .sg .following (human_user )
1759
+
1760
+ self .assertEqual (1 , len (result ))
1761
+
1762
+ result = self .sg .follow (human_user , task )
1763
+ assert (result ['followed' ])
1764
+
1765
+ result = self .sg .following (human_user )
1766
+
1767
+ self .assertEqual (2 , len (result ))
1768
+ result = self .sg .following (human_user , entity_type = "Task" )
1769
+ self .assertEqual (1 , len (result ))
1770
+ result = self .sg .following (human_user , entity_type = "Shot" )
1771
+ self .assertEqual (1 , len (result ))
1772
+
1773
+ shot_project_id = self .sg .find_one ("Shot" ,
1774
+ [["id" , "is" , shot ["id" ]]],
1775
+ ["project.Project.id" ])["project.Project.id" ]
1776
+ task_project_id = self .sg .find_one ("Task" ,
1777
+ [["id" , "is" , task ["id" ]]],
1778
+ ["project.Project.id" ])["project.Project.id" ]
1779
+ project_count = 2 if shot_project_id == task_project_id else 1
1780
+ result = self .sg .following (human_user , project = {"type" : "Project" , "id" : shot_project_id })
1781
+ self .assertEqual (project_count , len (result ))
1782
+ result = self .sg .following (human_user , project = {"type" : "Project" , "id" : task_project_id })
1783
+ self .assertEqual (project_count , len (result ))
1784
+ result = self .sg .following (human_user ,
1785
+ project = {"type" : "Project" , "id" : shot_project_id },
1786
+ entity_type = "Shot" )
1787
+ self .assertEqual (1 , len (result ))
1788
+ result = self .sg .following (human_user ,
1789
+ project = {"type" : "Project" , "id" : task_project_id },
1790
+ entity_type = "Task" )
1791
+ self .assertEqual (1 , len (result ))
1775
1792
1776
1793
1777
1794
class TestErrors (base .TestBase ):
@@ -1944,6 +1961,12 @@ class TestScriptUserSudoAuth(base.LiveTestBase):
1944
1961
def setUp (self ):
1945
1962
super (TestScriptUserSudoAuth , self ).setUp ('ApiUser' )
1946
1963
1964
+ self .sg .update (
1965
+ 'HumanUser' ,
1966
+ self .human_user ['id' ],
1967
+ {'projects' : [self .project ]},
1968
+ )
1969
+
1947
1970
def test_user_is_creator (self ):
1948
1971
"""
1949
1972
Test 'sudo_as_login' option: on create, ensure appropriate user is set in created-by
0 commit comments