From 3b09cae88b8d3a194bd1b493cbc9f731cea6cf17 Mon Sep 17 00:00:00 2001 From: "Kacper Kowalik (Xarthisius)" Date: Fri, 27 Oct 2023 09:11:34 -0500 Subject: [PATCH] fix: don't assume upload has all data --- tox.ini | 54 ++------------------------- virtual_resources/rest/__init__.py | 4 +- virtual_resources/tests/test_basic.py | 8 ---- virtual_resources/tests/test_file.py | 13 +------ 4 files changed, 7 insertions(+), 72 deletions(-) diff --git a/tox.ini b/tox.ini index fb08e1d..088e3eb 100644 --- a/tox.ini +++ b/tox.ini @@ -5,64 +5,18 @@ envlist = lint,pytest deps = -rrequirements-dev.txt commands = - pytest --cov=virtual_resources --cov-report=xml {posargs} + pytest {posargs} [testenv:lint] skip_install = true skipdist = true deps = - flake8 - flake8-bugbear - flake8-comprehensions - flake8-docstrings - flake8-import-order - pep8-naming + ruff commands = - flake8 {posargs} - -[flake8] -max-line-length = 100 -show-source = True -max-complexity = 14 -format = pylint -exclude = - node_modules, - .eggs, - .git, - __pycache__, - .tox -ignore = - # D10 - Missing docstring (errors D100 - D107) - D10, - # D200 - One-line docstrings should fit on one line with quotes. - D200, - # D205 - Blank line required between one-line summary and description. - D205, - # D400 - First line should end with a period. - D400, - # D401 - First line should be in imperative mood. - D401, - # E123 - Closing bracket does not match indentation of opening bracket's line - E123, - # N802 - Function name should be lowercase. - N802, - # N803 - Argument name should be lowercase. - N803, - # N806 - Variable in function should be lowercase. - N806, - # N812 - Lowercase imported as non lowercase. - N812, - # N815 - mixedCase variable in class scope - N815, - # N816 - mixedCase variable in global scope - N816, - # N818 - error suffix in exception name - N818, - # W503 - Line break occurred before a binary operator - W503, + ruff check . [pytest] -addopts = --verbose --strict --showlocals +addopts = --verbose --strict --showlocals --cov=virtual_resources --cov-report=xml cache_dir = build/test/pytest_cache junit_family = xunit2 testpaths = test diff --git a/virtual_resources/rest/__init__.py b/virtual_resources/rest/__init__.py index 26b152e..9fe743b 100644 --- a/virtual_resources/rest/__init__.py +++ b/virtual_resources/rest/__init__.py @@ -59,8 +59,8 @@ def wrapper(self, event): if "uploadId" in params: upload = Upload().load(params["uploadId"]) - parent_id = str(upload["parentId"]) - parent_type = upload["parentType"] + parent_id = str(upload.get("parentId")) + parent_type = upload.get("parentType") or "folder" else: parent_id = params.get("parentId") parent_type = params.get("parentType") or "folder" diff --git a/virtual_resources/tests/test_basic.py b/virtual_resources/tests/test_basic.py index afff66b..b8b9819 100644 --- a/virtual_resources/tests/test_basic.py +++ b/virtual_resources/tests/test_basic.py @@ -2,8 +2,6 @@ # -*- coding: utf-8 -*- import pathlib -import random -import string from girder.exceptions import ValidationException @@ -15,12 +13,6 @@ chunk1, chunk2 = ("hello ", "world") -def random_string(length=10): - """Generate a random string of fixed length.""" - letters = string.ascii_lowercase - return "".join(random.choice(letters) for i in range(length)) - - def test_vo_methods(mapped_folder): from virtual_resources.rest import VirtualObject diff --git a/virtual_resources/tests/test_file.py b/virtual_resources/tests/test_file.py index 56dd330..c6a3a2f 100644 --- a/virtual_resources/tests/test_file.py +++ b/virtual_resources/tests/test_file.py @@ -3,17 +3,12 @@ import os import pathlib -import random import shutil -import string - +import pytest from girder.models.assetstore import Assetstore from girder.models.setting import Setting from girder.settings import SettingKey - -import pytest - from pytest_girder.assertions import assertStatus, assertStatusOk from pytest_girder.utils import getResponseBody @@ -22,12 +17,6 @@ chunk1, chunk2 = ("hello ", "world") -def random_string(length=10): - """Generate a random string of fixed length.""" - letters = string.ascii_lowercase - return "".join(random.choice(letters) for i in range(length)) - - @pytest.mark.plugin("virtual_resources") def test_basic_file_ops(server, user, extra_user, example_mapped_folder): mapped_folder = example_mapped_folder["girder_root"]