@@ -1756,3 +1756,44 @@ def test_rest_service(self):
1756
1756
HTTP_AUTHORIZATION = f"Token { token } " ,
1757
1757
)
1758
1758
self .assertEqual (response .status_code , 204 )
1759
+
1760
+ @override_settings (PROMGEN = tests .SETTINGS )
1761
+ def test_rest_shard (self ):
1762
+ # Check retrieving all shards
1763
+ expected = tests .Data ("examples" , "rest.shard.default.json" ).json ()
1764
+ response = self .client .get (reverse ("api-v2:shard-list" ))
1765
+ self .assertEqual (response .status_code , 200 )
1766
+ self .assertEqual (response .json (), expected )
1767
+
1768
+ # Check retrieving paginated shards
1769
+ expected = tests .Data ("examples" , "rest.shard.paginated.json" ).json ()
1770
+ response = self .client .get (reverse ("api-v2:shard-list" ), {"page_number" : 1 , "page_size" : 1 })
1771
+ self .assertEqual (response .status_code , 200 )
1772
+ self .assertEqual (response .json (), expected )
1773
+
1774
+ # Check retrieving shards whose "name" contains "test"
1775
+ expected = tests .Data ("examples" , "rest.shard.filter_by_name.json" ).json ()
1776
+ response = self .client .get (reverse ("api-v2:shard-list" ), {"name" : "test" })
1777
+ self .assertEqual (response .status_code , 200 )
1778
+ self .assertEqual (response .json (), expected )
1779
+
1780
+ # Check retrieving shards with a non-existent "name" returns an empty list
1781
+ response = self .client .get (reverse ("api-v2:shard-list" ), {"name" : "non-existent" })
1782
+ self .assertEqual (response .status_code , 200 )
1783
+ self .assertEqual (response .data ["count" ], 0 )
1784
+
1785
+ # Check retrieving shards whose "id" is "1"
1786
+ expected = tests .Data ("examples" , "rest.shard.detail.json" ).json ()
1787
+ response = self .client .get (reverse ("api-v2:shard-detail" , args = [1 ]))
1788
+ self .assertEqual (response .status_code , 200 )
1789
+ self .assertEqual (response .json (), expected )
1790
+
1791
+ # Check retrieving shards with a non-existent "id" returns 404 Not Found
1792
+ response = self .client .get (reverse ("api-v2:shard-detail" , args = [- 1 ]))
1793
+ self .assertEqual (response .status_code , 404 )
1794
+
1795
+ # Check retrieving list of projects for a shard
1796
+ expected = tests .Data ("examples" , "rest.shard.projects.json" ).json ()
1797
+ response = self .client .get (reverse ("api-v2:shard-projects" , args = [1 ]))
1798
+ self .assertEqual (response .status_code , 200 )
1799
+ self .assertEqual (response .json (), expected )
0 commit comments