@@ -1703,6 +1703,216 @@ def test__update_users_data_from_initial_data(
1703
1703
assert model .user_dict == user_dict
1704
1704
assert model .users == user_list
1705
1705
1706
+ @pytest .mark .parametrize (
1707
+ "stream_id, expected_value" ,
1708
+ [
1709
+ case (
1710
+ 1000 ,
1711
+ {
1712
+ "name" : "Some general stream" ,
1713
+ "date_created" : None ,
1714
+ "invite_only" : False ,
1715
+ "color" : "#baf" ,
1716
+ "pin_to_top" : False ,
1717
+ "stream_id" : 1000 ,
1718
+ "is_muted" : False ,
1719
+ "audible_notifications" : False ,
1720
+ "description" : "General Stream" ,
1721
+ "rendered_description" : "General Stream" ,
1722
+ "desktop_notifications" : False ,
1723
+ "stream_weekly_traffic" : 0 ,
1724
+ "push_notifications" : False ,
1725
+ "email_address" : "[email protected] " ,
1726
+ "message_retention_days" : None ,
1727
+ "subscribers" : [1001 , 11 , 12 ],
1728
+ "history_public_to_subscribers" : True ,
1729
+ "is_announcement_only" : False ,
1730
+ "first_message_id" : 1 ,
1731
+ "email_notifications" : False ,
1732
+ "wildcard_mentions_notify" : False ,
1733
+ "is_web_public" : False ,
1734
+ },
1735
+ ),
1736
+ case (
1737
+ 3 ,
1738
+ {
1739
+ "name" : "Stream 3" ,
1740
+ "date_created" : 1472047127 ,
1741
+ "invite_only" : False ,
1742
+ "color" : "#b0a5fd" ,
1743
+ "pin_to_top" : False ,
1744
+ "stream_id" : 3 ,
1745
+ "is_muted" : False ,
1746
+ "audible_notifications" : False ,
1747
+ "description" : "A description of stream 3" ,
1748
+ "rendered_description" : "A description of stream 3" ,
1749
+ "desktop_notifications" : False ,
1750
+ "stream_weekly_traffic" : 0 ,
1751
+ "push_notifications" : False ,
1752
+ "message_retention_days" : 33 ,
1753
+ "email_address" : "[email protected] " ,
1754
+ "email_notifications" : False ,
1755
+ "wildcard_mentions_notify" : False ,
1756
+ "subscribers" : [1001 , 11 , 12 ],
1757
+ "history_public_to_subscribers" : True ,
1758
+ "is_announcement_only" : True ,
1759
+ "stream_post_policy" : 0 ,
1760
+ "is_web_public" : True ,
1761
+ "first_message_id" : None ,
1762
+ },
1763
+ ),
1764
+ case (
1765
+ 5 ,
1766
+ {
1767
+ "name" : "Stream 5" ,
1768
+ "date_created" : 1472047129 ,
1769
+ "invite_only" : False ,
1770
+ "stream_id" : 5 ,
1771
+ "description" : "A description of stream 5" ,
1772
+ "rendered_description" : "A description of stream 5" ,
1773
+ "stream_weekly_traffic" : 0 ,
1774
+ "message_retention_days" : 35 ,
1775
+ "subscribers" : [1001 , 11 , 12 ],
1776
+ "history_public_to_subscribers" : True ,
1777
+ "is_announcement_only" : True ,
1778
+ "stream_post_policy" : 0 ,
1779
+ "is_web_public" : True ,
1780
+ "first_message_id" : None ,
1781
+ },
1782
+ ),
1783
+ ],
1784
+ )
1785
+ def test__get_stream_from_id (
1786
+ self ,
1787
+ model ,
1788
+ stream_id ,
1789
+ expected_value ,
1790
+ stream_dict ,
1791
+ unsubscribed_streams ,
1792
+ never_subscribed_streams ,
1793
+ ):
1794
+ model .stream_dict = stream_dict
1795
+ model ._unsubscribed_streams = unsubscribed_streams
1796
+ model ._never_subscribed_streams = never_subscribed_streams
1797
+ assert model ._get_stream_from_id (stream_id ) == expected_value
1798
+
1799
+ def test__get_stream_from_id__nonexistent_stream (
1800
+ self ,
1801
+ model ,
1802
+ stream_dict ,
1803
+ unsubscribed_streams ,
1804
+ never_subscribed_streams ,
1805
+ stream_id = 231 , # id 231 does not belong to any stream
1806
+ ):
1807
+ model .stream_dict = stream_dict
1808
+ model ._unsubscribed_streams = unsubscribed_streams
1809
+ model ._never_subscribed_streams = never_subscribed_streams
1810
+ with pytest .raises (RuntimeError ):
1811
+ model ._get_stream_from_id (stream_id )
1812
+
1813
+ @pytest .mark .parametrize (
1814
+ "stream_id, expected_value" ,
1815
+ [
1816
+ case (
1817
+ 1000 ,
1818
+ {
1819
+ "name" : "Some general stream" ,
1820
+ "date_created" : None ,
1821
+ "invite_only" : False ,
1822
+ "color" : "#baf" ,
1823
+ "pin_to_top" : False ,
1824
+ "stream_id" : 1000 ,
1825
+ "is_muted" : False ,
1826
+ "audible_notifications" : False ,
1827
+ "description" : "General Stream" ,
1828
+ "rendered_description" : "General Stream" ,
1829
+ "desktop_notifications" : False ,
1830
+ "stream_weekly_traffic" : 0 ,
1831
+ "push_notifications" : False ,
1832
+ "email_address" : "[email protected] " ,
1833
+ "message_retention_days" : None ,
1834
+ "subscribers" : [1001 , 11 , 12 ],
1835
+ "history_public_to_subscribers" : True ,
1836
+ "is_announcement_only" : False ,
1837
+ "first_message_id" : 1 ,
1838
+ "email_notifications" : False ,
1839
+ "wildcard_mentions_notify" : False ,
1840
+ "is_web_public" : False ,
1841
+ },
1842
+ ),
1843
+ case (
1844
+ 3 ,
1845
+ {
1846
+ "name" : "Stream 3" ,
1847
+ "date_created" : 1472047127 ,
1848
+ "invite_only" : False ,
1849
+ "color" : "#b0a5fd" ,
1850
+ "pin_to_top" : False ,
1851
+ "stream_id" : 3 ,
1852
+ "is_muted" : False ,
1853
+ "audible_notifications" : False ,
1854
+ "description" : "A description of stream 3" ,
1855
+ "rendered_description" : "A description of stream 3" ,
1856
+ "desktop_notifications" : False ,
1857
+ "stream_weekly_traffic" : 0 ,
1858
+ "push_notifications" : False ,
1859
+ "message_retention_days" : 33 ,
1860
+ "email_address" : "[email protected] " ,
1861
+ "email_notifications" : False ,
1862
+ "wildcard_mentions_notify" : False ,
1863
+ "subscribers" : [1001 , 11 , 12 ],
1864
+ "history_public_to_subscribers" : True ,
1865
+ "is_announcement_only" : True ,
1866
+ "stream_post_policy" : 0 ,
1867
+ "is_web_public" : True ,
1868
+ "first_message_id" : None ,
1869
+ },
1870
+ ),
1871
+ ],
1872
+ )
1873
+ def test__get_subscription_from_id (
1874
+ self ,
1875
+ model ,
1876
+ stream_id ,
1877
+ expected_value ,
1878
+ stream_dict ,
1879
+ unsubscribed_streams ,
1880
+ ):
1881
+ model .stream_dict = stream_dict
1882
+ model ._unsubscribed_streams = unsubscribed_streams
1883
+ assert model ._get_subscription_from_id (stream_id ) == expected_value
1884
+
1885
+ @pytest .mark .parametrize (
1886
+ "stream_id" ,
1887
+ [case (5 , id = "never_subscribed_stream" ), case (231 , id = "non-existent_stream" )],
1888
+ )
1889
+ def test__get_subscription_from_id__nonexistent_subscription (
1890
+ self ,
1891
+ model ,
1892
+ stream_dict ,
1893
+ unsubscribed_streams ,
1894
+ never_subscribed_streams ,
1895
+ stream_id ,
1896
+ ):
1897
+ model .stream_dict = stream_dict
1898
+ model ._unsubscribed_streams = unsubscribed_streams
1899
+ model ._never_subscribed_streams = never_subscribed_streams
1900
+ with pytest .raises (RuntimeError ):
1901
+ model ._get_subscription_from_id (stream_id )
1902
+
1903
+ def test_get_all_stream_ids (
1904
+ self ,
1905
+ model ,
1906
+ stream_dict ,
1907
+ unsubscribed_streams ,
1908
+ never_subscribed_streams ,
1909
+ all_stream_ids ,
1910
+ ):
1911
+ model .stream_dict = stream_dict
1912
+ model ._unsubscribed_streams = unsubscribed_streams
1913
+ model ._never_subscribed_streams = never_subscribed_streams
1914
+ assert model .get_all_stream_ids () == all_stream_ids
1915
+
1706
1916
@pytest .mark .parametrize ("muted" , powerset ([99 , 1000 ]))
1707
1917
@pytest .mark .parametrize ("visual_notification_enabled" , powerset ([99 , 1000 ]))
1708
1918
def test__subscribe_to_streams (
0 commit comments