Add trivial pre-cq e2e test
BUG=chromium:835076
TEST=main_test
Change-Id: I8aae58cd86123925168bbf6f3990ea50c6c3a843
diff --git a/main_test.py b/main_test.py
index 3dd6f68..0a40b33 100644
--- a/main_test.py
+++ b/main_test.py
@@ -15,7 +15,7 @@
from chromite.lib import cidb
from chromite.lib import constants
from chromite.lib import gerrit
-from google.cloud import datastore
+from google.cloud import datastore # pylint: disable=E0611,import-error
import pytest
import mock
@@ -58,8 +58,8 @@
return helper
-def _CQCronTest(client, cidb_conn,
- datastore_client, change_details_map):
+def _CronTest(client, cidb_conn, datastore_client, change_details_map,
+ endpoint='cq'):
"""Patches services with side-effects.
Args:
@@ -68,17 +68,18 @@
datastore_client: A fake datastore.Client
change_details_map: A Dict[int, object] mapping change numbers to change
details responses from the gerrit API.
+ endpoint: /cron/exonerate/<endpoint> to call, defaults to 'cq'
Returns:
- The JSON response from /cron/exonerate/cq
+ The JSON response from |endpoint|
"""
with mock.patch.object(datastore, 'Client', return_value=datastore_client),\
- mock.patch.object(cidb, 'CIDBConnection', return_value=cidb_conn),\
- mock.patch.object(gerrit, 'GetGerritHelper',
- return_value=_GerritHelper(change_details_map)),\
- _PatchDatetime():
+ mock.patch.object(cidb, 'CIDBConnection', return_value=cidb_conn),\
+ mock.patch.object(gerrit, 'GetGerritHelper',
+ return_value=_GerritHelper(change_details_map)),\
+ _PatchDatetime():
response = client.get(
- '/cron/exonerate/cq',
+ '/cron/exonerate/' + endpoint,
headers={main.APPENGINE_CRON_HEADER: 'true'})
return json.loads(response.get_data(as_text=True))
@@ -93,9 +94,14 @@
def TestEmptyDatabase(client, cidb_conn, datastore_client):
+ """Endpoints should succeed, but do nothing when the databases are empty."""
change_details_map = {}
- response = _CQCronTest(client, cidb_conn, datastore_client,
- change_details_map)
+ response = _CronTest(client, cidb_conn, datastore_client, change_details_map)
+ assert response['exonerated'] == []
+
+ response = _CronTest(
+ client, cidb_conn, datastore_client, change_details_map,
+ endpoint='pre-cq')
assert response['exonerated'] == []
@@ -128,8 +134,11 @@
'timestamp': '2017-01-01 00:00:00'
})
- response = _CQCronTest(client, cidb_conn, datastore_client,
- change_details_map)
+ response = _CronTest(client, cidb_conn, datastore_client, change_details_map)
+ assert response['exonerated'] == []
+
+ response = _CronTest(client, cidb_conn, datastore_client, change_details_map,
+ endpoint='pre-cq')
assert response['exonerated'] == []
@@ -162,6 +171,9 @@
'timestamp': '2017-01-01 00:00:00'
})
- response = _CQCronTest(client, cidb_conn, datastore_client,
- change_details_map)
+ response = _CronTest(client, cidb_conn, datastore_client, change_details_map)
assert response['exonerated'] == [[list(patch), build_id]]
+
+ response = _CronTest(client, cidb_conn, datastore_client, change_details_map,
+ endpoint='pre-cq')
+ assert response['exonerated'] == []