Пример #1
0
    def test_multiple_updates_in_file(self):
        bot = bot_factory()
        bot.provider.create_branch = Mock()
        bot.provider.create_commit.side_effect = ["sha1", "sha2", "sha3"]
        bot.create_pull_request = Mock()
        requirement = Mock()
        requirement.update_content.return_value = "new content"
        updates = [
            RequirementUpdate(requirement_file=RequirementFile(path="foo.txt",
                                                               content='',
                                                               sha='abcd'),
                              requirement=requirement,
                              commit_message="foo"),
            RequirementUpdate(requirement_file=RequirementFile(path="foo.txt",
                                                               content='',
                                                               sha='abcd'),
                              requirement=requirement,
                              commit_message="foo"),
            RequirementUpdate(requirement_file=RequirementFile(path="baz.txt",
                                                               content='',
                                                               sha='xyz'),
                              requirement=requirement,
                              commit_message="foo")
        ]

        bot.commit_and_pull(True, "new branch", "repo", "", updates)

        self.assertEqual(bot.provider.create_commit.called, True)
        self.assertEqual(bot.provider.create_commit.call_count, 2)
        create_commit_calls = bot.provider.create_commit.call_args_list
        # we're looking for the sha here. Make sure that the sha got updated with the new content
        self.assertEqual(create_commit_calls[0][1]["sha"], "abcd")
        self.assertEqual(create_commit_calls[1][1]["sha"], "xyz")
Пример #2
0
    def test_apply_update_pull_request_exists(self):
        the_requirement = Mock()
        the_pull = pullrequest_factory("The PR")

        bot = bot_factory(prs=[the_pull])
        bot.req_bundle.get_updates = Mock()
        update = RequirementUpdate(requirement_file="foo",
                                   requirement=the_requirement,
                                   commit_message="foo")
        bot.req_bundle.get_updates.return_value = [("The PR", "", "", [update])
                                                   ]
        bot.apply_updates(initial=True, scheduled=False)

        self.assertEqual(the_requirement.pull_request, the_pull)
Пример #3
0
    def test_apply_update_initial_pr_still_open(self):
        initial_pr = pullrequest_factory(
            title=InitialUpdate.get_title(),
            state="open",
        )
        bot = bot_factory(prs=[initial_pr])
        the_requirement = Mock()
        update = RequirementUpdate(
            requirement_file="foo", requirement=the_requirement, commit_message="foo"
        )
        bot.req_bundle.get_updates = Mock()
        bot.req_bundle.get_updates.return_value = [("The PR", "", "", [update])]

        bot.apply_updates(initial=True, scheduled=False)

        self.assertEqual(bot.provider.create_pull_request.called, False)
Пример #4
0
    def test_close_stall_prs_called_only_once_on_scheduled_run(self):
        the_requirement = Mock()
        the_pull = pullrequest_factory("Scheduled")
        bot = bot_factory(prs=[])
        bot.close_stale_prs = Mock()
        bot.req_bundle.get_updates = Mock()
        update = RequirementUpdate(
            requirement_file="foo", requirement=the_requirement, commit_message="foo"
        )
        bot.req_bundle.get_updates.return_value = [("The PR", "", "", [update, update])]
        bot.commit_and_pull = Mock()
        bot.commit_and_pull.return_value = the_pull
        bot.apply_updates(initial=False, scheduled=True)

        self.assertEqual(the_requirement.pull_request, the_pull)
        bot.close_stale_prs.assert_called_once_with(update=update, pull_request=the_pull,
                                                    scheduled=True)
Пример #5
0
    def test_apply_update_with_write_config(self):
        the_requirement = Mock()
        the_pull = pullrequest_factory("The PR")

        bot = bot_factory(prs=[the_pull])
        bot.write_config = {'foo': 'bar'}
        bot.pull_config = Mock()
        bot.req_bundle.get_updates = Mock()
        update = RequirementUpdate(requirement_file="foo",
                                   requirement=the_requirement,
                                   commit_message="foo")
        bot.req_bundle.get_updates.return_value = [("The PR", "", "", [update])
                                                   ]
        bot.commit_and_pull = Mock()
        bot.commit_and_pull.return_value = the_pull
        bot.apply_updates(initial=True, scheduled=False)

        self.assertEqual(the_requirement.pull_request, the_pull)
        bot.pull_config.assert_called_once_with({'foo': 'bar'})
Пример #6
0
    def test_apply_update_with_prefix_pull_request_new(self):
        the_requirement = Mock()
        the_pull = pullrequest_factory("The PR")

        bot = bot_factory(prs=[the_pull])
        bot.config.pr_prefix = "Some Prefix"
        bot.req_bundle.get_updates = Mock()
        update = RequirementUpdate(requirement_file="foo",
                                   requirement=the_requirement,
                                   commit_message="foo")
        bot.req_bundle.get_updates.return_value = [("The PR", "", "", [update])
                                                   ]
        bot.commit_and_pull = Mock()
        bot.commit_and_pull.return_value = the_pull
        bot.apply_updates(initial=False, scheduled=False)
        self.assertEqual(the_requirement.pull_request, the_pull)
        bot.commit_and_pull.assert_called_once_with(
            body='',
            initial=False,
            new_branch=u'pyup-',
            title=u'Some Prefix The PR',
            updates=[update])