Skip to content

Commit

Permalink
add python mock server and refactor ci of http, upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Feb 1, 2024
1 parent 7c35c44 commit 23f7244
Show file tree
Hide file tree
Showing 18 changed files with 898 additions and 469 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
wget -qLO get-pip.py "$PIP_BOOTSTRAP_SCRIPT_PREFIX/$MAJOR.$MINOR/get-pip.py"
python get-pip.py --user
fi
- name: Setup mock server
run: |
conda create -n mock-server python=3.10
conda activate mock-server
nohup python3 ./tests/mock-server/main.py --port 9000 > py-mock-server.log &
echo $! > mock-server.pid
conda deactivate
- name: Install dependencies
shell: bash -l {0}
run: |
Expand All @@ -48,11 +56,11 @@ jobs:
QINIU_TEST_BUCKET: ${{ secrets.QINIU_TEST_BUCKET }}
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
QINIU_TEST_ENV: "travis"
MOCK_SERVER_ADDRESS: "http://127.0.0.1:9000"
PYTHONPATH: "$PYTHONPATH:."
run: |
set -e
flake8 --show-source --max-line-length=160 .
py.test --cov qiniu
coverage run -m pytest ./test_qiniu.py ./tests/cases
ocular --data-file .coverage
coverage run test_qiniu.py
codecov
8 changes: 7 additions & 1 deletion qiniu/http/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ def ok(self):
return self.status_code // 100 == 2

def need_retry(self):
if 0 < self.status_code < 500:
if 100 <= self.status_code < 500:
return False
if all([
self.status_code < 0,
self.exception is not None,
'BadStatusLine' in str(self.exception)
]):
return False
# https://developer.qiniu.com/fusion/kb/1352/the-http-request-return-a-status-code
if self.status_code in [
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ def find_version(*file_paths):
],
extras_require={
'dev': [
'coverage<7.2',
'coverage',
'flake8',
'pytest',
'pytest-cov',
'freezegun',
'scrutinizer-ocular',
'codecov'
],
'dev: python_version <= "3.4"': [
'pytest~=4.6',
'coverage~=5.5'
],
'dev: python_version < "3.8"': [
'pytest~=5.4',
'coverage~=7.1'
]
},

Expand Down
Loading

0 comments on commit 23f7244

Please sign in to comment.