diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..dd6ad3702 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,16 @@ +version: 2 +jobs: + test: + docker: + - image: circleci/python:3.7-buster + steps: + - checkout + - run: + name: Run tests + command: python3 -m unittest + +workflows: + version: 2 + per_pr: + jobs: + - test diff --git a/MANIFEST.in b/MANIFEST.in index 78f3d19f7..d82c3479f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ include LICENSE include README.md +include changelog.md include build-requirements.txt include requirements.txt include securedrop_log/*.py diff --git a/build-requirements.txt b/build-requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/changelog.md b/changelog.md new file mode 100644 index 000000000..9c18f3c15 --- /dev/null +++ b/changelog.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.0.1 + + * Initial release. diff --git a/example.py b/example.py index 83662f416..1a582bbea 100644 --- a/example.py +++ b/example.py @@ -1,12 +1,12 @@ import logging -from oqubeslogging import OQubesLog +from securedrop_log import SecureDropLog import ex2 import ex1 def main(): - handler = OQubesLog("workvm", "logging") + handler = SecureDropLog("workvm", "logging") logging.basicConfig(level=logging.DEBUG, handlers=[handler]) logger = logging.getLogger("example") diff --git a/journal-example.py b/journal-example.py index fa468cb10..903412af9 100644 --- a/journal-example.py +++ b/journal-example.py @@ -1,11 +1,11 @@ import logging -from oqubeslogging import OQubesLog +from securedrop_log import SecureDropLog from systemd import journal import select def main(): - handler = OQubesLog("workvm", "logging") + handler = SecureDropLog("workvm", "logging") logging.basicConfig(level=logging.DEBUG, handlers=[handler]) logger = logging.getLogger("example") j = journal.Reader() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_logger.py b/tests/test_logger.py new file mode 100644 index 000000000..174544f00 --- /dev/null +++ b/tests/test_logger.py @@ -0,0 +1,18 @@ +from unittest import mock, TestCase + +import securedrop_log + + +@mock.patch('securedrop_log.Popen') +class TestLogger(TestCase): + def test_singleton_there_can_be_only_one(self, mock_popen): + logger1 = securedrop_log.SecureDropLog('name', 'logvmname') + logger2 = securedrop_log.SecureDropLog('name', 'logvmname') + + self.assertEqual(logger1.qubes_log, logger2.qubes_log) + + def test_singleton_raises_exception_for_dev(self, mock_popen): + logger1 = securedrop_log.SecureDropLog('name', 'logvmname') + + with self.assertRaises(Exception): + logger2 = securedrop_log.SecureDropLog('name2', 'logvmname2')