Debian Codegraph @

reno/tests/test_cache.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import collections
16 from unittest import mock
17
18 import fixtures
19 import textwrap
20
21
22 from reno import cache
23 from reno import config
24 from reno.tests import base
25
26
27 class TestCache(base.TestCase):
28
29 scanner_output = [
30 collections.OrderedDict([ # master
31 ('0.0.0', [('note1', 'shaA')]),
32 ('1.0.0', [('note2', 'shaB'), ('note3', 'shaC')]),
33 ]),
34 collections.OrderedDict([ # stable/1.0
35 ('1.0.1', [('note4', 'shaD')]),
36 ]),
37 ]
38
39 note_bodies = {
40 'note1': textwrap.dedent("""
41 prelude: >
42 This is the prelude.
43 """),
44 'note2': textwrap.dedent("""
45 issues:
46 - This is the first issue.
47 - This is the second issue.
48 """),
49 'note3': textwrap.dedent("""
50 features:
51 - We added a feature!
52 """),
53 'note4': textwrap.dedent("""
54 fixes:
55 - We fixed all the bugs!
56 """),
57 }
58
59 def _get_note_body(self, filename, sha):
60 return self.note_bodies.get(filename, '')
61
62 def _get_dates(self):
63 return {'1.0.0': 1547874431}
64
65 def setUp(self):
66 super(TestCache, self).setUp()
67 self.useFixture(
68 fixtures.MockPatch('reno.scanner.Scanner.get_file_at_commit',
69 new=self._get_note_body)
70 )
71 self.useFixture(
72 fixtures.MockPatch('reno.scanner.Scanner.get_version_dates',
73 new=self._get_dates)
74 )
75 self.c = config.Config('.')
76
77 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
78 @mock.patch('reno.scanner.Scanner.get_series_branches')
79 def test_build_cache_db(self, mock_get_branches, mock_get_notes):
80 mock_get_notes.side_effect = self.scanner_output
81 mock_get_branches.return_value = ['stable/1.0']
82 expected = {
83 'dates': [{'version': '1.0.0', 'date': 1547874431}],
84 'notes': [
85 {'version': '0.0.0',
86 'files': [('note1', 'shaA')]},
87 {'version': '1.0.0',
88 'files': [('note2', 'shaB'), ('note3', 'shaC')]},
89 {'version': '1.0.1',
90 'files': [('note4', 'shaD')]},
91 ],
92 'file-contents': {
93 'note1': {
94 'prelude': 'This is the prelude.\n',
95 },
96 'note2': {
97 'issues': [
98 'This is the first issue.',
99 'This is the second issue.',
100 ],
101 },
102 'note3': {
103 'features': ['We added a feature!'],
104 },
105 'note4': {
106 'fixes': ['We fixed all the bugs!'],
107 },
108 },
109 }
110
111 db = cache.build_cache_db(
112 self.c,
113 versions_to_include=[],
114 )
115
116 mock_get_branches.assert_called_once()
117 mock_get_notes.assert_has_calls([
118 mock.call(None), mock.call('stable/1.0')])
119 self.assertEqual(expected, db)