OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """changes.ChangeStore unit tests""" | 6 """changes.ChangeStore unit tests""" |
7 | 7 |
8 import datetime | 8 import datetime |
9 import json | 9 import json |
10 import unittest | 10 import unittest |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 change = self.store._find_change(m.revision, m.change_id) | 63 change = self.store._find_change(m.revision, m.change_id) |
64 cache = self.buildbot.change_cache | 64 cache = self.buildbot.change_cache |
65 cache.get.assert_called_once_with((m.revision, m.change_id)) | 65 cache.get.assert_called_once_with((m.revision, m.change_id)) |
66 self.assertEqual(change, cache.get.return_value) | 66 self.assertEqual(change, cache.get.return_value) |
67 | 67 |
68 def test_get_change(self): | 68 def test_get_change(self): |
69 cache = self.buildbot.change_cache | 69 cache = self.buildbot.change_cache |
70 cache.get.return_value = None | 70 cache.get.return_value = None |
71 result = run_deferred(self.store.get_change(self.buildbucket_change)) | 71 result = run_deferred(self.store.get_change(self.buildbucket_change)) |
72 | 72 |
73 info = json.dumps({ | 73 info = { |
74 common.BUILDBUCKET_CHANGE_ID_PROPERTY: '1', | 74 common.BUILDBUCKET_CHANGE_ID_PROPERTY: '1', |
75 }, sort_keys=True) | 75 } |
76 self.buildbot.add_change_to_db.assert_called_once_with( | 76 self.buildbot.add_change_to_db.assert_called_once_with( |
77 author=self.buildbucket_change['author']['email'], | 77 author=self.buildbucket_change['author']['email'], |
78 files=[], | 78 files=[], |
79 comments=self.buildbucket_change['message'], | 79 comments=self.buildbucket_change['message'], |
80 revision=self.buildbucket_change['revision'], | 80 revision=self.buildbucket_change['revision'], |
81 when_timestamp=datetime.datetime(2014, 12, 22), | 81 when_timestamp=datetime.datetime(2014, 12, 22), |
82 branch=self.buildbucket_change['branch'], | 82 branch=self.buildbucket_change['branch'], |
83 category=common.CHANGE_CATEGORY, | 83 category=common.CHANGE_CATEGORY, |
84 revlink=self.buildbucket_change['url'], | 84 revlink=self.buildbucket_change['url'], |
85 properties={ | 85 properties={ |
86 common.INFO_PROPERTY: (info, 'Change'), | 86 common.INFO_PROPERTY: (info, 'Change'), |
87 }, | 87 }, |
88 repository=self.buildbucket_change.get('repo_url'), | 88 repository=self.buildbucket_change.get('repo_url'), |
89 project=self.buildbucket_change.get('project'), | 89 project=self.buildbucket_change.get('project'), |
90 ) | 90 ) |
91 self.assertEqual(result, self.buildbot.get_change_by_id.return_value) | 91 self.assertEqual(result, self.buildbot.get_change_by_id.return_value) |
92 | 92 |
93 def test_get_change_without_id(self): | 93 def test_get_change_without_id(self): |
94 cache = self.buildbot.change_cache | 94 cache = self.buildbot.change_cache |
95 cache.get.return_value = None | 95 cache.get.return_value = None |
96 result = run_deferred(self.store.get_change({ | 96 result = run_deferred(self.store.get_change({ |
97 'author': { | 97 'author': { |
98 'email': 'johndoe@chromium.org', | 98 'email': 'johndoe@chromium.org', |
99 }, | 99 }, |
100 'message': 'Hello world', | 100 'message': 'Hello world', |
101 })) | 101 })) |
102 | 102 |
103 expected_info = json.dumps({'change_id': None}) | 103 expected_info = {'change_id': None} |
104 self.buildbot.add_change_to_db.assert_called_once_with( | 104 self.buildbot.add_change_to_db.assert_called_once_with( |
105 author='johndoe@chromium.org', | 105 author='johndoe@chromium.org', |
106 files=[], | 106 files=[], |
107 comments='Hello world', | 107 comments='Hello world', |
108 revision='', | 108 revision='', |
109 when_timestamp=None, | 109 when_timestamp=None, |
110 branch=None, | 110 branch=None, |
111 category=common.CHANGE_CATEGORY, | 111 category=common.CHANGE_CATEGORY, |
112 revlink='', | 112 revlink='', |
113 properties={ | 113 properties={ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 result = run_deferred( | 149 result = run_deferred( |
150 self.store.get_source_stamp([self.buildbucket_change], cache=ss_cache)) | 150 self.store.get_source_stamp([self.buildbucket_change], cache=ss_cache)) |
151 self.assertFalse(self.buildbot.change_cache.get.called) | 151 self.assertFalse(self.buildbot.change_cache.get.called) |
152 self.assertFalse(self.buildbot.insert_source_stamp_to_db.called) | 152 self.assertFalse(self.buildbot.insert_source_stamp_to_db.called) |
153 self.assertEqual(result, ssid) | 153 self.assertEqual(result, ssid) |
154 | 154 |
155 | 155 |
156 if __name__ == '__main__': | 156 if __name__ == '__main__': |
157 unittest.main() | 157 unittest.main() |
OLD | NEW |