| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # Copyright (c) 2019 Cinc |
|---|
| 3 | # All rights reserved. |
|---|
| 4 | # |
|---|
| 5 | # Redistribution and use in source and binary forms, with or without |
|---|
| 6 | # modification, are permitted provided that the following conditions |
|---|
| 7 | # are met: |
|---|
| 8 | # 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | # notice, this list of conditions and the following disclaimer. |
|---|
| 10 | # 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | # documentation and/or other materials provided with the distribution. |
|---|
| 13 | # 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | # derived from this software without specific prior written permission. |
|---|
| 15 | # |
|---|
| 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | |
|---|
| 27 | from codereview.model import ReviewFileModel |
|---|
| 28 | from datetime import datetime |
|---|
| 29 | from trac.util.datefmt import to_datetime, to_utimestamp |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | def prepare_review_data(env): |
|---|
| 33 | # owner, status, created, name, notes, parent_id |
|---|
| 34 | revs = [ |
|---|
| 35 | ['Rev1', 'bar', to_utimestamp(to_datetime(datetime(2019, 2, 4))), 'name1', 'note1', 0], |
|---|
| 36 | ['Rev1', 'closed', to_utimestamp(to_datetime(datetime(2019, 3, 4))), 'name2', 'note2', 0], # review_id = 2 |
|---|
| 37 | ['Rev2', 'bar', to_utimestamp(to_datetime(datetime(2019, 3, 14))), 'name3', 'note3', 1], |
|---|
| 38 | ['Rev3', 'foo', to_utimestamp(to_datetime(datetime(2019, 4, 4))), 'name4', 'note4', 2] |
|---|
| 39 | ] |
|---|
| 40 | |
|---|
| 41 | with env.db_transaction as db: |
|---|
| 42 | cursor = db.cursor() |
|---|
| 43 | for rev in revs: |
|---|
| 44 | cursor.execute("INSERT INTO peerreview (owner, status, created, name, notes, parent_id) " |
|---|
| 45 | "VALUES (%s,%s,%s,%s,%s,%s)", rev) |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | def prepare_file_data(env): |
|---|
| 49 | # review_id, path, start, end, revision, status |
|---|
| 50 | files = [ |
|---|
| 51 | [1, '/foo/bar', 5, 100, '1234', 'new', None, 'repo1'], # file_id = 1 |
|---|
| 52 | [1, '/foo/bar/2', 6, 101, '1234', 'new', None, 'repo1'], # file_id = 2 |
|---|
| 53 | [2, '/foo/bar/3', 5, 100, '1234', 'closed', None, 'repo1'], # file_id = 3. Belongs to closed review |
|---|
| 54 | [2, '/foo/bar', 6, 101, '12346', 'closed', None, 'repo1'], |
|---|
| 55 | [2, '/foo/bar3', 7, 102, '12347', 'closed', None, 'repo1'], |
|---|
| 56 | [3, '/foo/bar2', 6, 101, '1234', 'new', None, 'repo1'], |
|---|
| 57 | [4, '/foo/bar', 5, 100, '1234', 'new', None, 'repo1'], |
|---|
| 58 | [4, '/foo/bar2', 6, 101, '1234', 'new', None, 'repo1'], |
|---|
| 59 | # File list data for several projects |
|---|
| 60 | [0, '/foo/bar', 5, 100, '1234', 'new', 'PrjFoo', 'repo1'], |
|---|
| 61 | [0, '/foo/bar2', 6, 101, '1234', 'new', 'PrjFoo', 'repo1'], |
|---|
| 62 | [0, '/foo/bar', 5, 100, '1234', 'new', 'PrjBar', 'repo1'], |
|---|
| 63 | [0, '/foo/bar2', 6, 101, '12346', 'new', 'PrjBar', 'repo1'], |
|---|
| 64 | [0, '/foo/bar3', 7, 102, '12347', 'new', 'PrjFoo', 'repo1'], |
|---|
| 65 | [0, '/foo/bar/baz', 6, 101, '1234', 'new', 'PrjBar', 'repo1'], |
|---|
| 66 | [0, '/foo/bar', 5, 100, '1234', 'new', 'PrjBaz', 'repo1'], |
|---|
| 67 | [0, '/foo/bar2', 6, 101, '1234', 'new', 'PrjBaz', 'repo1'], |
|---|
| 68 | ] |
|---|
| 69 | for f in files: |
|---|
| 70 | rfm = ReviewFileModel(env) |
|---|
| 71 | rfm['review_id'] = f[0] |
|---|
| 72 | rfm['path'] = f[1] |
|---|
| 73 | rfm['line_start'] = f[2] |
|---|
| 74 | rfm['line_end'] = f[3] |
|---|
| 75 | rfm['revision'] = f[4] |
|---|
| 76 | rfm['status'] = f[5] |
|---|
| 77 | rfm['project'] = f[6] |
|---|
| 78 | rfm['repo'] = f[7] |
|---|
| 79 | rfm.insert() |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | def prepare_comments(env): |
|---|
| 83 | # file_id, parent_id, line_num, author, created, comment |
|---|
| 84 | comments = [[1, -1, 123, 'user1', to_utimestamp(to_datetime(datetime(2019, 2, 4))), 'Comment 1'], |
|---|
| 85 | [1, 1, 123, 'user4', to_utimestamp(to_datetime(datetime(2019, 2, 5))), 'Comment 2'], |
|---|
| 86 | [2, -1, 12, 'user1', to_utimestamp(to_datetime(datetime(2019, 2, 5))), 'Comment 3'], |
|---|
| 87 | [2, -1, 13, 'user2', to_utimestamp(to_datetime(datetime(2019, 2, 6))), 'Comment 4'], |
|---|
| 88 | [2, 4, 13, 'user3', to_utimestamp(to_datetime(datetime(2019, 2, 7))), 'Comment 5'], |
|---|
| 89 | [3, -1, 15, 'user3', to_utimestamp(to_datetime(datetime(2019, 2, 8))), 'Comment 6'], # closed review |
|---|
| 90 | [3, -1, 16, 'user4', to_utimestamp(to_datetime(datetime(2019, 2, 9))), 'Comment 7'], |
|---|
| 91 | ] |
|---|
| 92 | with env.db_transaction as db: |
|---|
| 93 | cursor = db.cursor() |
|---|
| 94 | for comm in comments: |
|---|
| 95 | cursor.execute("INSERT INTO peerreviewcomment (file_id, parent_id, line_num, author, created, comment) " |
|---|
| 96 | "VALUES (%s,%s,%s,%s,%s,%s)", comm) |
|---|