autoland: move common test fixtures into conftest.py (bug 1368516) r?glob draft
authorMāris Fogels <mars@mozilla.com>
Mon, 29 May 2017 12:24:08 -0400
changeset 11117 66a288d290d5f6b2147e28e4155121e2d04c721b
parent 11116 5ff21685584d5f98b9458b2ac88550e388da57cd
child 11118 939a574d2988ac65cf78020f785598e669df4e62
push id1688
push usermfogels@mozilla.com
push dateMon, 29 May 2017 20:09:07 +0000
reviewersglob
bugs1368516
autoland: move common test fixtures into conftest.py (bug 1368516) r?glob Move some common test fixtures into conftest.py so that we can use them for a new API endpoint. MozReview-Commit-ID: LbMyUyD4YTa
autoland/tests/unit/conftest.py
autoland/tests/unit/test_autoland_api.py
new file mode 100644
--- /dev/null
+++ b/autoland/tests/unit/conftest.py
@@ -0,0 +1,54 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import base64
+
+import pytest
+from mock import MagicMock
+
+import autoland_rest
+
+
+@pytest.fixture
+def app():
+    return autoland_rest.app
+
+
+@pytest.fixture
+def autoland_config(monkeypatch):
+    """Swap out the .config module for a dict.
+
+    We need this because the .config module is hard-coded to read data from 
+    disk.
+    """
+    fake_config = dict()
+    monkeypatch.setattr('autoland_rest.config', fake_config)
+    return fake_config
+
+
+@pytest.fixture
+def dbcursor(monkeypatch):
+    """Fake a database connection and return a Mock cursor object."""
+    cursor = MagicMock()
+    get_dbconn = MagicMock()
+    get_dbconn.return_value.cursor.return_value = cursor
+    monkeypatch.setattr('autoland_rest.get_dbconn', get_dbconn)
+    return cursor
+
+
+@pytest.fixture
+def auth_basic(autoland_config):
+    """Return a pre-configured HTTP Basic auth header.
+
+    Also monkeypatches the app config so that the API user and password are
+    valid.
+    """
+    autoland_config['auth'] = {'foo': 'password'}
+    return [('Authorization', 'Basic ' + base64.b64encode('foo:password'))]
+
+
+@pytest.fixture
+def content_json():
+    """Return a ready-to-use JSON Content-Type header."""
+    return [('Content-Type', 'application/json')]
--- a/autoland/tests/unit/test_autoland_api.py
+++ b/autoland/tests/unit/test_autoland_api.py
@@ -1,79 +1,34 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import base64
+
 import json
 
 from flask import url_for
-from mock import MagicMock, sentinel
+from mock import sentinel
 import pytest
 
-import autoland_rest
 
 dummy_request = {
     "ldap_username": "cthulhu@mozilla.org",
     "tree": "mozilla-central",
     "rev": "9cc25f7ac50a",
     "destination": "try",
     "trysyntax": "try: -b o -p linux -u mochitest-1 -t none",
     "push_bookmark": "@",
     "commit_descriptions": {
         "9cc25f7ac50a": "bug 1 - did stuff r=gps"
     },
     "pingback_url": "http://localhost/"
 }
 
 
 @pytest.fixture
-def app():
-    return autoland_rest.app
-
-
-@pytest.fixture
-def autoland_config(monkeypatch):
-    """Swap out the .config module for a dict.
-
-    We need this because the .config module is hard-coded to read data from
-    disk.
-    """
-    fake_config = dict()
-    monkeypatch.setattr('autoland_rest.config', fake_config)
-    return fake_config
-
-
-@pytest.fixture
-def dbcursor(monkeypatch):
-    """Fake a database connection and return a Mock cursor object."""
-    cursor = MagicMock()
-    get_dbconn = MagicMock()
-    get_dbconn.return_value.cursor.return_value = cursor
-    monkeypatch.setattr('autoland_rest.get_dbconn', get_dbconn)
-    return cursor
-
-
-@pytest.fixture
-def auth_basic(autoland_config):
-    """Return a pre-configured HTTP Basic auth header.
-
-    Also monkeypatches the app config so that the API user and password are
-    valid.
-    """
-    autoland_config['auth'] = {'foo': 'password'}
-    return [('Authorization', 'Basic ' + base64.b64encode('foo:password'))]
-
-
-@pytest.fixture
-def content_json():
-    """Return a ready-to-use JSON Content-Type header."""
-    return [('Content-Type', 'application/json')]
-
-
-@pytest.fixture
 def mock_queued_job(dbcursor):
     """Mock the database cursor return values for a successful job submission.
     """
     # During successful processing of an autoland request the database "queue"
     # will be called 2 times: once to check that the job is already being
     # processed, and once to insert the new job.  We need to set the database
     # cursor mock's return value to handle both calls.