Description: Skip tests with dependencies we don't have

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: no

--- a/tests/test_pagure_flask_ui_groups.py
+++ b/tests/test_pagure_flask_ui_groups.py
@@ -16,8 +16,6 @@ import sys
 import os
 
 import json
-import pagure_messages
-from fedora_messaging import api, testing
 from mock import ANY, patch
 
 sys.path.insert(
@@ -269,6 +267,11 @@ class PagureFlaskGroupstests(tests.Model
             )
 
             # All good
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.GroupEditV1(
                     topic="pagure.group.edit",
--- a/tests/test_pagure_flask_ui_pr_edit.py
+++ b/tests/test_pagure_flask_ui_pr_edit.py
@@ -10,8 +10,6 @@ from __future__ import unicode_literals,
 import sys
 import os
 
-import pagure_messages
-from fedora_messaging import api, testing
 from mock import ANY, patch
 
 sys.path.insert(
@@ -234,6 +232,11 @@ class PagureFlaskPrEdittests(tests.Model
                 "branch_to": "master",
                 "csrf_token": self.get_csrf(),
             }
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestInitialCommentEditedV1(
                     topic="pagure.pull-request.initial_comment.edited",
--- a/tests/test_pagure_lib_git_diff_pr.py
+++ b/tests/test_pagure_lib_git_diff_pr.py
@@ -19,8 +19,6 @@ import time  # noqa
 import os  # noqa
 
 import pygit2  # noqa
-import pagure_messages
-from fedora_messaging import api, testing
 from mock import ANY, patch, MagicMock
 
 sys.path.insert(
@@ -396,6 +394,11 @@ class PagureFlaskForkPrtests(tests.Model
 
         # Get the new diff for that PR and check its new ref
 
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.PullRequestUpdatedV1(
                 topic="pagure.pull-request.updated",
--- a/tests/test_pagure_flask_api_issue.py
+++ b/tests/test_pagure_flask_api_issue.py
@@ -20,11 +20,9 @@ import time
 import os
 
 import flask
-import pagure_messages
 import json
 import munch
 
-from fedora_messaging import api, testing
 from mock import ANY, patch, MagicMock
 from sqlalchemy.exc import SQLAlchemyError
 
@@ -515,6 +513,11 @@ class PagureFlaskApiIssuetests(tests.Sim
         }
 
         # Valid request
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.IssueNewV1(
                 topic="pagure.issue.new",
@@ -914,6 +917,11 @@ class PagureFlaskApiIssuetests(tests.Sim
             "private": 1,
             "assignee": "foo",
         }
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with self.assertRaises(AssertionError) as cm:
             with testing.mock_sends(api.Message()):
                 output = self.app.post(
@@ -3201,6 +3209,11 @@ class PagureFlaskApiIssuetests(tests.Sim
         data = {"milestone": "v1.0"}
 
         # Valid requests
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.IssueEditV1(
                 topic="pagure.issue.edit",
@@ -3891,6 +3904,11 @@ class PagureFlaskApiIssuetests(tests.Sim
         data = {"assignee": "pingou"}
 
         # Valid request
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.IssueAssignedAddedV1(
                 topic="pagure.issue.assigned.added",
--- a/tests/test_pagure_flask_api_project.py
+++ b/tests/test_pagure_flask_api_project.py
@@ -14,7 +14,6 @@ from __future__ import unicode_literals,
 import datetime
 import json
 import unittest
-import pagure_messages
 import shutil
 import sys
 import tempfile
@@ -22,7 +21,6 @@ import os
 
 import pygit2
 from celery.result import EagerResult
-from fedora_messaging import api, testing
 from mock import ANY, patch, Mock
 
 sys.path.insert(
@@ -2991,6 +2989,11 @@ class PagureFlaskApiProjectFlagtests(tes
             "uid": "jenkins_build_pagure_100+seed",
             "status": "pending",
         }
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.CommitFlagAddedV1(
                 topic="pagure.commit.flag.added",
@@ -5441,6 +5444,11 @@ class PagureFlaskApiProjectCreateProject
         }
 
         # Valid request
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.ProjectNewV1(
                 topic="pagure.project.new",
--- a/tests/test_pagure_flask_rebase.py
+++ b/tests/test_pagure_flask_rebase.py
@@ -17,9 +17,7 @@ import sys
 import os
 
 import json
-import pagure_messages
 import pygit2
-from fedora_messaging import api, testing
 from mock import ANY, patch, MagicMock
 
 sys.path.insert(
@@ -473,7 +471,11 @@ class PagureRebaseNoHooktests(PagureReba
                     "short_code": "With merge",
                 },
             )
-
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestRebasedV1(
                     topic="pagure.pull-request.rebased",
--- a/tests/test_pagure_flask_ui_repo_delete_project.py
+++ b/tests/test_pagure_flask_ui_repo_delete_project.py
@@ -13,9 +13,7 @@ from __future__ import unicode_literals,
 import sys
 import os
 
-import pagure_messages
 from mock import ANY, patch, MagicMock
-from fedora_messaging import testing
 
 sys.path.insert(
     0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
@@ -196,6 +194,11 @@ class PagureFlaskDeleteRepotests(tests.M
 
         user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectDeletedV1(
                     topic="pagure.project.deleted",
--- a/tests/test_pagure_flask_api_pr_flag.py
+++ b/tests/test_pagure_flask_api_pr_flag.py
@@ -15,8 +15,6 @@ import sys
 import os
 
 import json
-import pagure_messages
-from fedora_messaging import api, testing
 from mock import ANY, patch, MagicMock
 
 sys.path.insert(
@@ -245,6 +243,11 @@ class PagureFlaskApiPRFlagtests(tests.Mo
         }
 
         # Valid request
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.CommitFlagAddedV1,
             pagure_messages.PullRequestFlagAddedV1(
@@ -519,7 +522,11 @@ class PagureFlaskApiPRFlagtests(tests.Mo
             "url": "http://jenkins.cloud.fedoraproject.org/",
             "uid": "jenkins_build_pagure_100+seed",
         }
-
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.CommitFlagUpdatedV1,
             pagure_messages.PullRequestFlagUpdatedV1(
--- a/tests/test_pagure_flask_ui_fork.py
+++ b/tests/test_pagure_flask_ui_fork.py
@@ -19,12 +19,10 @@ import time
 import os
 import re
 
-import pagure_messages
 import pygit2
 import six
 from bs4 import BeautifulSoup
 from datetime import datetime, timedelta
-from fedora_messaging import api, testing
 from mock import ANY, patch, MagicMock
 
 sys.path.insert(
@@ -2431,7 +2429,11 @@ index 0000000..2a552bb
             repo.settings = settings
             self.session.add(repo)
             self.session.commit()
-
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestCommentAddedV1(
                     topic="pagure.pull-request.comment.added",
@@ -3185,6 +3187,11 @@ index 0000000..2a552bb
 
         user.username = "pingou"
         with tests.user_set(self.app.application, user):
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 api.Message(
                     topic="pagure.request.assigned.added",
@@ -3664,6 +3671,11 @@ index 0000000..2a552bb
 
             data = {"csrf_token": csrf_token, "user": None}
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 api.Message(
                     topic="pagure.request.assigned.reset",
@@ -4228,6 +4240,11 @@ index 0000000..2a552bb
             # Tag the PR
             data = {"csrf_token": csrf_token, "tag": "black"}
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestTagAddedV1(
                     topic="pagure.pull-request.tag.added",
@@ -4443,6 +4460,11 @@ index 0000000..2a552bb
             # Re-try to tag the PR
             data = {"csrf_token": csrf_token, "tag": "blue, yellow"}
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestTagAddedV1(
                     topic="pagure.pull-request.tag.added",
@@ -4909,6 +4931,11 @@ index 0000000..2a552bb
 
             data = {"csrf_token": csrf_token}
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectForkedV1(
                     topic="pagure.project.forked",
@@ -5190,6 +5217,11 @@ More information</textarea>
                 "initial_comment": "Test Initial Comment",
             }
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestNewV1(
                     topic="pagure.pull-request.new",
@@ -6513,6 +6545,11 @@ More information</textarea>
                 "csrf_token": csrf_token,
                 "comment": "This look alright but we can do better",
             }
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestCommentAddedV1(
                     topic="pagure.pull-request.comment.added",
@@ -6860,6 +6897,11 @@ More information</textarea>
                 "csrf_token": csrf_token,
                 "update_comment": "This look alright but we can do better than this.",
             }
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.PullRequestCommentEditedV1(
                     topic="pagure.pull-request.comment.edited",
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -21,12 +21,10 @@ try:
     import pyclamd
 except ImportError:
     pyclamd = None
-import pagure_messages
 import six
 import tempfile
 import re
 from datetime import datetime, timedelta
-from fedora_messaging import testing
 from six.moves.urllib.parse import urlparse, parse_qs
 
 import pygit2
@@ -1996,6 +1994,11 @@ class PagureFlaskIssuestests(tests.Model
 
             # Add two tags to the issue
             data = {"csrf_token": csrf_token, "tag": "red,green"}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueTagAddedV1(
                     topic="pagure.issue.tag.added",
@@ -2609,6 +2612,11 @@ class PagureFlaskIssuestests(tests.Model
                 "csrf_token": csrf_token,
                 "comment": "Woohoo a second comment!",
             }
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueCommentAddedV1(
                     topic="pagure.issue.comment.added",
@@ -2828,6 +2836,11 @@ class PagureFlaskIssuestests(tests.Model
 
             # Add a dependent ticket
             data = {"csrf_token": csrf_token, "depending": "2"}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueDependencyAddedV1(
                     topic="pagure.issue.dependency.added",
@@ -3077,6 +3090,11 @@ class PagureFlaskIssuestests(tests.Model
 
         # Create issues to play with
         repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        try:
+            import pagure_messages
+            from fedora_messaging import api, testing
+        except ImportError:
+            self.skipTest("pagure_messages and/or fedora_messaging not available")
         with testing.mock_sends(
             pagure_messages.IssueNewV1(
                 topic="pagure.issue.new",
@@ -3227,6 +3245,11 @@ class PagureFlaskIssuestests(tests.Model
 
             # Add a dependent ticket
             data = {"csrf_token": csrf_token, "blocking": "2"}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueDependencyAddedV1(
                     topic="pagure.issue.dependency.added",
@@ -3366,6 +3389,11 @@ class PagureFlaskIssuestests(tests.Model
 
             # Add a dependent ticket
             data = {"csrf_token": csrf_token}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueDependencyRemovedV1(
                     topic="pagure.issue.dependency.removed",
@@ -3842,6 +3870,11 @@ class PagureFlaskIssuestests(tests.Model
             self.assertEqual(output_text.count("Not a valid choice"), 0)
 
             data["csrf_token"] = csrf_token
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueEditV1(
                     topic="pagure.issue.edit",
@@ -4160,6 +4193,11 @@ class PagureFlaskIssuestests(tests.Model
             )
 
             data["csrf_token"] = csrf_token
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectTagEditedV1(
                     topic="pagure.project.tag.edited",
@@ -4290,6 +4328,11 @@ class PagureFlaskIssuestests(tests.Model
         user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
             data = {"tag": "tag1", "csrf_token": self.get_csrf()}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectTagRemovedV1(
                     topic="pagure.project.tag.removed",
@@ -4510,6 +4553,11 @@ class PagureFlaskIssuestests(tests.Model
             )
 
             data["csrf_token"] = csrf_token
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.IssueDropV1(
                     topic="pagure.issue.drop",
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -26,10 +26,8 @@ try:
 except ImportError:
     pass
 
-import pagure_messages
 import pygit2
 import six
-from fedora_messaging import testing
 from mock import ANY, patch, MagicMock
 
 sys.path.insert(
@@ -341,6 +339,11 @@ class PagureFlaskRepotests(tests.Modelte
 
             # All correct
             data["user"] = "foo"
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectUserAddedV1(
                     topic="pagure.project.user.added",
@@ -646,6 +649,11 @@ class PagureFlaskRepotests(tests.Modelte
 
             # All good
             data["access"] = "ticket"
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectGroupAddedV1(
                     topic="pagure.project.group.added",
@@ -1036,6 +1044,11 @@ class PagureFlaskRepotests(tests.Modelte
 
             data = {"csrf_token": csrf_token}
 
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectUserRemovedV1(
                     topic="pagure.project.user.removed",
@@ -1332,6 +1345,11 @@ class PagureFlaskRepotests(tests.Modelte
             self.assertEqual(len(repo.groups), 1)
 
             data = {"csrf_token": csrf_token}
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectGroupRemovedV1(
                     topic="pagure.project.group.removed",
@@ -1757,6 +1775,11 @@ class PagureFlaskRepotests(tests.Modelte
                 "issue_tracker": "y",
                 "fedmsg_notifications": "y",
             }
+            try:
+                import pagure_messages
+                from fedora_messaging import api, testing
+            except ImportError:
+                self.skipTest("pagure_messages and/or fedora_messaging not available")
             with testing.mock_sends(
                 pagure_messages.ProjectEditV1(
                     topic="pagure.project.edit",
--- a/tests/test_pagure_flask_ui_oidc_login.py
+++ b/tests/test_pagure_flask_ui_oidc_login.py
@@ -28,7 +28,12 @@ sys.path.insert(
 import pagure.lib
 import tests
 
-from pagure.ui.oidc_login import fas_user_from_oidc, oidc
+try:
+    import flask_oidc
+except ImportError:
+    flask_oidc = None
+else:
+    from pagure.ui.oidc_login import fas_user_from_oidc, oidc
 
 
 CLIENT_SECRETS = {
@@ -50,6 +55,8 @@ class PagureFlaskOIDCLogintests(tests.Si
 
     def setUp(self):
         """ Create the application with PAGURE_AUTH being local. """
+        if flask_oidc is None:
+            self.skipTest("flask_oidc not available")
         super(PagureFlaskOIDCLogintests, self).setUp()
 
         self.app = pagure.flask_app.create_app(
