def test_get_credentials(self): # if already bztoolsrc is present, backup the existing '~/.bztoolsrc' rcfile = os.path.expanduser('~/.bztoolsrc') rcfile_backup = os.path.expanduser('~/.bztoolsrc_backup') if os.path.exists(rcfile): shutil.move(rcfile, rcfile_backup) cmd = 'python ' + get_project_root_path() + \ 'auto_nag/tests/_get_credential.py' child = pexpect.spawn(cmd, timeout=180) child.expect('username') child.sendline('test_username') child.expect('password') child.sendline('test_password') child.expect(pexpect.EOF) child.close() credentials = get_credentials() # Removing the ~/.bztoolsrc which generated for testing. os.remove(rcfile) # copy back bztoolsrc_backup to ~/.bztoolsrc if os.path.exists(rcfile_backup): shutil.move(rcfile_backup, rcfile) assert_equals(credentials, ('test_username', 'test_password'))
def main(): # Script options parser = argparse.ArgumentParser(description='Submit Bugzilla attachments') parser.add_argument('bug_id', type=int, metavar='BUG', help='Bug number') parser.add_argument('filename', metavar='FILE', help='File to upload') parser.add_argument('--description', help='Attachment description', required=True) parser.add_argument('--patch', action='store_true', help='Is this a patch?') parser.add_argument('--reviewer', help='Bugzilla name of someone to r?') parser.add_argument('--comment', help='Comment for the attachment') parser.add_argument('--content_type', choices=FILE_TYPES, help="File's content_type") args = parser.parse_args() if args.content_type: args.content_type = FILE_TYPES[args.content_type] # Get the API root, default to bugzilla.mozilla.org API_ROOT = os.environ.get('BZ_API_ROOT', 'https://api-dev.bugzilla.mozilla.org/latest/') # Authenticate username, password = get_credentials() # Load the agent bz = AttachmentAgent(API_ROOT, username, password) # Attach the file bz.attach(**dict(args._get_kwargs()))
# If relman-auto-nag not installed, add project root directory into # PYTHONPATH import os import inspect import sys currentdir = os.path.dirname(os.path.abspath(__file__)) project_root = os.path.dirname(os.path.dirname(currentdir)) sys.path.insert(0, project_root) from auto_nag.bugzilla import utils utils.get_credentials()