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
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.