From 77519f0fd36ac11db77384f29f37dbcd99f8bf4b Mon Sep 17 00:00:00 2001 From: David Trattnig <david@subsquare.at> Date: Fri, 15 Mar 2024 14:40:01 +0100 Subject: [PATCH] test: add first simple util tests --- tests/test_simple_util.py | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test_simple_util.py diff --git a/tests/test_simple_util.py b/tests/test_simple_util.py new file mode 100644 index 00000000..dd778365 --- /dev/null +++ b/tests/test_simple_util.py @@ -0,0 +1,71 @@ +# +# Aura Engine (https://gitlab.servus.at/aura/engine) +# +# Copyright (C) 2017-now() - The Aura Engine Team. + +# 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 datetime +import json +import unittest +from unittest import mock + +import requests + +from aura_engine.base.config import AuraConfig +from aura_engine.base.utils import SimpleUtil as SU + + +class TestSimpleUtil(unittest.TestCase): + """ + Test simple utility functions. + """ + + config = None + + # + # Setup + # + + def setUp(self): + self.config = AuraConfig.instance.config + + # + # Tests + # + + def test_timestamp(self): + print(self._testMethodName) + + ts = SU.timestamp() + self.assertIsNotNone(ts) + + dt = datetime.datetime(2024, 3, 15, 14, 8, 33, 0) + ts = SU.timestamp(dt) + self.assertIsNotNone(ts) + self.assertEqual(1710508113.0, ts) + + def test_timestamp_to_datetime(self): + print(self._testMethodName) + + expected_dt = datetime.datetime(2024, 3, 15, 14, 8, 33, 0) + ts = 1710508113.0 + dt = SU.timestamp_to_datetime(ts) + self.assertIsNotNone(dt) + self.assertEqual(expected_dt, dt) + + +if __name__ == "__main__": + unittest.main() -- GitLab