mdelagra avatar mdelagra committed 1623cc5

launch_browser was using the wrong url when the server flag was set, allowing use of the server flag in lieu of the hgrc setting

Comments (0)

Files changed (3)

mercurial_reviewboard/__init__.py

 
     ui.status('postreview plugin, version %s\n' % __version__)
     
-    if not ui.config('reviewboard', 'server'):
-        raise util.Abort(
-                _('please specify a reviewboard server in your .hgrc file') )
+    # checks to see if the server was set
+    find_server(ui, opts)
     
     check_parent_options(opts)
 
         request_id = new_review(ui, fields, diff, parentdiff, 
                                    opts)
 
-    request_url = '%s/%s/%s/' % (ui.config('reviewboard', 'server'), 
-                                 "r", request_id)
+    request_url = '%s/%s/%s/' % (find_server(ui, opts), "r", request_id)
 
     if not request_url.startswith('http'):
         request_url = 'http://%s' % request_url
     else:
         proxy=None
     
-    server = opts.get('server')
-    if not server:
-        server = ui.config('reviewboard', 'server')
+    server = find_server(ui, opts)
     
     ui.status('reviewboard:\t%s\n' % server)
     ui.status('\n')
         contexts.append(currctx)
     contexts.reverse()
     return contexts
+    
+
+def find_server(ui, opts):
+    server = opts.get('server')
+    if not server:
+        server = ui.config('reviewboard', 'server')
+    if not server:
+        msg = 'please specify a reviewboard server in your .hgrc file or using the --server flag'
+        raise util.Abort(_(msg))
+    return server
+    
 
 def readline():
     line = sys.stdin.readline()

mercurial_reviewboard/tests/test_find_server.py

+from nose.tools import eq_, raises
+
+from mercurial_reviewboard import find_server, util
+from mercurial_reviewboard.tests import get_initial_opts, mock_ui
+
+
+def test_find_server_from_hgrc():
+    ui = mock_ui()
+    opts = get_initial_opts()
+    
+    server = find_server(ui, opts)
+    eq_('http://example.com', server)
+
+
+def test_find_server_from_command_line():
+    ui = mock_ui()
+    opts = get_initial_opts()
+    opts['server'] = 'http://example.org'
+    
+    server = find_server(ui, opts)
+    eq_('http://example.org', server)
+
+
+def test_find_server_from_command_line_no_hgrc():
+    ui = mock_ui()
+    ui.setconfig('reviewboard', 'server', None)
+    opts = get_initial_opts()
+    opts['server'] = 'http://example.org'
+
+    server = find_server(ui, opts)
+    eq_('http://example.org', server)
+
+
+@raises(util.Abort)
+def test_find_server_not_defined():
+    ui = mock_ui()
+    ui.setconfig('reviewboard', 'server', None)
+    opts = get_initial_opts()
+
+    find_server(ui, opts)

mercurial_reviewboard/tests/test_ui.py

 from mock import Mock, patch_object
-from nose.tools import eq_
+from nose.tools import eq_, raises
 
 import mercurial_reviewboard
-from mercurial_reviewboard import postreview
+from mercurial_reviewboard import postreview, util
 from mercurial_reviewboard.tests import get_initial_opts, get_repo, mock_ui
 
 class TestChangesetsOutput:
     @patch_object(mercurial_reviewboard, 'new_review')
     @patch_object(mercurial_reviewboard, 'launch_webbrowser')
     def test_browser_launch_true(self, mock_launch, mock_create_method):
+        mock_create_method.return_value = '1'
+        
         ui = mock_ui()
         ui.setconfig('reviewboard', 'launch_webbrowser', 'true')
         
         repo = get_repo(ui, 'two_revs')
         opts = get_initial_opts()
         postreview(ui, repo, **opts)
-        assert mock_launch.called
+        eq_('http://example.com/r/1/', mock_launch.call_args[0][1])
+
+    @patch_object(mercurial_reviewboard, 'new_review')
+    @patch_object(mercurial_reviewboard, 'launch_webbrowser')
+    def test_browser_launch_server_arg(self, mock_launch, mock_create_method):
+        mock_create_method.return_value = '1'
+
+        ui = mock_ui()
+        ui.setconfig('reviewboard', 'launch_webbrowser', 'true')
+
+        repo = get_repo(ui, 'two_revs')
+        opts = get_initial_opts()
+        opts['server'] = 'example.org'
+        postreview(ui, repo, **opts)
+        eq_('http://example.org/r/1/', mock_launch.call_args[0][1])
+
+
+class TestServerConfiguration:
+    
+    @raises(util.Abort)
+    @patch_object(mercurial_reviewboard, 'new_review')
+    def test_no_reviewboard_configured(self, mock_create_review):
+        ui = mock_ui()
+        ui.setconfig('reviewboard', 'server', None)
         
+        repo = get_repo(ui, 'two_revs')
+        opts = get_initial_opts()
+        postreview(ui, repo, **opts)
+    
+    @patch_object(mercurial_reviewboard, 'new_review')
+    def test_reviewboard_option(self, mock_create_review):
+        ui = mock_ui()
+        ui.setconfig('reviewboard', 'server', None)
+
+        repo = get_repo(ui, 'two_revs')
+        opts = get_initial_opts()
+        opts['server'] = 'example.com'
+        postreview(ui, repo, **opts)
+        assert mock_create_review.called
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.