@@ -1763,6 +1763,100 @@ def test_get_moves_with_date(self, mock_get):
17631763 assert str (mock_get .call_args [0 ][1 ]).endswith (f"/moves?date={ date } " )
17641764 assert result == expected_response
17651765
1766+ # Move Status
1767+ @patch ("requests.Session.request" )
1768+ def test_get_all_move_status (self , mock_get ):
1769+ expected_response = [
1770+ {"id" : 1 , "host" : "host1" , "status" : "pending" },
1771+ {"id" : 2 , "host" : "host2" , "status" : "ipmi_config" },
1772+ ]
1773+ mock_response = Mock ()
1774+ mock_response .json .return_value = expected_response
1775+ mock_get .return_value = mock_response
1776+
1777+ result = self .api .get_all_move_status ()
1778+
1779+ mock_get .assert_called_once ()
1780+ assert str (mock_get .call_args [0 ][1 ]).endswith ("/moves/progress/" )
1781+ assert result == expected_response
1782+
1783+ @patch ("requests.Session.request" )
1784+ def test_get_all_move_status_with_cloud (self , mock_get ):
1785+ expected_response = [{"id" : 1 , "host" : "host1" , "status" : "pending" }]
1786+ mock_response = Mock ()
1787+ mock_response .json .return_value = expected_response
1788+ mock_get .return_value = mock_response
1789+
1790+ result = self .api .get_all_move_status (cloud = "cloud02" )
1791+
1792+ mock_get .assert_called_once ()
1793+ assert "cloud=cloud02" in str (mock_get .call_args [0 ][1 ])
1794+ assert result == expected_response
1795+
1796+ @patch ("requests.Session.request" )
1797+ def test_get_all_move_status_with_status (self , mock_get ):
1798+ expected_response = [{"id" : 1 , "host" : "host1" , "status" : "provisioning" }]
1799+ mock_response = Mock ()
1800+ mock_response .json .return_value = expected_response
1801+ mock_get .return_value = mock_response
1802+
1803+ result = self .api .get_all_move_status (status = "provisioning" )
1804+
1805+ mock_get .assert_called_once ()
1806+ assert "status=provisioning" in str (mock_get .call_args [0 ][1 ])
1807+ assert result == expected_response
1808+
1809+ @patch ("requests.Session.request" )
1810+ def test_get_move_status (self , mock_get ):
1811+ expected_response = {"id" : 1 , "host" : "host1" , "status" : "provisioning" }
1812+ mock_response = Mock ()
1813+ mock_response .json .return_value = expected_response
1814+ mock_get .return_value = mock_response
1815+
1816+ result = self .api .get_move_status ("host1" )
1817+
1818+ mock_get .assert_called_once ()
1819+ assert str (mock_get .call_args [0 ][1 ]).endswith ("/moves/progress/host1" )
1820+ assert result == expected_response
1821+
1822+ @patch ("requests.Session.request" )
1823+ def test_start_move_batch (self , mock_post ):
1824+ hostnames = ["host1" , "host2" ]
1825+ expected_response = {"host1" : 1 , "host2" : 2 }
1826+ mock_response = Mock ()
1827+ mock_response .json .return_value = expected_response
1828+ mock_post .return_value = mock_response
1829+
1830+ result = self .api .start_move_batch (hostnames )
1831+
1832+ mock_post .assert_called_once ()
1833+ assert str (mock_post .call_args [0 ][1 ]).endswith ("/moves/progress/batch" )
1834+ assert mock_post .call_args [1 ]["json" ] == {"hostnames" : hostnames }
1835+ assert result == expected_response
1836+
1837+ @patch ("requests.Session.request" )
1838+ def test_update_move_status (self , mock_patch ):
1839+ data = {"status" : "ipmi_config" , "message" : "IPMI configured" }
1840+ expected_response = {"id" : 1 , "host" : "host1" , "status" : "ipmi_config" }
1841+ mock_response = Mock ()
1842+ mock_response .json .return_value = expected_response
1843+ mock_patch .return_value = mock_response
1844+
1845+ result = self .api .update_move_status (1 , data )
1846+
1847+ mock_patch .assert_called_once ()
1848+ assert str (mock_patch .call_args [0 ][1 ]).endswith ("/moves/progress/1" )
1849+ assert result == expected_response
1850+
1851+ @patch ("requests.Session.request" )
1852+ def test_get_move_status_error (self , mock_get ):
1853+ mock_response = Mock ()
1854+ mock_response .status_code = 500
1855+ mock_get .return_value = mock_response
1856+
1857+ with pytest .raises (APIServerException , match = "Check the flask server logs" ):
1858+ self .api .get_move_status ("host1" )
1859+
17661860 @patch ("requests.Session.request" )
17671861 def test_get_version (self , mock_get ):
17681862 expected_response = {"version" : "1.0.0" , "api_version" : "2.0" }
0 commit comments