#4127 Fix keeping the branch_to value when refreshing the new remote PR page
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

@@ -44,7 +44,7 @@ 

        {{ render_bootstrap_field(form.branch_from, size=80) }}

        To branch:

        <select id="branch_select" name="branch_to" class="c-select">

-         {% if branch_to %}<option>{{ branch_to }}</option>{% endif %}

+         {% if branch_to %}<option selected>{{ branch_to }}</option>{% endif %}

          {% for branch in g.branches |reverse %}

            {% if not branch_to or branch != branch_to %}

            <option>{{ branch }}</option>

file modified
+7 -4
@@ -1961,10 +1961,13 @@ 

              flask.flash(str(err), "error")

  

      flask.g.branches = sorted(orig_repo.listall_branches())

-     try:

-         branch_to = orig_repo.head.shorthand

-     except pygit2.GitError:

-         branch_to = "master"

+     if flask.request.method == "GET":

+         try:

+             branch_to = orig_repo.head.shorthand

+         except pygit2.GitError:

+             branch_to = "master"

+     else:

+         branch_to = form.branch_to.data.strip()

  

      return flask.render_template(

          "remote_pull_request.html",

@@ -281,6 +281,50 @@ 

          self.assertEqual(len(project.requests), 1)

  

      @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))

+     def test_new_remote_no_title(self):

+         """ Test creating a new remote PR authenticated when no title is

+         specified. """

+ 

+         tests.create_projects(self.session)

+         tests.create_projects_git(

+             os.path.join(self.path, 'requests'), bare=True)

+         self.set_up_git_repo()

+ 

+         # Before

+         self.session = pagure.lib.query.create_session(self.dbpath)

+         project = pagure.lib.query.get_authorized_project(self.session, 'test')

+         self.assertEqual(len(project.requests), 0)

+ 

+         # Try creating a remote PR

+         user = tests.FakeUser(username='foo')

+         with tests.user_set(self.app.application, user):

+             output = self.app.get('/test/diff/remote')

+             self.assertEqual(output.status_code, 200)

+             self.assertIn(

+                 '<h2>New remote pull-request</h2>',

+                 output.get_data(as_text=True))

+ 

+             csrf_token = self.get_csrf(output=output)

+             with patch(

+                     'pagure.forms.RemoteRequestPullForm.git_repo.args',

+                     MagicMock(return_value=(

+                         u'Git Repo address',

+                         [wtforms.validators.DataRequired()]))):

+                 data = {

+                     'csrf_token': csrf_token,

+                     'branch_from': 'master',

+                     'branch_to': 'feature',

+                     'git_repo': os.path.join(self.newpath, 'test'),

+                 }

+                 output = self.app.post('/test/diff/remote', data=data)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<h2>New remote pull-request</h2>', output_text)

+                 self.assertIn(

+                     '<option selected>feature</option>', output_text)

+ 

+     @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))

      def test_new_remote_pr_empty_target(self):

          """ Test creating a new remote PR authenticated against an empty

          git repo. """