mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix unit tests (#6932)
* Fix unit test * Fix script pathing * Fix pathing in version_check.py * Fix mkdocs.yml
This commit is contained in:
parent
5bec4ebb0e
commit
6be2ede5e8
4
.github/scripts/version_check.py
vendored
4
.github/scripts/version_check.py
vendored
@ -92,7 +92,9 @@ def check_version_number(version_string, allow_duplicate=False):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if 'only_version' in sys.argv:
|
if 'only_version' in sys.argv:
|
||||||
here = Path(__file__).parent.absolute()
|
here = Path(__file__).parent.absolute()
|
||||||
version_file = here.joinpath('..', 'InvenTree', 'InvenTree', 'api_version.py')
|
version_file = here.joinpath(
|
||||||
|
'..', '..', 'src', 'backend', 'InvenTree', 'InvenTree', 'api_version.py'
|
||||||
|
)
|
||||||
text = version_file.read_text()
|
text = version_file.read_text()
|
||||||
results = re.findall(r"""INVENTREE_API_VERSION = (.*)""", text)
|
results = re.findall(r"""INVENTREE_API_VERSION = (.*)""", text)
|
||||||
print(results[0])
|
print(results[0])
|
||||||
|
4
.github/workflows/qc_checks.yaml
vendored
4
.github/workflows/qc_checks.yaml
vendored
@ -157,7 +157,7 @@ jobs:
|
|||||||
if: needs.paths-filter.outputs.api == 'false'
|
if: needs.paths-filter.outputs.api == 'false'
|
||||||
run: |
|
run: |
|
||||||
pip install requests==2.31.0 >/dev/null 2>&1
|
pip install requests==2.31.0 >/dev/null 2>&1
|
||||||
version="$(python3 ci/version_check.py only_version 2>&1)"
|
version="$(python3 .github/scripts/version_check.py only_version 2>&1)"
|
||||||
echo "Version: $version"
|
echo "Version: $version"
|
||||||
url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml"
|
url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml"
|
||||||
echo "URL: $url"
|
echo "URL: $url"
|
||||||
@ -176,7 +176,7 @@ jobs:
|
|||||||
if: github.ref == 'refs/heads/master' && needs.paths-filter.outputs.api == 'true'
|
if: github.ref == 'refs/heads/master' && needs.paths-filter.outputs.api == 'true'
|
||||||
run: |
|
run: |
|
||||||
pip install requests==2.31.0 >/dev/null 2>&1
|
pip install requests==2.31.0 >/dev/null 2>&1
|
||||||
version="$(python3 ci/version_check.py only_version 2>&1)"
|
version="$(python3 .github/scripts/version_check.py only_version 2>&1)"
|
||||||
echo "Version: $version"
|
echo "Version: $version"
|
||||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ plugins:
|
|||||||
handlers:
|
handlers:
|
||||||
python:
|
python:
|
||||||
paths:
|
paths:
|
||||||
- ../InvenTree
|
- ../src/backend/InvenTree
|
||||||
options:
|
options:
|
||||||
show_symbol_type_heading: true
|
show_symbol_type_heading: true
|
||||||
show_symbol_type_toc: true
|
show_symbol_type_toc: true
|
||||||
|
@ -670,40 +670,7 @@ class TestHelpers(TestCase):
|
|||||||
with self.assertRaises(django_exceptions.ValidationError):
|
with self.assertRaises(django_exceptions.ValidationError):
|
||||||
InvenTree.helpers_model.download_image_from_url(url)
|
InvenTree.helpers_model.download_image_from_url(url)
|
||||||
|
|
||||||
def dl_helper(url, expected_error, timeout=2.5, retries=3):
|
large_img = 'https://github.com/inventree/InvenTree/raw/master/src/backend/InvenTree/InvenTree/static/img/paper_splash_large.jpg'
|
||||||
"""Helper function for unit testing downloads.
|
|
||||||
|
|
||||||
As the httpstat.us service occasionally refuses a connection,
|
|
||||||
we will simply try multiple times
|
|
||||||
"""
|
|
||||||
tries = 0
|
|
||||||
|
|
||||||
with self.assertRaises(expected_error):
|
|
||||||
while tries < retries:
|
|
||||||
try:
|
|
||||||
InvenTree.helpers_model.download_image_from_url(
|
|
||||||
url, timeout=timeout
|
|
||||||
)
|
|
||||||
break
|
|
||||||
except Exception as exc:
|
|
||||||
if type(exc) is expected_error:
|
|
||||||
# Re-throw this error
|
|
||||||
raise exc
|
|
||||||
else:
|
|
||||||
print('Unexpected error:', type(exc), exc)
|
|
||||||
|
|
||||||
tries += 1
|
|
||||||
time.sleep(10 * tries)
|
|
||||||
|
|
||||||
# Attempt to download an image which throws a 404
|
|
||||||
# TODO: Re-implement this test when we are happier with the external service
|
|
||||||
# dl_helper("https://httpstat.us/404", requests.exceptions.HTTPError, timeout=10)
|
|
||||||
|
|
||||||
# Attempt to download, but timeout
|
|
||||||
# TODO: Re-implement this test when we are happier with the external service
|
|
||||||
# dl_helper("https://httpstat.us/200?sleep=5000", requests.exceptions.ReadTimeout, timeout=1)
|
|
||||||
|
|
||||||
large_img = 'https://github.com/inventree/InvenTree/raw/master/InvenTree/InvenTree/static/img/paper_splash_large.jpg'
|
|
||||||
|
|
||||||
InvenTreeSetting.set_setting(
|
InvenTreeSetting.set_setting(
|
||||||
'INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 1, change_user=None
|
'INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 1, change_user=None
|
||||||
|
Loading…
Reference in New Issue
Block a user