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

Side by Side Diff: appengine/findit/crash/test/findit_for_chromecrash_test.py

Issue 2605943002: Removing the mutation in the factories for getting dep repositories (Closed)
Patch Set: Created 3 years, 11 months 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 unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import mock 5 import mock
6 6
7 from common import chrome_dependency_fetcher 7 from common import chrome_dependency_fetcher
8 from common.dependency import DependencyRoll 8 from common.dependency import DependencyRoll
9 from common.http_client_appengine import HttpClientAppengine 9 from common.http_client_appengine import HttpClientAppengine
10 from crash import chromecrash_parser 10 from crash import chromecrash_parser
(...skipping 12 matching lines...) Expand all
23 from crash.stacktrace import CallStack 23 from crash.stacktrace import CallStack
24 from crash.stacktrace import Stacktrace 24 from crash.stacktrace import Stacktrace
25 from crash.test.crash_pipeline_test import DummyCrashData 25 from crash.test.crash_pipeline_test import DummyCrashData
26 from crash.test.predator_testcase import PredatorTestCase 26 from crash.test.predator_testcase import PredatorTestCase
27 from crash.type_enums import CrashClient 27 from crash.type_enums import CrashClient
28 from libs.gitiles import gitiles_repository 28 from libs.gitiles import gitiles_repository
29 from model import analysis_status 29 from model import analysis_status
30 from model.crash.crash_analysis import CrashAnalysis 30 from model.crash.crash_analysis import CrashAnalysis
31 from model.crash.fracas_crash_analysis import FracasCrashAnalysis 31 from model.crash.fracas_crash_analysis import FracasCrashAnalysis
32 32
33 MOCK_REPOSITORY = None 33 MOCK_GET_REPOSITORY = lambda _: None # pragma: no cover
34 34
35 class _FinditForChromeCrash(FinditForChromeCrash): # pylint: disable = W 35 class _FinditForChromeCrash(FinditForChromeCrash): # pylint: disable = W
36 # We allow overriding the default MOCK_REPOSITORY because one unittest 36 # We allow overriding the default ``get_repository`` because one unittest
37 # needs to. 37 # needs to.
38 def __init__(self, repository=MOCK_REPOSITORY): 38 def __init__(self, get_repository=MOCK_GET_REPOSITORY):
39 super(_FinditForChromeCrash, self).__init__(repository) 39 super(_FinditForChromeCrash, self).__init__(get_repository)
40 40
41 @classmethod 41 @classmethod
42 def _ClientID(cls): # pragma: no cover 42 def _ClientID(cls): # pragma: no cover
43 """Avoid throwing a NotImplementedError. 43 """Avoid throwing a NotImplementedError.
44 44
45 Since this method is called from ``FinditForChromeCrash.__init__`` 45 Since this method is called from ``FinditForChromeCrash.__init__``
46 in order to construct the Azalea object, we need to not throw 46 in order to construct the Azalea object, we need to not throw
47 exceptions since we want to be able to test the FinditForChromeCrash 47 exceptions since we want to be able to test the FinditForChromeCrash
48 class itself. 48 class itself.
49 """ 49 """
50 return '' 50 return ''
51 51
52 @property 52 @property
53 def config(self): 53 def config(self):
54 """Avoid returning None. 54 """Avoid returning None.
55 55
56 The default ``Findit.config`` will return None if the client 56 The default ``Findit.config`` will return None if the client
57 id is not found in the CrashConfig. This in turn will cause 57 id is not found in the CrashConfig. This in turn will cause
58 ``FinditForChromeCrash.__init__`` to crash, since NoneType doesn't 58 ``FinditForChromeCrash.__init__`` to crash, since NoneType doesn't
59 have a ``get`` method. In general it's fine for things to crash, since 59 have a ``get`` method. In general it's fine for things to crash, since
60 noone should make instances of Findit subclasses which don't define 60 noone should make instances of Findit subclasses which don't define
61 ``_clientID``; but for this test suite, we want to permit instances 61 ``_clientID``; but for this test suite, we want to permit instances
62 of FinditForChromeCrash, so that we can test that class directly. 62 of FinditForChromeCrash, so that we can test that class directly.
63 """ 63 """
64 return {} 64 return {}
65 65
66 66
67 def _FinditForFracas(): 67 def _FinditForFracas():
68 """A helper to pass in the standard pipeline class.""" 68 """A helper to pass in the standard pipeline class."""
69 return FinditForFracas(MOCK_REPOSITORY) 69 return FinditForFracas(MOCK_GET_REPOSITORY)
70
71
72 def _GitilesRepositoryFactory(repo_url): # pragma: no cover
73 return gitiles_repository.GitilesRepository(
74 HttpClientAppengine(), repo_url)
70 75
71 76
72 class FinditForChromeCrashTest(PredatorTestCase): 77 class FinditForChromeCrashTest(PredatorTestCase):
73 78
74 chrome_dep_fetcher = chrome_dependency_fetcher.ChromeDependencyFetcher(
75 gitiles_repository.GitilesRepository(HttpClientAppengine()))
76
77 # TODO(wrengr): what was the purpose of this test? As written it's 79 # TODO(wrengr): what was the purpose of this test? As written it's
78 # just testing that mocking works. I'm guessing it was to check that 80 # just testing that mocking works. I'm guessing it was to check that
79 # we fail when the analysis is for the wrong client_id; but if so, 81 # we fail when the analysis is for the wrong client_id; but if so,
80 # then we shouldn't need to mock FindCulprit... 82 # then we shouldn't need to mock FindCulprit...
81 def testFindCulprit(self): 83 def testFindCulprit(self):
82 self.mock(FinditForChromeCrash, 'FindCulprit', lambda self, *_: None) 84 self.mock(FinditForChromeCrash, 'FindCulprit', lambda self, *_: None)
83 85
84 # TODO(wrengr): would be less fragile to call 86 # TODO(wrengr): would be less fragile to call
85 # FinditForFracas.CreateAnalysis instead; though if I'm right about 87 # FinditForFracas.CreateAnalysis instead; though if I'm right about
86 # the original purpose of this test, then this is one of the few 88 # the original purpose of this test, then this is one of the few
87 # places where calling FracasCrashAnalysis directly would actually 89 # places where calling FracasCrashAnalysis directly would actually
88 # make sense. 90 # make sense.
89 analysis = FracasCrashAnalysis.Create({'signature': 'sig'}) 91 analysis = FracasCrashAnalysis.Create({'signature': 'sig'})
90 # TODO(wrengr): shouldn't FracasCrashAnalysis.Create already have set 92 # TODO(wrengr): shouldn't FracasCrashAnalysis.Create already have set
91 # the client_id? 93 # the client_id?
92 analysis.client_id = CrashClient.FRACAS 94 analysis.client_id = CrashClient.FRACAS
93 95
94 findit_client = _FinditForChromeCrash( 96 findit_client = _FinditForChromeCrash(_GitilesRepositoryFactory)
95 gitiles_repository.GitilesRepository(HttpClientAppengine()))
96 self.assertIsNone(findit_client.FindCulprit(analysis)) 97 self.assertIsNone(findit_client.FindCulprit(analysis))
97 98
98 99
99 class FinditForFracasTest(PredatorTestCase): 100 class FinditForFracasTest(PredatorTestCase):
100 101
101 def testPlatformRename(self): 102 def testPlatformRename(self):
102 self.assertEqual(_FinditForFracas().RenamePlatform('linux'), 'unix') 103 self.assertEqual(_FinditForFracas().RenamePlatform('linux'), 'unix')
103 104
104 def testCheckPolicyUnsupportedPlatform(self): 105 def testCheckPolicyUnsupportedPlatform(self):
105 self.assertIsNone(_FinditForFracas().CheckPolicy(DummyCrashData( 106 self.assertIsNone(_FinditForFracas().CheckPolicy(DummyCrashData(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 def testProcessResultForPublishing(self, mocked_get_default_host, 271 def testProcessResultForPublishing(self, mocked_get_default_host,
271 mocked_urlsafe): 272 mocked_urlsafe):
272 mocked_host = 'http://host' 273 mocked_host = 'http://host'
273 mocked_get_default_host.return_value = mocked_host 274 mocked_get_default_host.return_value = mocked_host
274 urlsafe_key = 'abcde' 275 urlsafe_key = 'abcde'
275 mocked_urlsafe.return_value = urlsafe_key 276 mocked_urlsafe.return_value = urlsafe_key
276 277
277 crash_identifiers = {'signature': 'sig'} 278 crash_identifiers = {'signature': 'sig'}
278 analysis = FracasCrashAnalysis.Create(crash_identifiers) 279 analysis = FracasCrashAnalysis.Create(crash_identifiers)
279 analysis.result = {'other': 'data'} 280 analysis.result = {'other': 'data'}
280 findit_object = FinditForFracas(None) 281 findit_object = FinditForFracas(MOCK_GET_REPOSITORY)
281 expected_processed_suspect = { 282 expected_processed_suspect = {
282 'client_id': findit_object.client_id, 283 'client_id': findit_object.client_id,
283 'crash_identifiers': {'signature': 'sig'}, 284 'crash_identifiers': {'signature': 'sig'},
284 'result': { 285 'result': {
285 'feedback_url': ( 286 'feedback_url': (
286 findit_for_chromecrash._FRACAS_FEEDBACK_URL_TEMPLATE % ( 287 findit_for_chromecrash._FRACAS_FEEDBACK_URL_TEMPLATE % (
287 mocked_host, urlsafe_key)), 288 mocked_host, urlsafe_key)),
288 'other': 'data' 289 'other': 'data'
289 } 290 }
290 } 291 }
291 292
292 self.assertDictEqual(findit_object.GetPublishableResult(crash_identifiers, 293 self.assertDictEqual(findit_object.GetPublishableResult(crash_identifiers,
293 analysis), 294 analysis),
294 expected_processed_suspect) 295 expected_processed_suspect)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698