~landscape/tarmac/ls-trunk

« back to all changes in this revision

Viewing changes to tarmac/tests/test_commands.py

  • Committer: Tarmac Traffic Controller
  • Author(s): Rodney Dawes
  • Date: 2014-02-28 20:37:12 UTC
  • mfrom: (428.2.4 merge-specific)
  • Revision ID: tarmac_traffic_controller-20140228203712-w3p50fhnpl81qtzh
Add an option to merge a single specific proposal to a branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import shutil
20
20
import sys
21
21
 
22
 
from mock import patch
 
22
from mock import patch, MagicMock
23
23
from tarmac.bin import commands
24
24
from tarmac.bin.registry import CommandRegistry
25
25
from tarmac.branch import Branch
157
157
                        reviewer=Thing(display_name=u'Reviewer'))]),
158
158
                          Thing(
159
159
                self_link=u'https://api.launchpad.net/1.0/proposal1',
160
 
                web_link=u'https://codelaunchpad.net/proposal1',
 
160
                web_link=u'https://code.launchpad.net/proposal1',
161
161
                queue_status=u'Approved',
162
162
                commit_message=u'Commit this.',
163
163
                source_branch=self.branches[0],
201
201
        branch3.lp_branch.unique_name = '~user/branch/' + name
202
202
        branch3.lp_branch.landing_candidates = []
203
203
        b3_proposal = Thing(
204
 
            self_link=u'http://api.edge.launchpad.net/devel/proposal3',
205
 
            web_link=u'http://edge.launchpad.net/proposal3',
 
204
            self_link=u'https://api.launchpad.net/1.0/proposal3',
 
205
            web_link=u'https://code.launchpad.net/proposal3',
206
206
            queue_status=u'Approved',
207
207
            commit_message=u'Commitable.',
208
208
            source_branch=branch3.lp_branch,
219
219
        branch3.lp_branch.landing_targets = [b3_proposal]
220
220
        self.proposals.append(b3_proposal)
221
221
        self.branches.append(branch3.lp_branch)
222
 
 
 
222
        self.addCleanup(shutil.rmtree, branch3_dir)
223
223
 
224
224
    def lp_save(self, *args, **kwargs):
225
225
        """Do nothing here."""
491
491
        self.addProposal("one_prerequisite", self.branches[0])
492
492
        proposals = self.command._get_prerequisite_proposals(self.proposals[2])
493
493
        self.assertEqual(len(proposals), 2)
 
494
 
 
495
    @patch('tarmac.bin.commands.Launchpad.load')
 
496
    def test__get_proposal_from_mp_url(self, mocked):
 
497
        """Test that the URL is substituted correctly."""
 
498
        self.command.launchpad = MagicMock()
 
499
        self.command.launchpad.load = mocked
 
500
        self.command._get_proposal_from_mp_url(
 
501
            'https://code.launchpad.net/~foo/bar/baz/+merge/10')
 
502
        mocked.assert_called_once_with(
 
503
            'https://api.launchpad.net/1.0/~foo/bar/baz/+merge/10')
 
504
 
 
505
    @patch('tarmac.bin.commands.Launchpad.load')
 
506
    def test__get_proposal_from_mp_url_with_api_url(self, mocked):
 
507
        """Test that the URL is ignored correctly."""
 
508
        self.command.launchpad = MagicMock()
 
509
        self.command.launchpad.load = mocked
 
510
        self.command._get_proposal_from_mp_url(
 
511
            'https://api.launchpad.net/1.0/~foo/bar/baz/+merge/10')
 
512
        mocked.assert_called_once_with(
 
513
            'https://api.launchpad.net/1.0/~foo/bar/baz/+merge/10')
 
514
 
 
515
    def test_run_merge_with_specific_proposal_without_branch_url(self):
 
516
        """Test that a specific proposal is merged, with the others ignored."""
 
517
        self.proposals[1].reviewed_revid = \
 
518
            self.branch2.bzr_branch.last_revision()
 
519
        self.addProposal('specific_merge_without_branch_url')
 
520
        self.launchpad.load = MagicMock(return_value=self.proposals[1])
 
521
        self.command._get_reviews = MagicMock()
 
522
        self.config.proposal = self.proposals[1].web_link
 
523
        self.command.run(launchpad=self.launchpad)
 
524
        self.launchpad.load.assert_called_once_with(self.proposals[1].self_link)
 
525
        self.command._get_reviews.assert_called_once_with(self.proposals[1])
 
526
 
 
527
    def test_run_merge_with_specific_proposal_with_branch_url(self):
 
528
        """Test that a specific proposal is merged, with the others ignored."""
 
529
        self.proposals[1].reviewed_revid = \
 
530
            self.branch2.bzr_branch.last_revision()
 
531
        self.addProposal('specific_merge_with_branch_url')
 
532
        self.launchpad.load = MagicMock(return_value=self.proposals[1])
 
533
        self.command._get_reviews = MagicMock()
 
534
        self.config.proposal = self.proposals[1].web_link
 
535
        self.command.run(launchpad=self.launchpad,
 
536
                         branch_url=self.branches[1].bzr_identity)
 
537
        self.launchpad.load.assert_called_once_with(self.proposals[1].self_link)
 
538
        self.command._get_reviews.assert_called_once_with(self.proposals[1])