Skip to content
Snippets Groups Projects
Verified Commit d60b73eb authored by Peter Stanko's avatar Peter Stanko
Browse files

Ability to upload

parent 53dfd55d
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -80,7 +80,7 @@ class Entity(object): ...@@ -80,7 +80,7 @@ class Entity(object):
def clean(self): def clean(self):
self.compress() self.compress()
shutil.rmtree(str(self.files_path)) shutil.rmtree(str(self.path))
def update_subdir(self, source: Union[str, Path], subdir: str) -> Path: def update_subdir(self, source: Union[str, Path], subdir: str) -> Path:
"""Updates subdirectory of the entity with files """Updates subdirectory of the entity with files
...@@ -130,9 +130,10 @@ class Entity(object): ...@@ -130,9 +130,10 @@ class Entity(object):
full = self.subdir(subdir=subdir) full = self.subdir(subdir=subdir)
return full.glob(pattern=pattern) return full.glob(pattern=pattern)
@property def delete(self):
def files_path(self): if self.zip_path.exists():
return self.path self.zip_path.unlink()
delete_dir(self.path)
class TestFiles(Entity): class TestFiles(Entity):
...@@ -169,8 +170,8 @@ class UploadedEntity(object): ...@@ -169,8 +170,8 @@ class UploadedEntity(object):
return self.entity.path return self.entity.path
@property @property
def files_path(self) -> Path: def path(self) -> Path:
return self.entity.files_path return self.entity.path
@property @property
def type(self) -> str: def type(self) -> str:
......
...@@ -7,9 +7,9 @@ log = logging.getLogger(__name__) ...@@ -7,9 +7,9 @@ log = logging.getLogger(__name__)
def filter_entity(entity): def filter_entity(entity):
filters = entity.filters.splitlines() filters = entity.filters.splitlines()
entity.files_path.mkdir(parents=True) entity.path.mkdir(parents=True)
from_path = entity.workspace / entity.from_dir from_path = entity.workspace / entity.from_dir
for pattern in filters: for pattern in filters:
log.info(f"[FLT] Filtering using filter for {pattern}") log.info(f"[FLT] Filtering using filter for {pattern}")
clone_files(src=from_path, dst=entity.files_path, pattern=pattern) clone_files(src=from_path, dst=entity.path, pattern=pattern)
return entity return entity
from pathlib import Path
import abc import abc
from pathlib import Path
from storage.entities import UploadedEntity, Submission, TestFiles, Entity, Results from storage.entities import Entity, Results, Submission, TestFiles, UploadedEntity
from storage.utils import unique_name, copy_and_overwrite from storage.utils import copy_and_overwrite, unique_name
class AbstractStoragePart(object): class AbstractStoragePart(object):
...@@ -80,7 +80,7 @@ class AbstractStoragePart(object): ...@@ -80,7 +80,7 @@ class AbstractStoragePart(object):
copy_and_overwrite( copy_and_overwrite(
src=from_instance.subdir('files'), src=from_instance.subdir('files'),
dst=to_instance.subdir('files') dst=to_instance.subdir('files')
) )
return to_instance return to_instance
def __instance(self, entity_id) -> Entity: def __instance(self, entity_id) -> Entity:
...@@ -119,6 +119,12 @@ class TestFilesStorage(AbstractStoragePart): ...@@ -119,6 +119,12 @@ class TestFilesStorage(AbstractStoragePart):
""" """
return Path(self.config.get('test_files_dir')) return Path(self.config.get('test_files_dir'))
def update(self, entity_id: str, **kwargs):
test_files = self.get(entity_id=entity_id)
if test_files:
test_files.delete()
return self.create(entity_id=entity_id, **kwargs)
class ResultsStorage(AbstractStoragePart): class ResultsStorage(AbstractStoragePart):
@property @property
......
...@@ -42,9 +42,9 @@ def uploaded_entity(workspace): ...@@ -42,9 +42,9 @@ def uploaded_entity(workspace):
def test_filtered_files(uploaded_entity): def test_filtered_files(uploaded_entity):
entity = filter_entity(uploaded_entity) entity = filter_entity(uploaded_entity)
assert (entity.files_path / 'src').exists() assert (entity.path / 'src').exists()
assert (entity.files_path / 'data').exists() assert (entity.path / 'data').exists()
assert not (entity.files_path / 'noot').exists() assert not (entity.path / 'noot').exists()
assert (entity.files_path / 'src/test-1.c').exists() assert (entity.path / 'src/test-1.c').exists()
assert (entity.files_path / 'data/test-1.c').exists() assert (entity.path / 'data/test-1.c').exists()
assert (entity.files_path / 'data/test-1.txt').exists() assert (entity.path / 'data/test-1.txt').exists()
...@@ -34,18 +34,18 @@ def submission(uploaded): ...@@ -34,18 +34,18 @@ def submission(uploaded):
def test_repo_will_be_cloned_successfully(submission: Submission, storage_instance: Storage, uploaded): def test_repo_will_be_cloned_successfully(submission: Submission, storage_instance: Storage, uploaded):
assert uploaded.version assert uploaded.version
assert submission.files_path.exists() assert submission.path.exists()
assert (submission.files_path / 'src').exists() assert (submission.path / 'src').exists()
assert (submission.files_path / 'src/main.c').exists() assert (submission.path / 'src/main.c').exists()
assert (submission.files_path / 'src/foo.c').exists() assert (submission.path / 'src/foo.c').exists()
assert (submission.files_path / 'src/bar.c').exists() assert (submission.path / 'src/bar.c').exists()
def test_repo_will_be_ziped(submission: Submission, storage_instance: Storage): def test_repo_will_be_ziped(submission: Submission, storage_instance: Storage):
assert submission.files_path.exists() assert submission.path.exists()
assert submission.compress() assert submission.compress()
assert submission.zip_path.exists() assert submission.zip_path.exists()
submission.clean() submission.clean()
assert not submission.files_path.exists() assert not submission.path.exists()
assert submission.decompress() assert submission.decompress()
assert submission.files_path.exists() assert submission.path.exists()
import pytest
from storage import Storage, Submission, UploadedEntity
@pytest.fixture
def git_config():
return dict(
type='git',
url='git@gitlab.fi.muni.cz:grp-kontr2/testing/test-repo.git',
branch='master'
)
@pytest.fixture
def test_request(git_config):
return dict(
entity_id="updated-git",
source=git_config,
whitelist="src/*",
from_dir='hw02'
)
@pytest.fixture
def updated_request(git_config):
return dict(
entity_id="updated-git",
source=git_config,
whitelist="main.c",
from_dir='hw01'
)
@pytest.fixture
def uploaded(test_request: dict, storage_instance: Storage) -> UploadedEntity:
return storage_instance.test_files.create(**test_request)
@pytest.fixture()
def updated(updated_request: dict, storage_instance: Storage, uploaded) -> UploadedEntity:
return storage_instance.test_files.update(**updated_request)
@pytest.fixture()
def submission(updated):
return updated.entity
def test_repo_will_be_cloned_successfully(submission: Submission, storage_instance: Storage,
uploaded):
assert uploaded.version
assert submission.path.exists()
assert (submission.path / 'main.c').exists()
assert not (submission.path / 'src').exists()
assert not (submission.path / 'src/main.c').exists()
assert not (submission.path / 'src/foo.c').exists()
assert not (submission.path / 'src/bar.c').exists()
def test_repo_will_be_zipped(submission: Submission, storage_instance: Storage):
assert submission.path.exists()
assert submission.compress()
assert submission.zip_path.exists()
submission.clean()
assert not submission.path.exists()
assert submission.decompress()
assert submission.path.exists()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment