diff --git a/config.py b/config.py index bbb20e4..561571c 100644 --- a/config.py +++ b/config.py @@ -26,7 +26,7 @@ class DefaultUser: datafile: Path = datadir / PATHS.datafile ignorefile: Path = datadir / PATHS.ignorefile settingsfile: Path = datadir / PATHS.settingsfile - lastlogin: float + lastlogin: str = "0.0" browser: str = "lynx" def save(self): @@ -68,21 +68,15 @@ def is_readable(st_mode: int) -> bool: def init(): """Performs startup checks to ensure environment is set up for use - Creates necessary data directory and data file. If they exist, no error - occurs. - Checks that the data directory and data file are group and other readable. - Sets some correct permissions if they are not. - Other errors may raise an exception. + If required, creates necessary data directory and data file. + If required, sets permissions to ensure the data directory and data file + are group and other readable. + Finally, tries to load the linkulator user configuration file, overwriting + with defaults if any issues. """ USER.datadir.mkdir(mode=0o755, exist_ok=True) - if not USER.settingsfile.is_file(): - with open(USER.settingsfile, "w+") as the_file: - the_file.write( - "[User Status]\nlastlogin = 0.0\n\n[User Settings]\nbrowser = lynx" - ) - if not is_readable(USER.datadir.stat().st_mode): print( "Warning: %s is not group or other readable - changing permissions" diff --git a/tests/config_test.py b/tests/config_test.py new file mode 100644 index 0000000..7cef21a --- /dev/null +++ b/tests/config_test.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +"""Tests for Linkulator configuration""" + +import unittest +import config + + +class TestConfigDefaults(unittest.TestCase): + """Tests covering configuration default settings""" + + def test_default_values_set(self): + """Test for issue reported in #74""" + # ensure config.USER.lastlogin exists and is a string + self.assertIsInstance(config.USER.lastlogin, str) + # ensure config.USER.lastlogin can be compared to string value + self.assertGreaterEqual(config.USER.lastlogin, "0.0")