Skip to content

Commit

Permalink
tests: Rework CLI tests
Browse files Browse the repository at this point in the history
The current tests do not take into account whether the `gpg` package has
been installed or not. If it is missing, the tests should be skipped.

Furthermore, the output of the tests must be checked in order to decide
whether tests fail due to an exception or whether the desired error message
is displayed.

Signed-off-by: Jörg Sommer <[email protected]>
  • Loading branch information
jo-so-nx authored and josch committed Jul 16, 2024
1 parent 48c90d6 commit 4c109dc
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions tests/test_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sys
import tempfile
import tests.helpers
import gpg
import shutil


Expand All @@ -39,10 +38,14 @@ def test_valid_signature(self):
self.tmpfile,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
check=False,
)
self.assertEqual(completed_process.returncode, 0, completed_process.stdout)
self.assertEqual(completed_process.returncode, 0)
self.assertEqual(completed_process.stdout, b"")
self.assertIn(
b"successfully verified bmap file signature", completed_process.stderr
)

def test_unknown_signer(self):
completed_process = subprocess.run(
Expand All @@ -57,10 +60,12 @@ def test_unknown_signer(self):
self.tmpfile,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
check=False,
)
self.assertEqual(completed_process.returncode, 1, completed_process.stdout)
self.assertEqual(completed_process.returncode, 1)
self.assertEqual(completed_process.stdout, b"")
self.assertIn(b"discovered a BAD GPG signature", completed_process.stderr)

def test_wrong_signature(self):
completed_process = subprocess.run(
Expand All @@ -75,10 +80,12 @@ def test_wrong_signature(self):
self.tmpfile,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
check=False,
)
self.assertEqual(completed_process.returncode, 1, completed_process.stdout)
self.assertEqual(completed_process.returncode, 1)
self.assertEqual(completed_process.stdout, b"")
self.assertIn(b"discovered a BAD GPG signature", completed_process.stderr)

def test_wrong_signature_uknown_signer(self):
completed_process = subprocess.run(
Expand All @@ -93,10 +100,12 @@ def test_wrong_signature_uknown_signer(self):
self.tmpfile,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
check=False,
)
self.assertEqual(completed_process.returncode, 1, completed_process.stdout)
self.assertEqual(completed_process.returncode, 1)
self.assertEqual(completed_process.stdout, b"")
self.assertIn(b"discovered a BAD GPG signature", completed_process.stderr)

def test_clearsign(self):
completed_process = subprocess.run(
Expand All @@ -109,12 +118,21 @@ def test_clearsign(self):
self.tmpfile,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
check=False,
)
self.assertEqual(completed_process.returncode, 0, completed_process.stdout)
self.assertEqual(completed_process.returncode, 0)
self.assertEqual(completed_process.stdout, b"")
self.assertIn(
b"successfully verified bmap file signature", completed_process.stderr
)

def setUp(self):
try:
import gpg
except ImportError:
self.skipTest("python module 'gpg' missing")

os.makedirs("tests/test-data/signatures", exist_ok=True)
for gnupghome, userid in [
("tests/test-data/gnupg/", "correct <[email protected]>"),
Expand Down

0 comments on commit 4c109dc

Please sign in to comment.