| |
@@ -0,0 +1,72 @@
|
| |
+ # -*- encoding: utf-8 -*-
|
| |
+
|
| |
+ import mock
|
| |
+
|
| |
+ try:
|
| |
+ import unittest2 as unittest
|
| |
+ except ImportError:
|
| |
+ import unittest
|
| |
+ from six import StringIO
|
| |
+
|
| |
+ from .helpers import get_compose, get_compose_path
|
| |
+
|
| |
+ import compose_utils
|
| |
+
|
| |
+
|
| |
+ class LookForBuildTest(unittest.TestCase):
|
| |
+ def test_present_nvr(self):
|
| |
+ compose = get_compose("DP-1.0-20160315.t.0")
|
| |
+ self.assertTrue(compose_utils.look_for_build(compose, "dummy-bash-4.2.37-6"))
|
| |
+
|
| |
+ def test_present_nevr(self):
|
| |
+ compose = get_compose("DP-1.0-20160315.t.0")
|
| |
+ self.assertTrue(compose_utils.look_for_build(compose, "dummy-bash-0:4.2.37-6"))
|
| |
+
|
| |
+ def test_missing_nvr(self):
|
| |
+ compose = get_compose("DP-1.0-20160315.t.0")
|
| |
+ self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-4.2.37-1"))
|
| |
+
|
| |
+ def test_missing_nevr(self):
|
| |
+ compose = get_compose("DP-1.0-20160315.t.0")
|
| |
+ self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-0:4.2.37-1"))
|
| |
+
|
| |
+ def test_missing_nevr_bad_epoch(self):
|
| |
+ compose = get_compose("DP-1.0-20160315.t.0")
|
| |
+ self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-1:4.2.37-6"))
|
| |
+
|
| |
+
|
| |
+ class HasBuildTest(unittest.TestCase):
|
| |
+ def setUp(self):
|
| |
+ self.path = get_compose_path("DP-1.0-20160315.t.0")
|
| |
+
|
| |
+ def test_present(self):
|
| |
+ with mock.patch("sys.stdout", new_callable=StringIO) as mock_out:
|
| |
+ compose_utils.has_build([self.path, "dummy-bash-4.2.37-6"])
|
| |
+
|
| |
+ self.assertEqual(
|
| |
+ "Compose DP-1.0-20160315.t.0 has build dummy-bash-4.2.37-6\n",
|
| |
+ mock_out.getvalue(),
|
| |
+ )
|
| |
+
|
| |
+ def test_missing(self):
|
| |
+ with mock.patch("sys.stdout", new_callable=StringIO) as mock_out:
|
| |
+ with self.assertRaises(SystemExit):
|
| |
+ compose_utils.has_build([self.path, "dummy-bash-4.2.37-1"])
|
| |
+
|
| |
+ self.assertEqual(
|
| |
+ "Compose DP-1.0-20160315.t.0 does not have build dummy-bash-4.2.37-1\n",
|
| |
+ mock_out.getvalue(),
|
| |
+ )
|
| |
+
|
| |
+ def test_present_quiet(self):
|
| |
+ with mock.patch("sys.stdout", new_callable=StringIO) as mock_out:
|
| |
+ compose_utils.has_build(["-q", self.path, "dummy-bash-4.2.37-6"])
|
| |
+
|
| |
+ self.assertEqual("", mock_out.getvalue())
|
| |
+
|
| |
+ def test_missing_quiet(self):
|
| |
+ with mock.patch("sys.stdout", new_callable=StringIO) as mock_out:
|
| |
+ with self.assertRaises(SystemExit):
|
| |
+ compose_utils.has_build(["-q", self.path, "dummy-bash-4.2.37-1"])
|
| |
+
|
| |
+ self.assertEqual("", mock_out.getvalue())
|
| |
The result is indicated in the exit code and a message on stdout (unless suppressed with
-q
option). The build can be specified as full NEVR or just NVR (in which case we assume epoch 0). It works with local path to compose or with a URL to the compose.Fixes: https://pagure.io/compose-utils/issue/73