bugzilla: move testing/bugzilla.py to bugzilla
authorGregory Szorc <gps@mozilla.com>
Fri, 24 Oct 2014 16:35:17 -0700
changeset 359826 ed05413a04c2ef673c2bb0123d2d38d974ae3f23
parent 359825 7f1dd03aa08d9cdee4e9152ce0fdaa52f51af29a
child 359827 4c4cbd58691a6f1d615c62f2bb2f23cac32266c2
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
bugzilla: move testing/bugzilla.py to bugzilla As we focus on making MozReview easier to hack on, we should expose the tools to interact with the various systems in a cleaner way. We move testing/bugzilla.py to ./bugzilla to make it easier to consume.
bugzilla
docs/hacking-mozreview.rst
hgext/bzpost/tests/test-post.t
hgext/reviewboard/tests/helpers.sh
hgext/reviewboard/tests/test-auth.t
hgext/reviewboard/tests/test-user-apis.t
testing/bugzilla.py
rename from testing/bugzilla.py
rename to bugzilla
--- a/testing/bugzilla.py
+++ b/bugzilla
@@ -4,22 +4,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # This is a script for performing common Bugzilla operations from the command
 # line. It is meant to support testing.
 
 import os
 import sys
 
-from mach.main import Mach
-
 HERE = os.path.abspath(os.path.dirname(__file__))
-sys.path.insert(0, HERE)
 
 def main(args):
+    sys.path.insert(0, os.path.join(HERE, 'testing'))
+
+    from mach.main import Mach
+
     m = Mach(os.getcwd())
     m.define_category('bugzilla', 'Bugzilla',
         'Interface with Bugzilla', 50)
     import vcttesting.bugzilla.mach_commands
 
     return m.run(args)
 
 if __name__ == '__main__':
--- a/docs/hacking-mozreview.rst
+++ b/docs/hacking-mozreview.rst
@@ -105,16 +105,39 @@ When you run ``mozreview start``, a numb
 daemon processes will be started. These will linger forever - taking up
 system resources - until there is some form of intervention.
 
 The easiest way to stop everything related to the running MozReview
 instance is to run ``mozreview stop``. e.g.::
 
    $ ./mozreview stop /path/to/instance
 
+Interacting with Bugzilla
+=========================
+
+The ``bugzilla`` tool in the root of the repository provides a quick an
+convenient interface to performing common Bugzilla operations, such as
+creating bugs and printing the state of bugs.
+
+This tool has the dual role of supporting both machines and humans. The
+tests rely heavily on this tool to perform small, well-defined Bugzilla
+interactions. You are encouraged to use the tool to help you hack on
+MozReview.
+
+Since the tool had its origins in testing land, it currently
+requires some environment variables to use:
+
+BUGZILLA_URL
+   This must be set the base URL of the Bugzilla instance you wish to
+   communicate with.
+BUGZILLA_USERNAME
+   The username your API requests to Bugzilla will use.
+BUGZILLA_PASSWORD
+   The password your API requests to Bugzilla will use.
+
 Code Locations
 ==============
 
 ``pylib/rbbz`` contains the modifications to Review Board to enable
 Bugzilla integration and support for series of reviews.
 
 ``pylib/rbmozui`` contains the UI modifications to Review Board.
 
--- a/hgext/bzpost/tests/test-post.t
+++ b/hgext/bzpost/tests/test-post.t
@@ -57,50 +57,50 @@
 
   $ cat >> hgweb << EOF
   > [paths]
   > / = *
   > EOF
   $ hg serve -d -p $HGPORT --pid-file hg.pid --web-conf hgweb
   $ cat hg.pid >> $DAEMON_PIDS
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug1
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug1
 
 Pushing to mozilla-inbound will result in bug being updated
 
   $ hg clone mozilla-central mi-push > /dev/null
   $ cd mi-push
   $ echo mc > foo
   $ hg commit -m 'Bug 1 - Commit to inbound'
   $ hg push http://localhost:$HGPORT/integration/mozilla-inbound
   pushing to http://localhost:$HGPORT/integration/mozilla-inbound
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   recording push in bug 1
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 1
+  $ $TESTDIR/bugzilla dump-bug 1
   Bug 1:
     comments:
     - author: admin@example.com
       id: 1
       tags: []
       text: ''
     - author: admin@example.com
       id: 2
       tags: []
       text: http://localhost:$HGPORT/integration/mozilla-inbound/rev/b507e8e33160
     summary: bug1
 
 Pushing multiple changesets with multiple bugs will result in bug being updated
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug2
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug3
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug2
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug3
 
   $ echo 2_1 > foo
   $ hg commit -m 'Bug 2 - First commit'
   $ echo 2_2 > foo
   $ hg commit -m 'Bug 2 - Second commit'
   $ echo 3_1 > foo
   $ hg commit -m 'Bug 3 - Another bug'
   $ hg push http://localhost:$HGPORT/integration/mozilla-inbound
