Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP ♻️ storage tests refactoring #2276

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7204157
WIP [skip ci]
pcrespov Apr 14, 2021
4d998cb
moved tests folder and cleaned-up fixtures
pcrespov Apr 22, 2021
18ffcb2
smal fixes
pcrespov Apr 22, 2021
c7040ec
upgrades reqs to latest
pcrespov Apr 22, 2021
81b57bf
moved s3wrapper inside storage
pcrespov Apr 22, 2021
b723eaa
minor
pcrespov Apr 22, 2021
02c32e3
updates reqs
pcrespov Apr 26, 2021
efea1d0
removes s3wrapper dependency from swarm-deploy
pcrespov Apr 26, 2021
3027f9e
adds minio in tests reqs for swarm-deploy
pcrespov Apr 26, 2021
b134867
Fixing bad merge. New storage has an extra level
pcrespov Apr 27, 2021
fc27f6c
Fixes reqs in storage
pcrespov Apr 27, 2021
2e767c8
storage: move all helpers to pytest-simcore
pcrespov Apr 27, 2021
ea45274
Structure refactoring
pcrespov Apr 27, 2021
7ce2435
bucket_name as fixture
pcrespov Apr 27, 2021
a170627
minor
pcrespov Apr 27, 2021
40a170d
Create tmp-file fixture
pcrespov Apr 27, 2021
332f7dd
Refactor creation of file-metadata
pcrespov Apr 27, 2021
aeae6df
missing save
pcrespov Apr 27, 2021
16c5726
fixes scope fixtures
pcrespov Apr 28, 2021
532aed5
Refactoring deep_copy_project_simcore_s3 and aiobotcore session
pcrespov Apr 28, 2021
148ae1c
WIP
pcrespov Apr 28, 2021
85c0f4e
utils_projects.py split in two to avoid webserver dependencies
pcrespov Apr 29, 2021
04331e0
Removed duplicate from merge
pcrespov Apr 29, 2021
8217c24
fixes tests after refactoring
pcrespov Apr 29, 2021
cd0f9a4
Upgraded api in pytest-simcore to latest minio. Upgraded all tests
pcrespov May 10, 2021
ef85e62
removes extras
pcrespov Jun 21, 2021
339e1b3
auto-formatting
pcrespov Jun 21, 2021
becfec8
another extra
pcrespov Jun 21, 2021
b7190a4
Removed blackfynn and other dependencies
pcrespov Jun 21, 2021
6566373
uses packaging instead of semantic_version
pcrespov Jun 21, 2021
2ac276f
moves datcore functionality to datcore_storage
pcrespov Jun 21, 2021
6a7279c
WIP: splitting dsm
pcrespov Jun 21, 2021
3d9bc64
Creating DataStorageInterface
pcrespov Jun 22, 2021
0f830a5
minor fix
pcrespov Jul 5, 2021
2c903b3
formatting
pcrespov Jul 5, 2021
aa3a5d5
minor cleanup reqs
pcrespov Jul 5, 2021
f3e7235
minor
pcrespov Jul 5, 2021
363de02
formatting
pcrespov Jul 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/github/unit-testing/storage.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install() {
test() {
pytest --cov=simcore_service_storage --durations=10 --cov-append \
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
-v -m "not travis" services/storage/tests
-v -m "not travis" services/storage/tests/unit
}

# Check if the function exists (bash specific)
Expand Down
1 change: 0 additions & 1 deletion packages/models-library/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint:disable=unused-argument
# pylint:disable=redefined-outer-name


from pytest_simcore.helpers.utils_pylint import (
assert_no_pdb_in_code,
assert_pylint_is_passing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import json
import re
import uuid as uuidlib
from datetime import datetime
from typing import Dict
from simcore_service_webserver.utils import now_str

from aiohttp import web

from simcore_service_webserver.projects.projects_db import (
APP_PROJECT_DBAPI,
DB_EXCLUSIVE_COLUMNS,
)
from simcore_service_webserver.resources import resources

# FIXME: remove dependencies with simcore_service_webserver
# TODO: and merge with utils_projects_extra.py


def now_str() -> str:
return "{}Z".format(datetime.utcnow().isoformat(timespec="milliseconds"))


fake_template_resources = [
"data/" + name
for name in resources.listdir("data")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# FIXME: temporary solution until simcore_service_webserver dependency is removed from utils_projects2.py


import uuid as uuidlib
from copy import deepcopy
from typing import Dict, Tuple
from typing import Any, Dict, Tuple


def clone_project_data(project: Dict) -> Tuple[Dict, Dict]:
def clone_project_data(project: Dict[str, Any]) -> Tuple[Dict, Dict]:
project_copy = deepcopy(project)

# Update project id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def osparc_simcore_root_dir(request) -> Path:
return root_dir


@pytest.fixture(scope="session")
def osparc_simcore_api_specs_dir(osparc_simcore_root_dir) -> Path:
dirpath = osparc_simcore_root_dir / "api" / "specs"
assert dirpath.exists()
return dirpath


@pytest.fixture(scope="session")
def osparc_simcore_services_dir(osparc_simcore_root_dir) -> Path:
""" Path to osparc-simcore/services folder """
Expand Down
11 changes: 9 additions & 2 deletions scripts/common-service.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export APP_VERSION
# COMMON TASKS
#

.env: .env-devel ## creates .env file from defaults in .env-devel
$(if $(wildcard $@), \
@echo "WARNING ##### $< is newer than $@ ####"; diff -uN $@ $<; false;,\
@echo "INFO $@ does not exist, cloning $< as $@"; cp $< $@)


.PHONY: install-dev install-prod install-ci

Expand All @@ -45,7 +50,7 @@ install-dev install-prod install-ci: _check_venv_active ## install app in develo
## pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.


.PHONY: test-dev-unit test-ci-unit test-dev-integration test-ci-integration test-dev
.PHONY: test-dev-unit test-ci-unit test-dev-integration test-ci-integration test-dev test-ci

test-dev-unit test-ci-unit: _check_venv_active
# Targets tests/unit folder
Expand All @@ -58,7 +63,9 @@ test-dev-integration test-ci-integration:
make --no-print-directory _run-$(subst -integration,,$@) target=$(CURDIR)/tests/integration


test-dev: test-dev-unit test-dev-integration ## runs unit and integration tests for development (e.g. w/ pdb)
test-dev: test-dev-unit test-dev-integration ## runs unit and integration tests for development (w/ pdb, fail-first)

test-ci: test-ci-unit test-ci-integration ## runs unit and integration tests for CI (w/ coverage, timing)

test-ci: test-ci-unit test-ci-integration ## runs unit and integration tests for CI

Expand Down
3 changes: 3 additions & 0 deletions scripts/common.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ version-minor: ## commits version with backwards-compatible API addition or chan
version-major: ## commits version with backwards-INcompatible addition or changes
$(_bumpversion)

.PHONY: reqs requirements
reqs requirements: ## compiles pip requirements (.in -> .txt). Usage 'make reqs upgrade=$package'
@$(MAKE_C) requirements reqs

#
# SUBTASKS
Expand Down
2 changes: 0 additions & 2 deletions services/storage/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ tests: ## runs unit tests


# DEVELOPMENT ########
.env:
cp .env-devel $@

run-devel: .env
# start app (within $<) in prod mode
Expand Down
5 changes: 0 additions & 5 deletions services/storage/requirements/_base.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ aiofiles
aiopg[sa]

tenacity
semantic_version
typer
minio
urllib3

#
# FIXME: pip copiling these requirements wil fail due to incompatible contraints on urllib3 (ongoing in weekely mainteinance)
#
17 changes: 5 additions & 12 deletions services/storage/requirements/_base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
# pip-compile --output-file=requirements/_base.txt requirements/_base.in
Expand All @@ -10,8 +10,6 @@ aiodebug==1.1.2
# via -r requirements/../../../packages/service-library/requirements/_base.in
aiofiles==0.7.0
# via -r requirements/_base.in
aiohttp-swagger[performance]==1.0.15
# via -r requirements/_base.in
aiohttp==3.7.4.post0
# via
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand All @@ -24,6 +22,8 @@ aiohttp==3.7.4.post0
# aiobotocore
# aiohttp-swagger
# aiozipkin
aiohttp-swagger[performance]==1.0.15
# via -r requirements/_base.in
aioitertools==0.7.1
# via aiobotocore
aiopg[sa]==1.3.0
Expand Down Expand Up @@ -60,8 +60,6 @@ dnspython==2.1.0
# via email-validator
email-validator==1.1.3
# via pydantic
fastapi==0.65.2
# via -r requirements/../../../packages/service-library/requirements/_base.in
idna==2.10
# via
# -r requirements/../../../packages/models-library/requirements/_base.in
Expand Down Expand Up @@ -125,11 +123,10 @@ pydantic[email]==1.8.2
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/_base.in
# -r requirements/../../../packages/settings-library/requirements/_base.in
# fastapi
pyinstrument-cext==0.2.4
# via pyinstrument
pyinstrument==3.4.2
# via -r requirements/../../../packages/service-library/requirements/_base.in
pyinstrument-cext==0.2.4
# via pyinstrument
pyrsistent==0.18.0
# via jsonschema
python-dateutil==2.8.1
Expand All @@ -144,8 +141,6 @@ pyyaml==5.4.1
# -r requirements/../../../packages/service-library/requirements/_base.in
# aiohttp-swagger
# openapi-spec-validator
semantic-version==2.8.5
# via -r requirements/_base.in
six==1.16.0
# via
# isodate
Expand All @@ -165,8 +160,6 @@ sqlalchemy[postgresql_psycopg2binary]==1.3.24
# -r requirements/../../../packages/postgres-database/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/_base.in
# aiopg
starlette==0.14.2
# via fastapi
strict-rfc3339==0.7
# via openapi-core
tenacity==7.0.0
Expand Down
24 changes: 12 additions & 12 deletions services/storage/requirements/_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
# pip-compile --output-file=requirements/_test.txt requirements/_test.in
Expand Down Expand Up @@ -54,12 +54,12 @@ cryptography==3.4.7
# paramiko
distro==1.5.0
# via docker-compose
docker[ssh]==5.0.0
# via docker-compose
docker-compose==1.29.1
# via
# -c requirements/../../../requirements/constraints.txt
# pytest-docker
docker[ssh]==5.0.0
# via docker-compose
dockerpty==0.4.1
# via docker-compose
docopt==0.6.2
Expand Down Expand Up @@ -120,6 +120,15 @@ pyrsistent==0.18.0
# via
# -c requirements/_base.txt
# jsonschema
pytest==6.2.4
# via
# -r requirements/_test.in
# pytest-aiohttp
# pytest-cov
# pytest-docker
# pytest-instafail
# pytest-mock
# pytest-sugar
pytest-aiohttp==0.3.0
# via -r requirements/_test.in
pytest-cov==2.12.1
Expand All @@ -134,15 +143,6 @@ pytest-runner==5.3.1
# via -r requirements/_test.in
pytest-sugar==0.9.4
# via -r requirements/_test.in
pytest==6.2.4
# via
# -r requirements/_test.in
# pytest-aiohttp
# pytest-cov
# pytest-docker
# pytest-instafail
# pytest-mock
# pytest-sugar
python-dateutil==2.8.1
# via
# -c requirements/_base.txt
Expand Down
2 changes: 1 addition & 1 deletion services/storage/requirements/_tools.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
# pip-compile --output-file=requirements/_tools.txt requirements/_tools.in
Expand Down
44 changes: 44 additions & 0 deletions services/storage/src/simcore_service_storage/abc_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional

from .models import DatasetMetaData, FileMetaDataEx


def DataStorageInterface(ABC):
"""An interface to any data storage system plugged to this service"""

@abstractmethod
async def is_responsive(self, session_id: str, **options) -> bool:
"""Returns True if service is available for a given session"""
raise NotImplementedError

# FILES resource ---

@abstractmethod
async def list_files(
self, session_id: str, *, fields_filter: Optional[Dict[str, Any]] = None
) -> List[FileMetaDataEx]:
"""Lists all files of a given session"""
# TODO: pagination
raise NotImplementedError

@abstractmethod
async def get_file(self, session_id: str, file_id: str) -> Optional[FileMetaDataEx]:
raise NotImplementedError

@abstractmethod
async def delete_file(self, session_id: str, file_id: str) -> None:
raise NotImplementedError

# DATASET resource ---
# - a group of files and its metadata?

@abstractmethod
async def list_datasets(self, session_id: str) -> List[DatasetMetaData]:
raise NotImplementedError

@abstractmethod
async def get_dataset(
self, session_id: str, dataset_id: str
) -> List[FileMetaDataEx]:
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def none(cls) -> "AccessRights":


class AccessLayerError(Exception):
""" Base class for access-layer related errors """
"""Base class for access-layer related errors"""


class InvalidFileIdentifier(AccessLayerError):
Expand Down Expand Up @@ -282,6 +282,6 @@ async def get_file_access_rights(


async def get_readable_project_ids(conn: SAConnection, user_id: int) -> List[ProjectID]:
""" Returns a list of projects where user has granted read-access """
"""Returns a list of projects where user has granted read-access"""
projects_access_rights = await list_projects_access_rights(conn, int(user_id))
return [pid for pid, access in projects_access_rights.items() if access.read]
Loading