aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Fung <stevefung@google.com>2016-05-04 15:58:46 -0700
committerSteve Fung <stevefung@google.com>2016-05-04 16:05:09 -0700
commit47a520ca49612c6249ce563c143b167304aee83b (patch)
tree7cbc60c2e49b602b6cccdd7324325d701faa9ec6
parent0ebce37d35afe62b227d58fa1637106ff62f3c60 (diff)
downloadbdk-47a520ca49612c6249ce563c143b167304aee83b.tar.gz
Fix clicommand unit tests to not check user store
The clicommand.RunWithMetrics tests code was never updated when the user store was refactored. As such, the stubs stopped taking effect, so the actual user store in the BDK tree was being created and used, which could lead to unpredictable behavior. Bug: 28590102 Change-Id: I3ec1b74b7f338fa086f38bb13c41be08e2c5e23e Test: `python test_runner.py` passes, no user_store created in BDK tree.
-rw-r--r--cli/lib/cli/clicommand_unittest.py11
-rw-r--r--cli/lib/core/config_stub.py52
-rw-r--r--cli/lib/core/user_config_stub.py7
3 files changed, 13 insertions, 57 deletions
diff --git a/cli/lib/cli/clicommand_unittest.py b/cli/lib/cli/clicommand_unittest.py
index c529e56..af8f888 100644
--- a/cli/lib/cli/clicommand_unittest.py
+++ b/cli/lib/cli/clicommand_unittest.py
@@ -21,7 +21,7 @@
import unittest
from cli import clicommand
-from core import config_stub
+from core import user_config_stub
from metrics import hit_store_stub
from metrics import metrics_util
from metrics.data_types import hit_stub
@@ -41,12 +41,13 @@ class RunWithMetricsTest(unittest.TestCase):
"""Tests to make sure RunWithMetrics() behaves as expected."""
def setUp(self):
- self.config_stub = config_stub.StubConfig(metrics_opt_in='1')
+ self.user_config_stub = user_config_stub.StubUserConfig(
+ metrics_opt_in='1')
self.hit_stub = hit_stub.StubHit()
self.hit_store_stub = hit_store_stub.StubHitStore()
- self.user_store_stub = self.config_stub.user_store
+ self.user_store_stub = self.user_config_stub.USER_CONFIG
- clicommand.metrics_util.config = self.config_stub
+ clicommand.metrics_util.user_config = self.user_config_stub
clicommand.metrics_util.hit = self.hit_stub
clicommand.metrics_util.hit_store = self.hit_store_stub
# pylint: disable=protected-access
@@ -89,7 +90,7 @@ class RunWithMetricsTest(unittest.TestCase):
def test_metrics_opt_out(self):
"""Tests metrics are never sent if the user has opted out."""
- self.config_stub.user_store.metrics_opt_in = '0'
+ self.user_config_stub.USER_CONFIG.metrics_opt_in = '0'
self.command.Run = lambda _args: 0
self.command.RunWithMetrics([])
diff --git a/cli/lib/core/config_stub.py b/cli/lib/core/config_stub.py
deleted file mode 100644
index 9131515..0000000
--- a/cli/lib/core/config_stub.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-"""core.config module stubs."""
-
-
-class StubConfig(object):
- """Stubs the core.config module.
-
- Attributes:
- user_store: the StubUserStore object that will be passed to the
- code under test. Modify this to get the desired behavior.
- """
-
- def __init__(self, **kwargs):
- """Initializes a StubConfig object.
-
- Args:
- kwargs: passed through to StubUserStore init.
- """
- self.user_store = self.StubUserStore(**kwargs)
-
- def UserStore(self, *_args, **_kwargs):
- """Returns our user_store object."""
- return self.user_store
-
- class StubUserStore(object):
- """Stubs the config.UserStore class."""
-
- def __init__(self, metrics_opt_in='1', is_complete=True):
- self.metrics_opt_in = metrics_opt_in
- self.is_complete = is_complete
- self.uid = 0
-
- def initialize(self, *_args, **_kwargs):
- pass
-
- def complete(self):
- return self.is_complete
diff --git a/cli/lib/core/user_config_stub.py b/cli/lib/core/user_config_stub.py
index 47fcace..905559a 100644
--- a/cli/lib/core/user_config_stub.py
+++ b/cli/lib/core/user_config_stub.py
@@ -25,6 +25,9 @@ class StubUserConfig(object):
EXPOSED = user_config.EXPOSED
+ def __init__(self, metrics_opt_in='0'):
+ self.USER_CONFIG.metrics_opt_in = metrics_opt_in
+
class UserConfig(object):
def __init__(self, file_path='user_data.db', table='totally_private'):
self.file_path = file_path
@@ -33,5 +36,9 @@ class StubUserConfig(object):
self.uid = 'user_id'
self.bsp_dir = 'somewhere/bsps'
self.platform_cache = 'elsewhere/pc'
+ self.is_complete = True
+
+ def complete(self):
+ return self.is_complete
USER_CONFIG = UserConfig()