@@ -108,17 +108,17 @@ Pushing multiple changesets with multipl
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 3 changesets with 3 changes to 1 files
   recording push in bug 2
   recording push in bug 3
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 2 3
+  $ $TESTDIR/bugzilla dump-bug 2 3
   Bug 2:
     comments:
     - author: admin@example.com
       id: 3
       tags: []
       text: ''
     - author: admin@example.com
       id: 5
@@ -138,51 +138,51 @@ Pushing multiple changesets with multipl
       tags: []
       text: http://localhost:$HGPORT/integration/mozilla-inbound/rev/abe0245372d4
     summary: bug3
 
   $ cd ..
 
 Pushing to Try will post TBPL comment
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug4
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug4
 
   $ hg clone -r 0 try client > /dev/null
   $ cd client
   $ echo expected > foo
   $ hg commit -m 'Bug 4 - Add foo'
   $ echo foo > foo
   $ hg commit -m 'try: -b do -p all -u all -t all'
   $ hg push http://localhost:$HGPORT/try
   pushing to http://localhost:$HGPORT/try
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 2 changesets with 2 changes to 1 files
   recording TBPL push in bug 4
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 4
+  $ $TESTDIR/bugzilla dump-bug 4
   Bug 4:
     comments:
     - author: admin@example.com
       id: 7
       tags: []
       text: ''
     - author: admin@example.com
       id: 8
       tags: []
       text: https://tbpl.mozilla.org/?tree=Try&rev=311111800824
     summary: bug4
 
   $ cd ..
 
 Public changesets pushed to Try will be ignored if no bug in draft changesets
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug5
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug5
   $ hg clone -r 0 try no-bug-in-draft > /dev/null
   $ cd no-bug-in-draft
   $ echo no-bug-in-draft > foo
   $ hg commit -m 'Bug 5 - This should be irrelevant'
   $ hg phase --public -r .
   $ echo foo > foo
   $ hg commit -m 'New draft changeset without bug'
   $ echo try > foo
@@ -190,30 +190,30 @@ Public changesets pushed to Try will be 
   $ hg push --force http://localhost:$HGPORT/try
   pushing to http://localhost:$HGPORT/try
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 3 changesets with 3 changes to 1 files (+1 heads)
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 5
+  $ $TESTDIR/bugzilla dump-bug 5
   Bug 5:
     comments:
     - author: admin@example.com
       id: 9
       tags: []
       text: ''
     summary: bug5
 
   $ cd ..
 
 Public changesets pushed to Try will be ignored if a bug in draft changesets
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug6
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug6
 
   $ hg clone -r 0 try bug-in-draft > /dev/null
   $ cd bug-in-draft
   $ echo bug-in-draft > foo
   $ hg commit -m 'Bug 5 - This should also irrelevant'
   $ hg phase --public -r .
   $ echo foo > foo
   $ hg commit -m 'Bug 6 - New draft changeset with bug'
@@ -223,17 +223,17 @@ Public changesets pushed to Try will be 
   pushing to http://localhost:$HGPORT/try
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 3 changesets with 3 changes to 1 files (+1 heads)
   recording TBPL push in bug 6
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 5 6
+  $ $TESTDIR/bugzilla dump-bug 5 6
   Bug 5:
     comments:
     - author: admin@example.com
       id: 9
       tags: []
       text: ''
     summary: bug5
   Bug 6:
@@ -262,17 +262,17 @@ Pushing commit with bug number to user r
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   $ cd ..
 
 Pushing commit with bug number to user repo will post comment if enabled
 
