-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from keboola/feature/python-sync-actions-pagi…
…nation-review Feature/python sync actions pagination review
- Loading branch information
Showing
25 changed files
with
615 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ keboola.json-to-csv | |
mock | ||
freezegun | ||
nested-lookup | ||
python-dateutil | ||
python-dateutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class BasePagination: | ||
def get_page_params(self, paginator_params): | ||
raise NotImplementedError("Subclasses should implement this method") | ||
|
||
|
||
class DummyPagination(BasePagination): | ||
def get_page_params(self, paginator_params): | ||
return {} | ||
|
||
|
||
class OffsetPagination(BasePagination): | ||
def get_page_params(self, paginator_params): | ||
page_params = {} | ||
if paginator_params.get("firstPageParams", True): | ||
page_params[paginator_params.get("offsetParam", "offset")] = paginator_params.get("offset", 0) | ||
page_params[paginator_params.get("limitParam", "limit")] = paginator_params.get("limit") | ||
return page_params | ||
|
||
|
||
class PageNumPagination(BasePagination): | ||
def get_page_params(self, paginator_params): | ||
page_params = {} | ||
if paginator_params.get("firstPageParams"): | ||
page_params[paginator_params.get("pageParam", "page")] = paginator_params.get("firstPage", 1) | ||
if paginator_params.get("limit"): | ||
page_params[paginator_params.get("limitParam", "limit")] = paginator_params.get("limit") | ||
return page_params | ||
|
||
|
||
class PaginationBuilder: | ||
|
||
@classmethod | ||
def get_paginator(cls, pagination): | ||
"""Factory function to create the appropriate paginator configuration.""" | ||
if pagination == 'offset': | ||
return OffsetPagination() | ||
elif pagination == 'pagenum': | ||
return PageNumPagination() | ||
else: | ||
return DummyPagination() |
2 changes: 1 addition & 1 deletion
2
python-sync-actions/tests/calls/002-token-body/orders.requestHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
accept: */* | ||
accept: */* |
2 changes: 1 addition & 1 deletion
2
python-sync-actions/tests/calls/005-query/orders.requestHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
accept: */* | ||
accept: */* |
72 changes: 36 additions & 36 deletions
72
python-sync-actions/tests/calls/006-login-auth-headers/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
{ | ||
"parameters": { | ||
"__SELECTED_JOB": "0", | ||
"api": { | ||
"baseUrl": "http://mock-server:80/006-login-auth-headers/", | ||
"authentication": { | ||
"type": "login", | ||
"loginRequest": { | ||
"endpoint": "login", | ||
"method": "GET", | ||
"headers": { | ||
"X-Login": "JohnDoe", | ||
"X-Password": "TopSecret" | ||
} | ||
}, | ||
"apiRequest": { | ||
"headers": { | ||
"X-ApiToken": { | ||
"response": "authorization.token" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"debug": true, | ||
"outputBucket": "mock-server", | ||
"jobs": [ | ||
{ | ||
"endpoint": "users" | ||
} | ||
] | ||
} | ||
}, | ||
"action": "test_request" | ||
} | ||
{ | ||
"parameters": { | ||
"__SELECTED_JOB": "0", | ||
"api": { | ||
"baseUrl": "http://mock-server:80/006-login-auth-headers/", | ||
"authentication": { | ||
"type": "login", | ||
"loginRequest": { | ||
"endpoint": "login", | ||
"method": "GET", | ||
"headers": { | ||
"X-Login": "JohnDoe", | ||
"X-Password": "TopSecret" | ||
} | ||
}, | ||
"apiRequest": { | ||
"headers": { | ||
"X-ApiToken": { | ||
"response": "authorization.token" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"debug": true, | ||
"outputBucket": "mock-server", | ||
"jobs": [ | ||
{ | ||
"endpoint": "users" | ||
} | ||
] | ||
} | ||
}, | ||
"action": "test_request" | ||
} |
2 changes: 1 addition & 1 deletion
2
python-sync-actions/tests/calls/006-login-auth-headers/login.requestHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
X-Login: JohnDoe | ||
X-Login: JohnDoe | ||
X-Password: TopSecret |
8 changes: 4 additions & 4 deletions
8
python-sync-actions/tests/calls/006-login-auth-headers/login.response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"authorization": { | ||
"token": "a1b2c3d435f6" | ||
} | ||
{ | ||
"authorization": { | ||
"token": "a1b2c3d435f6" | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
python-sync-actions/tests/calls/006-login-auth-headers/users.requestHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
accept: */* | ||
x-apitoken: a1b2c3d435f6 | ||
accept: */* | ||
x-apitoken: a1b2c3d435f6 |
20 changes: 10 additions & 10 deletions
20
python-sync-actions/tests/calls/006-login-auth-headers/users.response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[ | ||
{ | ||
"id": 123, | ||
"name": "John Doe" | ||
}, | ||
{ | ||
"id": 234, | ||
"name": "Jane Doe" | ||
} | ||
] | ||
[ | ||
{ | ||
"id": 123, | ||
"name": "John Doe" | ||
}, | ||
{ | ||
"id": 234, | ||
"name": "Jane Doe" | ||
} | ||
] |
70 changes: 70 additions & 0 deletions
70
python-sync-actions/tests/calls/007-page-params-pagenum/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"storage": {}, | ||
"parameters": { | ||
"__SELECTED_JOB": "0", | ||
|
||
"config": { | ||
"jobs": [ | ||
{ | ||
"__NAME": "orders", | ||
"endpoint": "007-page-params-pagenum/orders", | ||
"method": "GET", | ||
"dataType": "", | ||
"dataField": "nested.orders", | ||
"scroller": "pagenumber" | ||
} | ||
], | ||
"test": "test-value", | ||
"concat": { | ||
"function": "concat", | ||
"args": [ | ||
"hello", | ||
"-world" | ||
] | ||
}, | ||
"debug": false, | ||
"outputBucket": "in.c-", | ||
"incrementalOutput": false, | ||
"key": "asdfadsfadsf", | ||
"__AUTH_METHOD": "basic", | ||
"username": "name", | ||
"#password": "pass" | ||
}, | ||
"api": { | ||
"baseUrl": "http://mock-server:80/", | ||
"authentication": { | ||
"type": "basic" | ||
}, | ||
"pagination": { | ||
"method": "multiple", | ||
"scrollers": { | ||
"pagenumber": { | ||
"method": "pagenum", | ||
"limit": 100, | ||
"limitParam": "limit", | ||
"pageParam": "page", | ||
"firstPageParams": true, | ||
"firstPage": 1 | ||
} | ||
} | ||
} | ||
}, | ||
"http": { | ||
"maxRetries": 10, | ||
"codes": [ | ||
500, | ||
502, | ||
503, | ||
504, | ||
408, | ||
420, | ||
429 | ||
] | ||
} | ||
}, | ||
"action": "test_request", | ||
"image_parameters": { | ||
}, | ||
"authorization": { | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
python-sync-actions/tests/calls/007-page-params-pagenum/orders.request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GET /007-page-params-pagenum/orders?page=1&limit=100 |
2 changes: 2 additions & 0 deletions
2
python-sync-actions/tests/calls/007-page-params-pagenum/orders.requestHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
accept: */* | ||
authorization: Basic bmFtZTpwYXNz |
Oops, something went wrong.