File: importer_tag_test.py

package info (click to toggle)
git-ubuntu 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,688 kB
  • sloc: python: 13,378; sh: 480; makefile: 2
file content (748 lines) | stat: -rw-r--r-- 28,912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# This file contains tests additional to importer_test.py grouped here because
# they are considerable on their own.

from unittest.mock import (
    patch,
)

import pygit2
import pytest

import gitubuntu.repo_builder as repo_builder
from gitubuntu.repo_builder import Commit, Placeholder
import gitubuntu.repo_comparator as repo_comparator
import gitubuntu.source_builder as source_builder

import gitubuntu.importer as target

from gitubuntu.test_fixtures import repo
from gitubuntu.importer_test import MockSPI, patch_get_commit_environment


# When importing a publishing record, there are two potential logical
# consequences:
#
#    1) Some new commit is created, with an associated tag; and/or
#    2) Some branch is adjusted to point at some commit
#
# If an existing tag with the same Git tree is found as a new publish
# event, we should reuse the tag, and adjust the corresponding branch to
# the same tagged commit.
#
# If no existing tag with the same Git tree is found, a new tree and a new
# import/applied tag that points to it should be created, as appropriate, and
# the corresponding branch should be adjusted to the the new tagged commit.
#
# If a new commit is created, appropriate commit parents are found in the
# existing Git commit graph. A changelog parent is the nearest (reverse
# chronologically) tagged version from the debian/changelog of the publishing
# record.

@pytest.mark.parametrize(
    [
        'input_repo',
        'expected_output_refs',
        'validation_repo_delta',
        'validation_repo_expected_identical_refs',
        'reuse',
    ],
    [
        # 1) An existing import tag (or reimport tag) with the same Git tree
        #   - Reuse import tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[Commit.from_spec(name='import')],
                branches={
                    'importer/ubuntu/trusty-proposed': Placeholder('import'),
                },
                tags={'importer/import/1-1': Placeholder('import')},
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
            ],
            # validation_repo_delta:
            {
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('import'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty-proposed',
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
            ],
            # reuse:
            True,
        ),
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='import',
                        mutate='import tag contents',
                    ),
                    Commit.from_spec(name='reimport'),
                ],
                branches={
                    'importer/ubuntu/trusty-proposed': Placeholder('import'),
                },
                tags={
                    'importer/import/1-1': Placeholder('import'),
                    'importer/reimport/import/1-1/0': Placeholder('import'),
                    'importer/reimport/import/1-1/1': Placeholder('reimport'),
                },
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
            ],
            # validation_repo_delta:
            {
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('reimport'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty-proposed',
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/reimport/import/1-1/0',
                'refs/tags/importer/reimport/import/1-1/1',
            ],
            # reuse:
            True,
        ),

        # 2) An existing import tag with a different Git tree and an existing
        #    upload tag with the same Git tree
        #    - Reuse upload tag, create reimport tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='import',
                        mutate='The import tag contents',
                    ),
                    Commit.from_spec(name='upload'),
                ],
                branches={
                    'importer/ubuntu/trusty-proposed': Placeholder('import'),
                },
                tags={
                    'importer/import/1-1': Placeholder('import'),
                    'importer/upload/1-1': Placeholder('upload'),
                },
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'update_tags': {
                    'importer/reimport/import/1-1/0': Placeholder('import'),
                    'importer/reimport/import/1-1/1': Placeholder('upload'),
                },
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('upload'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty-proposed',
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/upload/1-1',
                'refs/tags/importer/reimport/import/1-1/0',
                'refs/tags/importer/reimport/import/1-1/1',
            ],
            # reuse:
            True,
        ),

        # 3) An existing import tag with a different Git tree and an existing
        #    upload tag with a different Git tree
        #    - Create reimport tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='import',
                        mutate='The import tag contents',
                    ),
                    Commit.from_spec(
                        name='upload',
                        mutate='The upload tag contents',
                    ),
                ],
                branches={
                    'importer/ubuntu/trusty-proposed': Placeholder('import'),
                },
                tags={
                    'importer/import/1-1': Placeholder('import'),
                    'importer/upload/1-1': Placeholder('upload'),
                },
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/changelog',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'add_commits': [Commit.from_spec(
                    name='reimport',
                    message='Test commit (new)',
                )],
                'update_tags': {
                    'importer/reimport/import/1-1/0': Placeholder('import'),
                    'importer/reimport/import/1-1/1': Placeholder('reimport'),
                },
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('reimport'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty-proposed',
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/upload/1-1',
                'refs/tags/importer/reimport/import/1-1/0',
                'refs/tags/importer/reimport/import/1-1/1',
            ],
            # reuse:
            False,
        ),

        # 4) An existing import tag with a different Git tree and no upload tag
        #    - Create reimport tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='import',
                        mutate='The import tag contents',
                    ),
                ],
                branches={
                    'importer/ubuntu/trusty-proposed': Placeholder('import'),
                },
                tags={'importer/import/1-1': Placeholder('import')},
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/changelog',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'add_commits': [Commit.from_spec(
                    name='reimport',
                    message='Test commit (new)',
                )],
                'update_tags': {
                    'importer/reimport/import/1-1/0': Placeholder('import'),
                    'importer/reimport/import/1-1/1': Placeholder('reimport'),
                },
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('reimport'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty-proposed',
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/reimport/import/1-1/0',
                'refs/tags/importer/reimport/import/1-1/1',
            ],
            # reuse:
            False,
        ),

        # 5) No import tag and an existing upload tag with the same Git tree
        #    - Reuse upload tag, create import tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[Commit.from_spec(name='upload')],
                tags={'importer/upload/1-1': Placeholder('upload')},
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'update_tags': {
                    'importer/import/1-1': Placeholder('upload'),
                },
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('upload'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/upload/1-1',
            ],
            # reuse:
            True,
        ),

        # 6) No import tag and an existing upload tag with a different Git tree
        #    - Create import tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='upload',
                        mutate='The upload tag contents',
                    ),
                ],
                tags={'importer/upload/1-1': Placeholder('upload')},
            ),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/changelog',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'add_commits': [
                    Commit.from_spec(
                        name='publish',
                        message='Test commit (new)',
                    ),
                ],
                'update_tags': {
                    'importer/import/1-1': Placeholder('publish'),
                },
                'update_branches': {
                    'importer/ubuntu/trusty': Placeholder('publish'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/upload/1-1',
            ],
            # reuse:
            False,
        ),

        # 7) No import tags or upload tags
        #    - Create import tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(),
            # expected_output_refs:
            [
                'refs/heads/do-not-push',
                'refs/tags/importer/upstream/ubuntu/1.gz',
                'refs/heads/importer/importer/ubuntu/dsc',
                'refs/heads/importer/importer/ubuntu/pristine-tar',
                'refs/notes/importer/changelog',
                'refs/notes/importer/importer',
            ],
            # validation_repo_delta:
            {
                'add_commits': [
                    Commit.from_spec(
                        name='publish',
                        message='Test commit (new)',
                    ),
                ],
                'update_tags': {
                    'importer/import/1-1': Placeholder('publish'),
                },
                'update_branches': {
                     'importer/ubuntu/trusty': Placeholder('publish'),
                },
            },
            # validation_repo_expected_identical_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/tags/importer/import/1-1'
            ],
            # reuse:
            False,
        ),
    ]
)
@patch('gitubuntu.importer.get_import_tag_msg')
@patch('gitubuntu.importer.get_import_commit_msg')
def test_import_unapplied_spi_tags(
    get_import_commit_msg_mock,
    get_import_tag_msg_mock,
    repo,
    input_repo,
    expected_output_refs,
    validation_repo_delta,
    validation_repo_expected_identical_refs,
    reuse,
):
    """Test that unapplied tags are correctly created, adjusted and/or reused

    :param unittest.mock.Mock get_import_commit_msg_mock: mock of the function
        that determines the commit message to use for a given import
    :param unittest.mock.Mock get_import_tag_msg_mock: mock of the function
        that determines the tag message to use for a given import
    :param repo gitubuntu.git_repository.GitUbuntuRepository: fixture to hold a
        temporary output repository
    :param repo_builder.Repo input_repo: input repository data
    :param list(str) expected_output_refs: refs that must exist in the output
        repository
    :param dict validation_repo_delta: how to transform the input
        repository into a "validation repository", expressed as a dict to
        provide as **kwargs to gitubuntu.repo_builder.Repo.copy() against the
        input repository. The validation repository is then used for the
        purposes of comparison against the output repository.
    :param list(str) validation_repo_expected_identical_refs: refs that must be
        identical between the validation repository and the output repository
    :param bool reuse: if set, the output ref importer/ubuntu/trusty must be
        one supplied by the input repository (assumed to have a commit message
        of "Test commit") and not one created by the importer in this run
        (arranged by this test to have a different commit message)

    The input repository data is written into the output repository and then a
    fake non-native source package publication of version 1-1 in the Trusty
    release pocket is imported into it by calling import_unapplied_spi()
    directly. expected_output_refs, validation_repo_expected_identical_refs and
    reuse are then asserted. It is further asserted that no other refs exist in
    the output repository except for those listed in expected_output_refs and
    validation_repo_expected_identical_refs.
    """
    # Match the repo_builder objects
    get_import_tag_msg_mock.return_value = 'Test tag'
    # Importantly, the following commit message must not be the same as the
    # commit messages used by the test input repository commits, so that we can
    # later detect the difference between commits that were already there and
    # new commits created by the importer for the purposes of asserting the
    # reuse parameter correctly.
    get_import_commit_msg_mock.return_value = b'Test commit (new)'

    input_repo.write(repo.raw_repo)

    publish_spec = source_builder.SourceSpec(
        version='1-1',
        native=False,
    )

    with source_builder.Source(publish_spec) as dsc_path:
        target.import_unapplied_spi(
            repo=repo,
            spi=MockSPI(dsc_path, publish_spec.version),
            namespace='importer',
            skip_orig=False,
            parent_overrides={},
        )

    if reuse:
        # Test that the previous commit was reused. In this case, the
        # commit message should be one created by the repo_builder.Commit()
        # default, and not one created by the importer.
        tip_ref = repo.raw_repo.lookup_reference(
            'refs/heads/importer/ubuntu/trusty'
        )
        message = tip_ref.peel(pygit2.Commit).message
        assert message == 'Test commit'

    validation_repo = input_repo.copy(**validation_repo_delta)

    # Verify validation_repo_expected_identical_refs
    assert repo_comparator.equals(
        repoA=repo.raw_repo,
        repoB=validation_repo,
        test_refs=validation_repo_expected_identical_refs,
    )

    # Verify expected_output_refs
    for ref in expected_output_refs:
        assert repo.raw_repo.lookup_reference(ref)

    # Verify that no other refs exist
    all_expected_output_refs = (
        frozenset(validation_repo_expected_identical_refs) |
        frozenset(expected_output_refs)
    )
    all_actual_output_refs = frozenset(repo.raw_repo.listall_references())
    assert all_expected_output_refs == all_actual_output_refs


@pytest.mark.parametrize(
    [
        'input_repo',
        'validation_repo_delta',
        'validation_repo_expected_treewise_refs',
        'reuse',
    ],
    [
        # 1) An existing applied tag (or reimport tag) with the same Git tree
        #    - Reuse applied tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(name='unapplied', has_patches=True),
                    Commit.from_spec(name='applied', patches_applied=True),
                ],
                branches={
                    'importer/ubuntu/trusty': Placeholder('unapplied'),
                    'importer/applied/ubuntu/trusty': Placeholder('applied'),
                },
                tags={
                    'importer/import/1-1': Placeholder('unapplied'),
                    'importer/applied/1-1': Placeholder('applied'),
                },
            ),
            # validation_repo_delta:
            {
                # no output repository delta
            },
            # validation_repo_expected_treewise_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/heads/importer/applied/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/applied/1-1',
            ],
            # reuse:
            True,
        ),

        # 2) An existing applied tag with a different Git tree
        #    - Create reimport tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[
                    Commit.from_spec(
                        name='unapplied',
                        has_patches=True,
                        mutate='import tag contents',
                    ),
                    Commit.from_spec(
                        name='unapplied_reimport',
                        has_patches=True,
                    ),
                    Commit.from_spec(
                        name='applied',
                        patches_applied=True,
                        mutate='import tag contents',
                    )
                ],
                branches={'importer/ubuntu/trusty': Placeholder('unapplied')},
                tags={
                    'importer/import/1-1':
                        Placeholder('unapplied'),
                    'importer/reimport/import/1-1/0':
                        Placeholder('unapplied'),
                    'importer/reimport/import/1-1/1':
                        Placeholder('unapplied_reimport'),
                    'importer/applied/1-1':
                        Placeholder('applied'),
                },
            ),
            # validation_repo_delta:
            {
                'add_commits': [
                    Commit.from_spec(
                        name='applied_reimport',
                        patches_applied=True,
                        parents=[Placeholder('unapplied_reimport')],
                    ),
                ],
                'update_tags': {
                    'importer/reimport/applied/1-1/0':
                        Placeholder('applied'),
                    'importer/reimport/applied/1-1/1':
                        Placeholder('applied_reimport'),
                },
                'update_branches': {
                     'importer/applied/ubuntu/trusty':
                        Placeholder('applied_reimport'),
                },
            },
            # validation_repo_expected_treewise_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/heads/importer/applied/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/reimport/import/1-1/0',
                'refs/tags/importer/reimport/import/1-1/1',
                'refs/tags/importer/applied/1-1',
                'refs/tags/importer/reimport/applied/1-1/0',
                'refs/tags/importer/reimport/applied/1-1/1',
            ],
            # reuse:
            False,

            marks=pytest.mark.xfail(reason='LP: #1755247'),
        ),

        # 3) No applied tags
        #    - Create applied tag
        pytest.param(
            # input_repo:
            repo_builder.Repo(
                commits=[Commit.from_spec(name='unapplied', has_patches=True)],
                branches={'importer/ubuntu/trusty': Placeholder('unapplied')},
                tags={'importer/import/1-1': Placeholder('unapplied')},
            ),
            # validation_repo_delta:
            {
                'add_commits': [
                    Commit.from_spec(
                        name='applied',
                        patches_applied=True,
                        parents=[Placeholder('unapplied')],
                    ),
                ],
                'update_tags': {
                    'importer/applied/1-1': Placeholder('applied')
                },
                'update_branches': {
                     'importer/applied/ubuntu/trusty': Placeholder('applied'),
                },
            },
            # validation_repo_expected_treewise_refs:
            [
                'refs/heads/importer/ubuntu/trusty',
                'refs/heads/importer/applied/ubuntu/trusty',
                'refs/tags/importer/import/1-1',
                'refs/tags/importer/applied/1-1'
            ],
            # reuse:
            False,
        ),
    ]
)
@patch('gitubuntu.importer.get_import_tag_msg')
@patch('gitubuntu.importer.get_import_commit_msg')
def test_import_applied_spi_tags(
    get_import_commit_msg_mock,
    get_import_tag_msg_mock,
    repo,
    input_repo,
    validation_repo_delta,
    validation_repo_expected_treewise_refs,
    reuse,
):
    """Test that applied tags are correctly created, adjusted and/or reused

    :param unittest.mock.Mock get_import_commit_msg_mock: mock of the function
        that determines the commit message to use for a given import
    :param unittest.mock.Mock get_import_tag_msg_mock: mock of the function
        that determines the tag message to use for a given import
    :param repo gitubuntu.git_repository.GitUbuntuRepository: fixture to hold a
        temporary output repository
    :param repo_builder.Repo input_repo: input repository data
    :param dict validation_repo_delta: how to transform the input repository
        into a "validation repository", expressed as a dict to
        provide as **kwargs to gitubuntu.repo_builder.Repo.copy() against the
        input repository. The validation repository is then used for the
        purposes of comparison against the output repository.
    :param list(str) validation_repo_expected_treewise_refs: refs whose trees
        must be identical between the validation repository and the output
        repository
    :param bool reuse: if set, the output ref importer/ubuntu/trusty must be
        one supplied by the input repository (assumed to have a commit message
        of "Test commit") and not one created by the importer in this run
        (arranged by this test to have a different commit message)

    The input repository data is written into the output repository and then a
    fake non-native source package publication of version 1-1 in the Trusty
    release pocket is imported into it by calling import_applied_spi()
    directly. reuse and validation_repo_expected_treewise_refs are then
    asserted.

    This is similar to test_unapplied_spi_tags except that it calls
    import_applied_spi() instead of import_unapplied_spi() and only treewise
    ref comparisons are made.
    """
    # Match the repo_builder objects
    get_import_tag_msg_mock.return_value = 'Test tag'
    # Importantly, the following commit message must not be the same as the
    # commit messages used by the test input repository commits, so that we can
    # later detect the difference between commits that were already there and
    # new commits created by the importer for the purposes of asserting the
    # reuse parameter correctly.
    get_import_commit_msg_mock.return_value = b'Test commit (new)'

    input_repo.write(repo.raw_repo)

    publish_spec = source_builder.SourceSpec(
        version='1-1',
        native=False,
        has_patches=True,
    )

    with source_builder.Source(publish_spec) as dsc_path:
        target.import_applied_spi(
            repo=repo,
            spi=MockSPI(dsc_path, publish_spec.version),
            namespace='importer',
            allow_applied_failures=False,
            parent_overrides={},
        )

    if reuse:
        # Test that the previous commit was reused. In this case,
        # the commit message should be one created by the
        # repo_builder.Commit() default, and not one created by the
        # importer.
        tip_ref = repo.raw_repo.lookup_reference(
            'refs/heads/importer/ubuntu/trusty'
        )
        message = tip_ref.peel(pygit2.Commit).message
        assert message == 'Test commit'

    validation_repo = input_repo.copy(**validation_repo_delta)
    assert repo_comparator.equals(
        repoA=repo.raw_repo,
        repoB=validation_repo,
        test_refs=validation_repo_expected_treewise_refs,
        # this should be Commit, but we do not have a method yet
        # to obtain the stage-wise `quilt push` commits for a
        # patches-applied import
        comparison_type=repo_comparator.RepoComparisonType.Tree,
    )