-  $ $TESTDIR/testing/bugzilla.py create-bug TestProduct TestComponent bug7
+  $ $TESTDIR/bugzilla create-bug TestProduct TestComponent bug7
   $ hg clone users/bzpost_mozilla.com/mozilla-central post-to-user > /dev/null
   $ cd post-to-user
   $ cat >> .hg/hgrc << EOF
   > [bzpost]
   > updateuserrepo = True
   > EOF
 
   $ echo 'post to user repo' > foo
@@ -281,17 +281,17 @@ Pushing commit with bug number to user r
   pushing to http://localhost:$HGPORT/users/bzpost_mozilla.com/mozilla-central
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   recording push in bug 7
 
-  $ $TESTDIR/testing/bugzilla.py dump-bug 7
+  $ $TESTDIR/bugzilla dump-bug 7
   Bug 7:
     comments:
     - author: admin@example.com
       id: 12
       tags: []
       text: ''
     - author: admin@example.com
       id: 13
--- a/hgext/reviewboard/tests/helpers.sh
+++ b/hgext/reviewboard/tests/helpers.sh
@@ -51,23 +51,23 @@ reviewboard = $TESTDIR/hgext/reviewboard
 
 EOF
 
 fi
 
 }
 
 alias rbmanage='python $TESTDIR/hgext/reviewboard/tests/rbmanage.py'
