Skip to content

Commit d3cd69f

Browse files
author
Alpine Release
committed
fix the issue that the get workfile list can fetch ony 50 workfiles
1 parent 7a99dc6 commit d3cd69f

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

alpine/workfile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def get_list(self, workspace_id, per_page=100):
5252
url = "{0}/workspaces/{1}/workfiles".format(self.base_url, str(workspace_id))
5353
url = self._add_token_to_url(url)
5454

55-
if self.session.headers.get("Content-Type") is not None:
56-
self.session.headers.pop("Content-Type")
55+
self.session.headers.update({"Content-Type": "application/json"})
5756
page_current = 0
5857
while True:
5958
payload = {"no_published_worklets": True,
@@ -242,6 +241,8 @@ def upload(self, workspace_id, afm_file, data_sources_list):
242241
payload.append(("workfile[execution_locations][{0}][id]".format(i), database_id))
243242

244243
# files is used to create a multipart upload content-type with requests, we send in a file object
244+
if self.session.headers.get("Content-Type") is not None:
245+
self.session.headers.pop("Content-Type")
245246
files = {"workfile[versions_attributes][0][contents]": open(afm_file, 'rb')}
246247
self.logger.debug("POSTing to: {0}\n With payload: {1}".format(url, payload))
247248
response = self.session.post(url, files=files, data=payload, verify=False)

tests/api/test_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setUp(self):
4343

4444
# Upload a DB flow
4545
base_dir = os.getcwd()
46-
afm_path = "{0}/../data/afm/db_row_fil_with_variable.afm".format(base_dir)
46+
afm_path = "{0}/data/afm/db_row_fil_with_variable.afm".format(base_dir)
4747
# afm_path = "db_bat_row_fil.afm"
4848
try:
4949
workfile_id = alpine_client.workfile.get_id("db_row_fil_with_variable", workspace_id)

tests/api/test_workfile.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def setUp(self):
4848

4949
# Upload a DB flow
5050
base_dir = os.getcwd()
51-
afm_path = "{0}/../data/afm/db_row_fil_with_variable.afm".format(base_dir)
51+
afm_path = "{0}/data/afm/db_row_fil_with_variable.afm".format(base_dir)
5252
# afm_path = "db_bat_row_fil.afm"
5353
try:
5454
workfile_id = alpine_client.workfile.get_id("db_row_fil_with_variable", workspace_id)
@@ -75,6 +75,36 @@ def test_get_workfiles_list(self):
7575
self.assertIsNotNone(workfile_list)
7676
self.assertEqual(workfile_list.__len__(), 1)
7777

78+
def test_get_workfiles_list_multiple_pages(self):
79+
workspace_name_multiple_flows = "Workspace for Multiple Workfile Tests"
80+
workspace_id_multiple_flows_count = 10
81+
82+
try:
83+
workspace_id_multiple_flows = alpine_client.workspace.get_id(workspace_name_multiple_flows)
84+
alpine_client.workspace.delete(workspace_id_multiple_flows)
85+
except WorkspaceNotFoundException:
86+
pass
87+
workspace_info_nultiple_flow = alpine_client.workspace.create(workspace_name_multiple_flows)
88+
workspace_id_multiple_flows = workspace_info_nultiple_flow['id']
89+
90+
# Upload DB flows
91+
base_dir = os.getcwd()
92+
afm_path = "{0}/data/afm/db_row_fil_with_variable.afm".format(base_dir)
93+
database_list = alpine_client.datasource.get_database_list(db_datasource_id)
94+
for database in database_list:
95+
if database['name'] == "miner_demo":
96+
database_id = database['id']
97+
datasource_info = [{"data_source_type": DataSource.DSType.GreenplumDatabase,
98+
"data_source_id": db_datasource_id,
99+
"database_id": database_id
100+
}]
101+
for i in range(0, workspace_id_multiple_flows_count):
102+
workfile_info = alpine_client.workfile.upload(workspace_id_multiple_flows, afm_path, datasource_info)
103+
104+
workfile_list = alpine_client.workfile.get_list(workspace_id_multiple_flows,per_page=2)
105+
self.assertIsNotNone(workfile_list)
106+
self.assertEqual(workfile_list.__len__(), workspace_id_multiple_flows_count)
107+
78108
def test_get_workfile_info(self):
79109
workfile_id = alpine_client.workfile.get_id("db_row_fil_with_variable", workspace_id)
80110
workfile_info = alpine_client.workfile.get(workfile_id)
@@ -132,7 +162,7 @@ def test_stop_workflow(self):
132162

133163
def test_upload_hdfs_afm(self):
134164
base_dir = os.getcwd()
135-
afm_path = "{0}/../data/afm/demo_hadoop_row_filter_regression.afm".format(base_dir)
165+
afm_path = "{0}/data/afm/demo_hadoop_row_filter_regression.afm".format(base_dir)
136166
#afm_path = "demo_hadoop_row_filter_regression.afm"
137167
try:
138168
workfile_id = alpine_client.workfile.get_id("demo_hadoop_row_filter_regression", workspace_id)
@@ -147,7 +177,7 @@ def test_upload_hdfs_afm(self):
147177

148178
def test_upload_db_afm(self):
149179
base_dir = os.getcwd()
150-
afm_path = "{0}/../data/afm/db_bat_row_fil.afm".format(base_dir)
180+
afm_path = "{0}/data/afm/db_bat_row_fil.afm".format(base_dir)
151181
#afm_path = "db_bat_row_fil.afm"
152182
try:
153183
workfile_id = alpine_client.workfile.get_id("db_bat_row_fil", workspace_id)

0 commit comments

Comments
 (0)