diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..1ceb77be197bf025e2f80abb377e85b38e23fa62 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2021: +# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +import pytest + +from spearhead.configure import Configuration + + +@pytest.fixture() +def config(): + yield Configuration("./tests/config.yml") diff --git a/tests/data/state.txt b/tests/data/state.txt new file mode 100644 index 0000000000000000000000000000000000000000..86409e2e39d974109267fba107d90357b075da5a --- /dev/null +++ b/tests/data/state.txt @@ -0,0 +1 @@ +4749548 diff --git a/tests/test_file_handler.py b/tests/test_file_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..11401c15a4565785177e21801fa1a56a931229dc --- /dev/null +++ b/tests/test_file_handler.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2021: +# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +import logging + +import os +import pytest + +from spearhead.file_handler import FileHandler + +logger = logging.getLogger() + + +@pytest.fixture +def file_handler(config): + return FileHandler(config) + + +def test_file_handler_init(config): + file_handler = FileHandler(config) + assert file_handler + + +@pytest.mark.asyncio +async def test_read_state_file(file_handler): + state_number = await file_handler.read_state_file() + assert state_number == 4749548 + + +@pytest.mark.asyncio +async def test_update_state_file(file_handler): + await file_handler.update_state_file("4749545") + state_number = await file_handler.read_state_file() + assert state_number == 4749545 + await file_handler.update_state_file("4749548") + state_number = await file_handler.read_state_file() + assert state_number == 4749548 + + +@pytest.mark.asyncio +async def test_write_diff_report(file_handler): + await file_handler.write_diff_report("4749545", ["337202175", "17837838", "-387388722"]) + os.remove(file_handler.config.filepath + "augmented-diff-4749545.txt")