table_test.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import os
  2. import time
  3. import unittest
  4. import requests
  5. from fate_flow.entity.run_status import JobStatus
  6. from fate_flow.utils.base_utils import get_fate_flow_directory
  7. from fate_flow.settings import API_VERSION, HOST, HTTP_PORT
  8. server_url = "http://{}:{}/{}".format(HOST, HTTP_PORT, API_VERSION)
  9. class TestTable(unittest.TestCase):
  10. def setUp(self):
  11. self.data_dir = os.path.join(get_fate_flow_directory(), "examples", "data")
  12. self.upload_config = {"file": os.path.join(self.data_dir, "breast_hetero_guest.csv"), "head": 1,
  13. "partition": 10, "namespace": "fate_flow_test_table_breast_hetero",
  14. "table_name": "breast_hetero_guest", "use_local_data": 0, 'drop': 1, 'backend': 0, "id_delimiter": ','}
  15. def test_upload_guest(self):
  16. response = requests.post("/".join([server_url, 'data', 'upload']), json=self.upload_config)
  17. self.assertTrue(response.status_code in [200, 201])
  18. self.assertTrue(int(response.json()['retcode']) == 0)
  19. job_id = response.json()['jobId']
  20. for i in range(60):
  21. response = requests.post("/".join([server_url, 'job', 'query']), json={'job_id': job_id})
  22. self.assertTrue(int(response.json()['retcode']) == 0)
  23. if response.json()['data'][0]['f_status'] == JobStatus.SUCCESS:
  24. break
  25. time.sleep(1)
  26. self.assertTrue(response.json()['data'][0]['f_status'] == JobStatus.SUCCESS)
  27. response = test_table_info()
  28. self.assertTrue(response.status_code in [200, 201])
  29. self.assertTrue(int(response.json()['retcode']) == 0)
  30. response = test_table_delete()
  31. self.assertTrue(response.status_code in [200, 201])
  32. self.assertTrue(int(response.json()['retcode']) == 0)
  33. def test_table_info():
  34. response = requests.post("/".join([server_url, 'table', 'table_info']),
  35. json={'table_name': 'breast_hetero_guest',
  36. 'namespace': 'fate_flow_test_table_breast_hetero'})
  37. return response
  38. def test_table_delete():
  39. # submit
  40. response = requests.post("/".join([server_url, 'table', 'delete']),
  41. json={'table_name': 'breast_hetero_guest',
  42. 'namespace': 'fate_flow_test_table_breast_hetero'})
  43. return response
  44. if __name__ == '__main__':
  45. unittest.main()