Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: dashboard/dashboard/testing_common.py

Issue 1549583002: In /graph_json, check internal_only on Test entity and skip test for all Row entities. (Closed) Base URL: https://github.com/catapult-project/catapult@master
Patch Set: Fixed assertions Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dashboard/dashboard/mr_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/dashboard/testing_common.py
diff --git a/dashboard/dashboard/testing_common.py b/dashboard/dashboard/testing_common.py
index 2ab35433aae9d957448bbe70e5204ad9d8210f57..77f2f5f4310f4539ced390045e827c880a0999ed 100644
--- a/dashboard/dashboard/testing_common.py
+++ b/dashboard/dashboard/testing_common.py
@@ -6,10 +6,12 @@
import base64
import json
+import mock
import os
import re
import unittest
import urllib
+import webapp2
from google.appengine.ext import deferred
from google.appengine.ext import ndb
@@ -22,6 +24,22 @@ from dashboard.models import graph_data
_QUEUE_YAML_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir)
+class FakeRequestObject(object):
+ """Fake Request object which can be used by datastore_hooks mocks."""
+
+ def __init__(self, remote_addr=None):
+ self.registry = {}
+ self.remote_addr = remote_addr
+
+
+class FakeResponseObject(object):
+ """Fake Response Object which can be returned by urlfetch mocks."""
+
+ def __init__(self, status_code, content):
+ self.status_code = status_code
+ self.content = content
+
+
class TestCase(unittest.TestCase):
"""Common base class for test cases."""
@@ -35,6 +53,7 @@ class TestCase(unittest.TestCase):
self.testbed.init_taskqueue_stub(root_path=_QUEUE_YAML_DIR)
self.testbed.init_user_stub()
self.testbed.init_urlfetch_stub()
+ self.mock_get_request = None
def tearDown(self):
self.testbed.deactivate()
@@ -100,6 +119,18 @@ class TestCase(unittest.TestCase):
return None
return None
+ def PatchDatastoreHooksRequest(self, remote_addr=None):
+ """This patches the request object to allow IP address to be set.
+
+ It should be used by tests which check code that does IP address checking
+ through datastore_hooks.
+ """
+ get_request_patcher = mock.patch(
+ 'webapp2.get_request',
+ mock.MagicMock(return_value=FakeRequestObject(remote_addr)))
+ self.mock_get_request = get_request_patcher.start()
+ self.addCleanup(get_request_patcher.stop)
+
def AddTests(masters, bots, tests_dict):
"""Adds data to the mock datastore.
@@ -177,14 +208,6 @@ def SetSheriffDomains(domains):
stored_object.Set(utils.SHERIFF_DOMAINS_KEY, domains)
-class FakeResponseObject(object):
- """Fake Response Object which can be returned by urlfetch mocks."""
-
- def __init__(self, status_code, content):
- self.status_code = status_code
- self.content = content
-
-
def SetIpWhitelist(ip_addresses):
"""Sets the list of whitelisted IP addresses."""
stored_object.Set(utils.IP_WHITELIST_KEY, ip_addresses)
« no previous file with comments | « dashboard/dashboard/mr_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698