-alias bugzilla='$TESTDIR/testing/bugzilla.py'
+alias bugzilla='$TESTDIR/bugzilla'
 alias dockercontrol='$TESTDIR/testing/docker-control.py'
 
 commonenv() {
   $TESTDIR/testing/docker-control.py start-bmo $1 $HGPORT2 > /dev/null
   export BUGZILLA_URL=http://${DOCKER_HOSTNAME}:$HGPORT2
-  $TESTDIR/testing/bugzilla.py create-group reviewboard 'reviewboard users'
+  $TESTDIR/bugzilla create-group reviewboard 'reviewboard users'
 
   hg init client
   hg init server
   rbmanage create rbserver
   rbmanage repo rbserver test-repo http://localhost:$HGPORT/
   rbmanage start rbserver $HGPORT1
   serverconfig server/.hg/hgrc $HGPORT1
   clientconfig client/.hg/hgrc
--- a/hgext/reviewboard/tests/test-auth.t
+++ b/hgext/reviewboard/tests/test-auth.t
@@ -83,19 +83,19 @@ Pushing using username password auth wor
   review id:  bz://1/gooduserpass
   review url: http://localhost:$HGPORT1/r/3 (pending)
   [1]
 
 Pushing as a user not in Review Board should auto create the RB account
 We create 2 users here. 1 looks like a normal person: "First Last"
 The other has Mozilla IRC syntax: "First Last [:nick]"
 
-  $ $TESTDIR/testing/bugzilla.py create-user user1@example.com password1 'Dummy User1'
+  $ bugzilla create-user user1@example.com password1 'Dummy User1'
   created user 2
-  $ $TESTDIR/testing/bugzilla.py create-user user2@example.com password2 'Mozila User [:nick]'
+  $ bugzilla create-user user2@example.com password2 'Mozila User [:nick]'
   created user 3
 
   $ hg --config bugzilla.username=user1@example.com --config bugzilla.password=password1 push --reviewid bz://1/nonick
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
@@ -144,17 +144,17 @@ Usernames for users with IRC nicks are t
     fullname: Mozila User [:nick]
     id: 3
     last_name: ''
     url: /users/nick/
     username: nick
 
 Changing the IRC nickname in Bugzilla will update the RB username
 
-  $ $TESTDIR/testing/bugzilla.py update-user-fullname user2@example.com 'Mozilla User [:newnick]'
+  $ bugzilla update-user-fullname user2@example.com 'Mozilla User [:newnick]'
   updated user 3
 
   $ hg --config bugzilla.username=user2@example.com --config bugzilla.password=password2 push --reviewid bz://1/user2newnick
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
@@ -176,17 +176,17 @@ Changing the IRC nickname in Bugzilla wi
     id: 3
     last_name: ''
     url: /users/newnick/
     username: newnick
 
 Changing the email address in Bugzilla will update the RB email
 
   $ exportbzauth admin@example.com password
-  $ $TESTDIR/testing/bugzilla.py update-user-email user2@example.com user2-new@example.com
+  $ bugzilla update-user-email user2@example.com user2-new@example.com
   updated user 3
   $ hg --config bugzilla.username=user2-new@example.com --config bugzilla.password=password2 push --reviewid bz://1/user2newemail
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
   changeset:  1:737709d9e5f4
@@ -222,17 +222,17 @@ Disabling a user in Bugzilla will preven
   no changes found
   submitting 1 changesets for review
   abort: invalid Bugzilla username/password; check your settings
   [255]
 
 Re-enabling a disabled user will allow them to use Review Board
 
   $ exportbzauth admin@example.com password
-  $ $TESTDIR/testing/bugzilla.py update-user-login-denied-text user1@example.com ''
+  $ bugzilla update-user-login-denied-text user1@example.com ''
   updated user 2
   $ hg --config bugzilla.username=user1@example.com --config bugzilla.password=password1 push --reviewid bz://1/undisableduser
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
   changeset:  1:737709d9e5f4
@@ -242,17 +242,17 @@ Re-enabling a disabled user will allow t
   review id:  bz://1/undisableduser
   review url: http://localhost:$HGPORT1/r/13 (pending)
   [1]
 
 If a new Review Board user claims the same IRC nick as an existing user,
 we fall back to non-IRC RB usernames.
 
   $ exportbzauth admin@example.com password
-  $ $TESTDIR/testing/bugzilla.py create-user user3@example.com password3 'Dummy User3 [:newnick]'
+  $ bugzilla create-user user3@example.com password3 'Dummy User3 [:newnick]'
   created user 4
 
   $ hg --config bugzilla.username=user3@example.com --config bugzilla.password=password3 push --reviewid bz://1/conflictingircnick
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
@@ -290,17 +290,17 @@ adding a new user or splitting this test
     last_name: ''
     url: /users/user3%2B4/
     username: user3+4
 
 If an existing RB user changes their IRC nick to one taken by another RB
 user, they will be assigned the email+id username.
 
   $ exportbzauth admin@example.com password
-  $ $TESTDIR/testing/bugzilla.py update-user-fullname user3@example.com 'Mozilla User3 [:mynick]'
+  $ bugzilla update-user-fullname user3@example.com 'Mozilla User3 [:mynick]'
   updated user 4
 
 (We need to push to get the RB username updated)
 
   $ hg --config bugzilla.username=user3@example.com --config bugzilla.password=password3 push --reviewid bz://1/user3newnick > /dev/null
   [1]
 
   $ exportbzauth user3@example.com password3
@@ -327,17 +327,17 @@ user, they will be assigned the email+id
     first_name: Mozilla User [:newnick]
     fullname: Mozilla User [:newnick]
     id: 3
     last_name: ''
     url: /users/newnick/
     username: newnick
 
   $ exportbzauth admin@example.com password
-  $ $TESTDIR/testing/bugzilla.py update-user-fullname user2-new@example.com 'Mozilla User [:mynick]'
+  $ bugzilla update-user-fullname user2-new@example.com 'Mozilla User [:mynick]'
   updated user 3
 
   $ hg --config bugzilla.username=user2-new@example.com --config bugzilla.password=password2 push --reviewid bz://1/user2sharednick
   pushing to ssh://user@dummy/$TESTTMP/server
   searching for changes
   no changes found
   submitting 1 changesets for review
   
--- a/hgext/reviewboard/tests/test-user-apis.t
+++ b/hgext/reviewboard/tests/test-user-apis.t
@@ -1,21 +1,21 @@
 #require docker
 
   $ . $TESTDIR/hgext/reviewboard/tests/helpers.sh
 
   $ commonenv rb-test-autocomplete
 
 Create some users
 
-  $ $TESTDIR/testing/bugzilla.py create-user joe1@example.com password 'Joe Smith'
+  $ bugzilla create-user joe1@example.com password 'Joe Smith'
   created user 2
-  $ $TESTDIR/testing/bugzilla.py create-user the-real-j-o-e@example.com password 'Joe Another'
+  $ bugzilla create-user the-real-j-o-e@example.com password 'Joe Another'
   created user 3
-  $ $TESTDIR/testing/bugzilla.py create-user jane@example.com password 'Jane Jones [:jenny]'
+  $ bugzilla create-user jane@example.com password 'Jane Jones [:jenny]'
   created user 4
 
 Unauthenticated users should not be able to search
 
   $ BUGZILLA_USERNAME= BUGZILLA_PASSWORD= rbmanage get-users $HGPORT1 joe
   API Error: 500: 226: Bugzilla error: Logged-out users cannot use the "match" argument to this function to access any user information.
   [1]