File: test_storage.py

package info (click to toggle)
pywps 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,016 kB
  • sloc: python: 8,846; xml: 723; makefile: 106
file content (60 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
##################################################################
# Copyright 2018 Open Source Geospatial Foundation and others    #
# licensed under MIT, Please consult LICENSE.txt for details     #
##################################################################
from basic import TestBase
import pytest

from pywps.inout.storage.builder import StorageBuilder
from pywps.inout.storage.file import FileStorage
from pywps.inout.storage.s3 import S3Storage

from pywps import configuration

from pathlib import Path

import os

class FakeOutput(object):
    """Fake output object for testing."""

    def __init__(self, tmp_path):
        self.identifier = "fake_output"
        fn = Path(tmp_path) / "file.tiff"
        fn.touch()
        self.file = str(fn.absolute())
        self.uuid = None


class TestDefaultStorageBuilder(TestBase):

    def test_default_storage(self):
        storage = StorageBuilder.buildStorage()
        assert isinstance(storage, FileStorage)


class TestS3StorageBuilder(TestBase):

    def setUp(self) -> None:
        super().setUp()
        configuration.CONFIG.set('server', 'storagetype', 's3')

    def test_s3_storage(self):
        storage = StorageBuilder.buildStorage()
        assert isinstance(storage, S3Storage)


class TestFileStorageBuilder(TestBase):

    def setUp(self) -> None:
        super().setUp()
        configuration.CONFIG.set('server', 'storagetype', 'file')
        self.opath = os.path.join(self.tmpdir.name, "a", "b", "c")
        configuration.CONFIG.set('server', 'outputpath', self.opath)

    def test_recursive_directory_creation(self):
        """Test that outputpath is created."""
        storage = StorageBuilder.buildStorage()
        fn = FakeOutput(self.tmpdir.name)
        storage.store(fn)
        assert os.path.exists(self.opath)